Kaydet (Commit) 23854ea2 authored tarafından Caolán McNamara's avatar Caolán McNamara

refactor x_rtl_uString_new_WithLength to be consistent

i.e. change x_rtl_uString_new_WithLength to always create a rtl_uString
with ref count of 1, like rtl_uString_new_WithLength, so requiring:

either the explicit use of rtl_uString_release or
passing ownership to an OUString via OUString(pStr, SAL_NO_ACQUIRE)
which will do the same in its dtor
üst 5e51cc84
......@@ -99,7 +99,7 @@ cclass_Unicode::toTitle( const OUString& Text, sal_Int32 nPos, sal_Int32 nCount,
nCount = len - nPos;
trans->setMappingType(MappingTypeToTitle, rLocale);
rtl_uString* pStr = x_rtl_uString_new_WithLength( nCount, 1 );
rtl_uString* pStr = x_rtl_uString_new_WithLength(nCount);
sal_Unicode* out = pStr->buffer;
BreakIteratorImpl brk(xMSF);
Boundary bdy = brk.getWordBoundary(Text, nPos, rLocale,
......
......@@ -83,7 +83,8 @@ OUString SAL_CALL AsciiToNativeChar( const OUString& inStr, sal_Int32 startPos,
if (useOffset)
offset.realloc(nCount);
for (sal_Int32 i = 0; i < nCount; i++) {
for (sal_Int32 i = 0; i < nCount; i++)
{
sal_Unicode ch = src[i];
if (isNumber(ch))
newStr->buffer[i] = NumberChar[number][ ch - NUMBER_ZERO ];
......@@ -99,7 +100,7 @@ OUString SAL_CALL AsciiToNativeChar( const OUString& inStr, sal_Int32 startPos,
if (useOffset)
offset[i] = startPos + i;
}
return OUString(newStr->buffer, nCount);
return OUString(newStr, SAL_NO_ACQUIRE); // take ownership
}
sal_Bool SAL_CALL AsciiToNative_numberMaker(const sal_Unicode *str, sal_Int32 begin, sal_Int32 len,
......
......@@ -86,11 +86,11 @@ TextConversion_zh::getCharConversion(const OUString& aText, sal_Int32 nStartPos,
Index = ((const sal_uInt16* (*)())getFunctionBySymbol("getSTC_CharIndex_S2T"))();
}
rtl_uString * newStr = x_rtl_uString_new_WithLength( nLength ); // defined in x_rtl_ustring.h
rtl_uString * newStr = x_rtl_uString_new_WithLength(nLength);
for (sal_Int32 i = 0; i < nLength; i++)
newStr->buffer[i] =
getOneCharConversion(aText[nStartPos+i], Data, Index);
return OUString( newStr->buffer, nLength);
return OUString(newStr, SAL_NO_ACQUIRE); //take ownership
}
OUString SAL_CALL
......
......@@ -87,8 +87,8 @@ ignoreIandEfollowedByYa_ja_JP::folding( const OUString& inStr, sal_Int32 startPo
throw(RuntimeException)
{
// Create a string buffer which can hold nCount + 1 characters.
// 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);
sal_Unicode * dst = newStr->buffer;
const sal_Unicode * src = inStr.getStr() + startPos;
......@@ -145,7 +145,7 @@ ignoreIandEfollowedByYa_ja_JP::folding( const OUString& inStr, sal_Int32 startPo
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
}
} } } }
......
......@@ -102,8 +102,8 @@ ignoreIterationMark_ja_JP::folding( const OUString& inStr, sal_Int32 startPos, s
oneToOneMapping aTable(ignoreIterationMark_ja_JP_mappingTable, sizeof(ignoreIterationMark_ja_JP_mappingTable));
// Create a string buffer which can hold nCount + 1 characters.
// 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);
sal_Unicode * dst = newStr->buffer;
const sal_Unicode * src = inStr.getStr() + startPos;
......@@ -152,7 +152,7 @@ ignoreIterationMark_ja_JP::folding( const OUString& inStr, sal_Int32 startPos, 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
}
......
......@@ -47,8 +47,8 @@ ignoreKiKuFollowedBySa_ja_JP::folding( const OUString& inStr, sal_Int32 startPos
throw(RuntimeException)
{
// Create a string buffer which can hold nCount + 1 characters.
// 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);
sal_Unicode * dst = newStr->buffer;
const sal_Unicode * src = inStr.getStr() + startPos;
......@@ -102,7 +102,7 @@ ignoreKiKuFollowedBySa_ja_JP::folding( const OUString& inStr, sal_Int32 startPos
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
}
} } } }
......
......@@ -309,8 +309,8 @@ ignoreProlongedSoundMark_ja_JP::folding( const OUString& inStr, sal_Int32 startP
throw(RuntimeException)
{
// Create a string buffer which can hold nCount + 1 characters.
// 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);
sal_Unicode * dst = newStr->buffer;
const sal_Unicode * src = inStr.getStr() + startPos;
......@@ -360,7 +360,7 @@ ignoreProlongedSoundMark_ja_JP::folding( const OUString& inStr, sal_Int32 startP
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
}
......
......@@ -137,8 +137,8 @@ transliteration_Ignore::folding( const OUString& inStr, sal_Int32 startPos,
throw(RuntimeException)
{
// Create a string buffer which can hold nCount + 1 characters.
// 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);
sal_Unicode * dst = newStr->buffer;
const sal_Unicode * src = inStr.getStr() + startPos;
......@@ -209,7 +209,7 @@ transliteration_Ignore::folding( const OUString& inStr, sal_Int32 startPos,
offset.realloc(newStr->length);
*dst = (sal_Unicode) 0;
return OUString( newStr ); // defined in rtl/usrting. The reference count is increased from 0 to 1.
return OUString(newStr, SAL_NO_ACQUIRE); // take ownership
}
sal_Unicode SAL_CALL
......
......@@ -78,7 +78,7 @@ transliteration_Numeric::transliterateBullet( const OUString& inStr, sal_Int32 s
if (endPos > inStr.getLength())
endPos = inStr.getLength();
rtl_uString* pStr = x_rtl_uString_new_WithLength( nCount, 1 ); // our x_rtl_ustring.h
rtl_uString* pStr = x_rtl_uString_new_WithLength(nCount);
sal_Unicode* out = pStr->buffer;
if (useOffset)
......
......@@ -74,8 +74,8 @@ transliteration_OneToOne::transliterate( const OUString& inStr, sal_Int32 startP
throw(RuntimeException)
{
// Create a string buffer which can hold nCount + 1 characters.
// 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);
sal_Unicode * dst = newStr->buffer;
const sal_Unicode * src = inStr.getStr() + startPos;
......@@ -97,7 +97,7 @@ transliteration_OneToOne::transliterate( const OUString& inStr, sal_Int32 startP
}
*dst = (sal_Unicode) 0;
return OUString( newStr ); // defined in rtl/usrting. The reference count is increased from 0 to 1.
return OUString(newStr, SAL_NO_ACQUIRE); // take ownership
}
sal_Unicode SAL_CALL
......
......@@ -129,7 +129,7 @@ Transliteration_body::transliterate(
const Mapping &map = casefolding::getValue( in, i, nCount, aLocale, nTmpMappingType );
nOffCount += map.nmap;
}
rtl_uString* pStr = x_rtl_uString_new_WithLength( nOffCount, 1 ); // our x_rtl_ustring.h
rtl_uString* pStr = x_rtl_uString_new_WithLength(nOffCount);
sal_Unicode* out = pStr->buffer;
if ( nOffCount != offset.getLength() )
......@@ -199,7 +199,7 @@ OUString SAL_CALL
Transliteration_body::transliterateChar2String( sal_Unicode inChar ) throw(RuntimeException)
{
const Mapping &map = casefolding::getValue(&inChar, 0, 1, aLocale, nMappingType);
rtl_uString* pStr = x_rtl_uString_new_WithLength( map.nmap, 1 ); // our x_rtl_ustring.h
rtl_uString* pStr = x_rtl_uString_new_WithLength(map.nmap);
sal_Unicode* out = pStr->buffer;
sal_Int32 i;
......
......@@ -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;
}
/**
......
......@@ -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)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment