diff options
Diffstat (limited to 'i18nutil')
-rw-r--r-- | i18nutil/inc/i18nutil/x_rtl_ustring.h | 22 | ||||
-rw-r--r-- | i18nutil/source/utility/widthfolding.cxx | 11 |
2 files changed, 20 insertions, 13 deletions
diff --git a/i18nutil/inc/i18nutil/x_rtl_ustring.h b/i18nutil/inc/i18nutil/x_rtl_ustring.h index 848cc9e5eb6e..406817a9e7d4 100644 --- a/i18nutil/inc/i18nutil/x_rtl_ustring.h +++ b/i18nutil/inc/i18nutil/x_rtl_ustring.h @@ -38,19 +38,25 @@ * Allocates a new <code>rtl_uString</code> with capacity of nLen + 1 * characters. * - * The reference count is 0. The characters of the capacity are not cleared, + * The reference count is 1. The characters of the capacity are not cleared, * unlike the similar method of rtl_uString_new_WithLength in rtl/ustring.h, so - * is more efficient for allocating a new string. You need to "acquire" by such - * as OUString( rtl_uString * value ) if you intend to use it for a while. + * is more efficient for allocating a new string. + * + * call rtl_uString_release to release the string + * alternatively pass ownership to an OUString with + * rtl::OUString(newStr, SAL_NO_ACQUIRE); + * * @param nLen * @return newStr */ -I18NUTIL_DLLPUBLIC inline rtl_uString * SAL_CALL x_rtl_uString_new_WithLength( sal_Int32 nLen, sal_Int32 _refCount = 0 ) +I18NUTIL_DLLPUBLIC inline rtl_uString * SAL_CALL x_rtl_uString_new_WithLength( sal_Int32 nLen ) { - rtl_uString *newStr = (rtl_uString*) rtl_allocateMemory ( sizeof(rtl_uString) + sizeof(sal_Unicode) * nLen); - newStr->refCount = _refCount; - newStr->length = nLen; - return newStr; + //rtl_uString contains sal_Unicode buffer[1], so an input of nLen allocates + //a buffer of nLen + 1 + rtl_uString *newStr = (rtl_uString*) rtl_allocateMemory ( sizeof(rtl_uString) + sizeof(sal_Unicode) * nLen); + newStr->refCount = 1; + newStr->length = nLen; + return newStr; } /** diff --git a/i18nutil/source/utility/widthfolding.cxx b/i18nutil/source/utility/widthfolding.cxx index ed636b2e5cc4..edfe573e70be 100644 --- a/i18nutil/source/utility/widthfolding.cxx +++ b/i18nutil/source/utility/widthfolding.cxx @@ -55,7 +55,8 @@ OUString widthfolding::decompose_ja_voiced_sound_marks (const OUString& inStr, s { // Create a string buffer which can hold nCount * 2 + 1 characters. // Its size may become double of nCount. - rtl_uString * newStr = x_rtl_uString_new_WithLength(nCount * 2 ); // defined in x_rtl_ustring.h The reference count is 0 now. + // The reference count is 1 now. + rtl_uString * newStr = x_rtl_uString_new_WithLength(nCount * 2); sal_Int32 *p = NULL; sal_Int32 position = 0; @@ -99,7 +100,7 @@ OUString widthfolding::decompose_ja_voiced_sound_marks (const OUString& inStr, s newStr->length = sal_Int32(dst - newStr->buffer); if (useOffset) offset.realloc(newStr->length); - return OUString( newStr ); // defined in rtl/usrting. The reference count is increased from 0 to 1. + return OUString(newStr, SAL_NO_ACQUIRE); // take ownership } oneToOneMapping& widthfolding::getfull2halfTable(void) @@ -116,8 +117,8 @@ OUString widthfolding::compose_ja_voiced_sound_marks (const OUString& inStr, sal { // Create a string buffer which can hold nCount + 1 characters. // Its size may become equal to nCount or smaller. - // The reference count is 0 now. - rtl_uString * newStr = x_rtl_uString_new_WithLength( nCount ); // defined in x_rtl_ustring.h + // The reference count is 1 now. + rtl_uString * newStr = x_rtl_uString_new_WithLength(nCount); // Prepare pointers of unicode character arrays. const sal_Unicode* src = inStr.getStr() + startPos; @@ -204,7 +205,7 @@ OUString widthfolding::compose_ja_voiced_sound_marks (const OUString& inStr, sal } if (useOffset) offset.realloc(newStr->length); - return OUString( newStr ); // defined in rtl/usrting. The reference count is increased from 0 to 1. + return OUString(newStr, SAL_NO_ACQUIRE); // take ownership } oneToOneMapping& widthfolding::gethalf2fullTable(void) |