diff options
author | Luboš Luňák <l.lunak@suse.cz> | 2012-03-06 10:44:52 +0100 |
---|---|---|
committer | Luboš Luňák <l.lunak@suse.cz> | 2012-03-12 13:35:56 +0100 |
commit | 2f5f802bcf197c5c65aa4453ad2097d5642b80aa (patch) | |
tree | de73d7917814113d7e593f9c42e7a0242465f447 /sal/rtl/source/ustring.cxx | |
parent | f2d0fcc26be481c2f872056fb3b8402169d124d8 (diff) |
rtl_uString_newFromLiteral() for string literals
Drop the recently introduced rtl_uString_newFromAscii_WithLength()
and replace it with this one. The name fits better and it'll be also
a distinct function that specifically includes embedded \0's
(because that's what OUString supports and if a string literal
explicitly includes it, it makes sense to copy it as such).
Diffstat (limited to 'sal/rtl/source/ustring.cxx')
-rw-r--r-- | sal/rtl/source/ustring.cxx | 37 |
1 files changed, 32 insertions, 5 deletions
diff --git a/sal/rtl/source/ustring.cxx b/sal/rtl/source/ustring.cxx index 763d9c51e573..649cb82b9013 100644 --- a/sal/rtl/source/ustring.cxx +++ b/sal/rtl/source/ustring.cxx @@ -471,10 +471,37 @@ void SAL_CALL rtl_uString_newFromAscii( rtl_uString** ppThis, else nLen = 0; - rtl_uString_newFromAscii_WithLength( ppThis, pCharStr, nLen ); + if ( !nLen ) + { + IMPL_RTL_STRINGNAME( new )( ppThis ); + return; + } + + if ( *ppThis ) + IMPL_RTL_STRINGNAME( release )( *ppThis ); + + *ppThis = IMPL_RTL_STRINGNAME( ImplAlloc )( nLen ); + OSL_ASSERT(*ppThis != NULL); + if ( (*ppThis) ) + { + IMPL_RTL_STRCODE* pBuffer = (*ppThis)->buffer; + do + { + /* Check ASCII range */ + SAL_WARN_IF( ((unsigned char)*pCharStr) > 127, "rtl.string", + "rtl_uString_newFromAscii - Found char > 127" ); + + *pBuffer = *pCharStr; + pBuffer++; + pCharStr++; + } + while ( *pCharStr ); + } } -void SAL_CALL rtl_uString_newFromAscii_WithLength( rtl_uString** ppThis, +// Used when creating from string literals. +// Intentionally copies also embedded \0's if present. +void SAL_CALL rtl_uString_newFromLiteral( rtl_uString** ppThis, const sal_Char* pCharStr, sal_Int32 nLen ) SAL_THROW_EXTERN_C() @@ -493,17 +520,17 @@ void SAL_CALL rtl_uString_newFromAscii_WithLength( rtl_uString** ppThis, if ( (*ppThis) ) { IMPL_RTL_STRCODE* pBuffer = (*ppThis)->buffer; - do + sal_Int32 nCount; + for( nCount = nLen; nCount > 0; --nCount ) { /* Check ASCII range */ SAL_WARN_IF( ((unsigned char)*pCharStr) > 127, "rtl.string", - "rtl_uString_newFromAscii_WithLength - Found char > 127" ); + "rtl_uString_newFromLiteral - Found char > 127" ); *pBuffer = *pCharStr; pBuffer++; pCharStr++; } - while ( *pCharStr ); } } |