summaryrefslogtreecommitdiff
path: root/i18npool
diff options
context:
space:
mode:
authorCaolán McNamara <caolanm@redhat.com>2011-08-31 22:38:04 +0100
committerCaolán McNamara <caolanm@redhat.com>2011-09-01 09:53:36 +0100
commit5e51cc84d9a9885cc081dd409697244dcd7a67c8 (patch)
tree9521ec9abe8923ea3e200a0d266b4568ac004015 /i18npool
parent5ba602cbf06a51c8889a3e6357442d32ffb792ab (diff)
these don't actually take ownership, just copy and leak original
Diffstat (limited to 'i18npool')
-rw-r--r--i18npool/source/nativenumber/nativenumbersupplier.cxx64
-rw-r--r--i18npool/source/textconversion/textconversion_ko.cxx16
-rw-r--r--i18npool/source/textconversion/textconversion_zh.cxx16
3 files changed, 56 insertions, 40 deletions
diff --git a/i18npool/source/nativenumber/nativenumbersupplier.cxx b/i18npool/source/nativenumber/nativenumbersupplier.cxx
index cb170b6e1fd1..933a2f548d4a 100644
--- a/i18npool/source/nativenumber/nativenumbersupplier.cxx
+++ b/i18npool/source/nativenumber/nativenumbersupplier.cxx
@@ -177,32 +177,36 @@ sal_Bool SAL_CALL AsciiToNative_numberMaker(const sal_Unicode *str, sal_Int32 be
OUString SAL_CALL AsciiToNative( const OUString& inStr, sal_Int32 startPos, sal_Int32 nCount,
Sequence< sal_Int32 >& offset, sal_Bool useOffset, Number* number ) throw(RuntimeException)
{
+ rtl::OUString aRet;
+
sal_Int32 strLen = inStr.getLength() - startPos;
sal_Unicode *numberChar = NumberChar[number->number];
if (nCount > strLen)
nCount = strLen;
- if (nCount > 0) {
+ if (nCount > 0)
+ {
const sal_Unicode *str = inStr.getStr() + startPos;
- rtl_uString *newStr = x_rtl_uString_new_WithLength(nCount * 2);
- rtl_uString *srcStr = x_rtl_uString_new_WithLength(nCount); // for keeping number without comma
+ sal_Unicode *newStr = new sal_Unicode[nCount * 2 + 1];
+ sal_Unicode *srcStr = new sal_Unicode[nCount + 1]; // for keeping number without comma
sal_Int32 i, len = 0, count = 0;
if (useOffset)
offset.realloc( nCount * 2 );
sal_Bool doDecimal = sal_False;
- for (i = 0; i <= nCount; i++) {
+ for (i = 0; i <= nCount; i++)
+ {
if (i < nCount && isNumber(str[i])) {
if (doDecimal) {
- newStr->buffer[count] = numberChar[str[i] - NUMBER_ZERO];
+ newStr[count] = numberChar[str[i] - NUMBER_ZERO];
if (useOffset)
offset[count] = i + startPos;
count++;
}
else
- srcStr->buffer[len++] = str[i];
+ srcStr[len++] = str[i];
} else {
if (len > 0) {
if (isSeparator(str[i]) && i < nCount-1 && isNumber(str[i+1]))
@@ -212,14 +216,14 @@ OUString SAL_CALL AsciiToNative( const OUString& inStr, sal_Int32 startPos, sal_
end <= len; begin = end, end += number->multiplierExponent[0]) {
if (end == 0) continue;
sal_Int32 _count = count;
- notZero |= AsciiToNative_numberMaker(srcStr->buffer, begin, end - begin, newStr->buffer, count,
+ notZero |= AsciiToNative_numberMaker(srcStr, begin, end - begin, newStr, count,
end == len ? -1 : 0, offset, useOffset, i - len + startPos, number, numberChar);
if (count > 0 && number->multiplierExponent[number->exponentCount-1] == 1 &&
- newStr->buffer[count-1] == numberChar[0])
+ newStr[count-1] == numberChar[0])
count--;
if (notZero && _count == count) {
if (end != len) {
- newStr->buffer[count] = number->multiplierChar[0];
+ newStr[count] = number->multiplierChar[0];
if (useOffset)
offset[count] = i - len + startPos;
count++;
@@ -227,7 +231,7 @@ OUString SAL_CALL AsciiToNative( const OUString& inStr, sal_Int32 startPos, sal_
}
}
if (! notZero && ! (number->numberFlag & NUMBER_OMIT_ONLY_ZERO)) {
- newStr->buffer[count] = numberChar[0];
+ newStr[count] = numberChar[0];
if (useOffset)
offset[count] = i - len + startPos;
count++;
@@ -236,13 +240,13 @@ OUString SAL_CALL AsciiToNative( const OUString& inStr, sal_Int32 startPos, sal_
}
if (i < nCount) {
if ((doDecimal = (!doDecimal && isDecimal(str[i]) && i < nCount-1 && isNumber(str[i+1]))) != sal_False)
- newStr->buffer[count] = (DecimalChar[number->number] ? DecimalChar[number->number] : str[i]);
+ newStr[count] = (DecimalChar[number->number] ? DecimalChar[number->number] : str[i]);
else if (isMinus(str[i]) && i < nCount-1 && isNumber(str[i+1]))
- newStr->buffer[count] = (MinusChar[number->number] ? MinusChar[number->number] : str[i]);
+ newStr[count] = (MinusChar[number->number] ? MinusChar[number->number] : str[i]);
else if (isSeparator(str[i]) && i < nCount-1 && isNumber(str[i+1]))
- newStr->buffer[count] = (SeparatorChar[number->number] ? SeparatorChar[number->number] : str[i]);
+ newStr[count] = (SeparatorChar[number->number] ? SeparatorChar[number->number] : str[i]);
else
- newStr->buffer[count] = str[i];
+ newStr[count] = str[i];
if (useOffset)
offset[count] = i + startPos;
count++;
@@ -250,11 +254,14 @@ OUString SAL_CALL AsciiToNative( const OUString& inStr, sal_Int32 startPos, sal_
}
}
+ delete[] srcStr;
+
if (useOffset)
offset.realloc(count);
- return OUString(newStr->buffer, count);
+ aRet = OUString(newStr, count);
+ delete[] newStr;
}
- return OUString();
+ return aRet;
}
static void SAL_CALL NativeToAscii_numberMaker(sal_Int16 max, sal_Int16 prev, const sal_Unicode *str,
sal_Int32& i, sal_Int32 nCount, sal_Unicode *dst, sal_Int32& count, Sequence< sal_Int32 >& offset, sal_Bool useOffset,
@@ -308,6 +315,8 @@ static void SAL_CALL NativeToAscii_numberMaker(sal_Int16 max, sal_Int16 prev, co
static OUString SAL_CALL NativeToAscii(const OUString& inStr,
sal_Int32 startPos, sal_Int32 nCount, Sequence< sal_Int32 >& offset, sal_Bool useOffset ) throw(RuntimeException)
{
+ OUString aRet;
+
sal_Int32 strLen = inStr.getLength() - startPos;
if (nCount > strLen)
@@ -315,7 +324,7 @@ static OUString SAL_CALL NativeToAscii(const OUString& inStr,
if (nCount > 0) {
const sal_Unicode *str = inStr.getStr() + startPos;
- rtl_uString *newStr = x_rtl_uString_new_WithLength(nCount * MultiplierExponent_7_CJK[0] + 1);
+ sal_Unicode *newStr = new sal_Unicode[nCount * MultiplierExponent_7_CJK[0] + 2];
if (useOffset)
offset.realloc( nCount * MultiplierExponent_7_CJK[0] + 1 );
sal_Int32 count = 0, index;
@@ -330,8 +339,8 @@ static OUString SAL_CALL NativeToAscii(const OUString& inStr,
for ( i = 0; i < nCount; i++) {
if ((index = multiplierChar.indexOf(str[i])) >= 0) {
- if (count == 0 || !isNumber(newStr->buffer[count-1])) { // add 1 in front of multiplier
- newStr->buffer[count] = NUMBER_ONE;
+ if (count == 0 || !isNumber(newStr[count-1])) { // add 1 in front of multiplier
+ newStr[count] = NUMBER_ONE;
if (useOffset)
offset[count] = i;
count++;
@@ -339,29 +348,29 @@ static OUString SAL_CALL NativeToAscii(const OUString& inStr,
index = MultiplierExponent_7_CJK[index % ExponentCount_7_CJK];
NativeToAscii_numberMaker(
sal::static_int_cast<sal_Int16>( index ), sal::static_int_cast<sal_Int16>( index ),
- str, i, nCount, newStr->buffer, count, offset, useOffset,
+ str, i, nCount, newStr, count, offset, useOffset,
numberChar, multiplierChar);
} else {
if ((index = numberChar.indexOf(str[i])) >= 0)
- newStr->buffer[count] = sal::static_int_cast<sal_Unicode>( (index % 10) + NUMBER_ZERO );
+ newStr[count] = sal::static_int_cast<sal_Unicode>( (index % 10) + NUMBER_ZERO );
else if ((index = separatorChar.indexOf(str[i])) >= 0 &&
(i < nCount-1 && (numberChar.indexOf(str[i+1]) >= 0 ||
multiplierChar.indexOf(str[i+1]) >= 0)))
- newStr->buffer[count] = SeparatorChar[NumberChar_HalfWidth];
+ newStr[count] = SeparatorChar[NumberChar_HalfWidth];
else if ((index = decimalChar.indexOf(str[i])) >= 0 &&
(i < nCount-1 && (numberChar.indexOf(str[i+1]) >= 0 ||
multiplierChar.indexOf(str[i+1]) >= 0)))
// Only when decimal point is followed by numbers,
// it will be convert to ASCII decimal point
- newStr->buffer[count] = DecimalChar[NumberChar_HalfWidth];
+ newStr[count] = DecimalChar[NumberChar_HalfWidth];
else if ((index = minusChar.indexOf(str[i])) >= 0 &&
(i < nCount-1 && (numberChar.indexOf(str[i+1]) >= 0 ||
multiplierChar.indexOf(str[i+1]) >= 0)))
// Only when minus is followed by numbers,
// it will be convert to ASCII minus sign
- newStr->buffer[count] = MinusChar[NumberChar_HalfWidth];
+ newStr[count] = MinusChar[NumberChar_HalfWidth];
else
- newStr->buffer[count] = str[i];
+ newStr[count] = str[i];
if (useOffset)
offset[count] = i;
count++;
@@ -373,9 +382,10 @@ static OUString SAL_CALL NativeToAscii(const OUString& inStr,
for (i = 0; i < count; i++)
offset[i] += startPos;
}
- return OUString(newStr->buffer, count);
+ aRet = OUString(newStr, count);
+ delete[] newStr;
}
- return OUString();
+ return aRet;
}
static Number natnum4[4] = {
diff --git a/i18npool/source/textconversion/textconversion_ko.cxx b/i18npool/source/textconversion/textconversion_ko.cxx
index 8ebda8005220..9cdc070ff6bf 100644
--- a/i18npool/source/textconversion/textconversion_ko.cxx
+++ b/i18npool/source/textconversion/textconversion_ko.cxx
@@ -159,24 +159,28 @@ TextConversion_ko::getCharConversions(const OUString& aText, sal_Int32 nStartPos
break;
}
}
- } else if (! toHanja && getHanja2HangulIndex && getHanja2HangulData) {
- rtl_uString * newStr = x_rtl_uString_new_WithLength( nLength ); // defined in x_rtl_ustring.h
+ } else if (! toHanja && getHanja2HangulIndex && getHanja2HangulData)
+ {
+ sal_Unicode *newStr = new sal_Unicode[nLength+1];
sal_Int32 count = 0;
- while (count < nLength) {
+ while (count < nLength)
+ {
ch = aText[nStartPos + count];
sal_Unicode address = getHanja2HangulIndex()[ch>>8];
if (address != 0xFFFF)
address = getHanja2HangulData()[address + (ch & 0xFF)];
if (address != 0xFFFF)
- newStr->buffer[count++] = address;
+ newStr[count++] = address;
else
break;
}
- if (count > 0) {
+ if (count > 0)
+ {
output.realloc(1);
- output[0] = OUString( newStr->buffer, count);
+ output[0] = OUString(newStr, count);
}
+ delete[] newStr;
}
return output;
}
diff --git a/i18npool/source/textconversion/textconversion_zh.cxx b/i18npool/source/textconversion/textconversion_zh.cxx
index ddb8a02283fd..b9460eb44119 100644
--- a/i18npool/source/textconversion/textconversion_zh.cxx
+++ b/i18npool/source/textconversion/textconversion_zh.cxx
@@ -125,7 +125,7 @@ TextConversion_zh::getWordConversion(const OUString& aText, sal_Int32 nStartPos,
if ((!wordData || !index || !entry) && !xCDL.is()) // no word mapping defined, do char2char conversion.
return getCharConversion(aText, nStartPos, nLength, toSChinese, nConversionOptions);
- rtl_uString * newStr = x_rtl_uString_new_WithLength( nLength * 2 ); // defined in x_rtl_ustring.h
+ sal_Unicode *newStr = new sal_Unicode[nLength * 2 + 1];
sal_Int32 currPos = 0, count = 0;
while (currPos < nLength) {
sal_Int32 len = nLength - currPos;
@@ -161,12 +161,12 @@ TextConversion_zh::getWordConversion(const OUString& aText, sal_Int32 nStartPos,
while (current < conversions[0].getLength()) {
offset[count] = nStartPos + currPos + (current *
word.getLength() / conversions[0].getLength());
- newStr->buffer[count++] = conversions[0][current++];
+ newStr[count++] = conversions[0][current++];
}
// offset[count-1] = nStartPos + currPos + word.getLength() - 1;
} else {
while (current < conversions[0].getLength())
- newStr->buffer[count++] = conversions[0][current++];
+ newStr[count++] = conversions[0][current++];
}
currPos += word.getLength();
found = sal_True;
@@ -197,12 +197,12 @@ TextConversion_zh::getWordConversion(const OUString& aText, sal_Int32 nStartPos,
while (wordData[current]) {
offset[count]=nStartPos + currPos + ((current-start) *
word.getLength() / convertedLength);
- newStr->buffer[count++] = wordData[current++];
+ newStr[count++] = wordData[current++];
}
// offset[count-1]=nStartPos + currPos + word.getLength() - 1;
} else {
while (wordData[current])
- newStr->buffer[count++] = wordData[current++];
+ newStr[count++] = wordData[current++];
}
currPos += word.getLength();
found = sal_True;
@@ -213,14 +213,16 @@ TextConversion_zh::getWordConversion(const OUString& aText, sal_Int32 nStartPos,
if (!found) {
if (offset.getLength() > 0)
offset[count]=nStartPos+currPos;
- newStr->buffer[count++] =
+ newStr[count++] =
getOneCharConversion(aText[nStartPos+currPos], charData, charIndex);
currPos++;
}
}
if (offset.getLength() > 0)
offset.realloc(one2one ? 0 : count);
- return OUString( newStr->buffer, count);
+ OUString aRet(newStr, count);
+ delete[] newStr;
+ return aRet;
}
TextConversionResult SAL_CALL