From 087dd70dac798ffe0448e2183614182442ebcc60 Mon Sep 17 00:00:00 2001 From: Norbert Thiebaud Date: Sat, 24 Nov 2012 00:06:37 -0600 Subject: convert first and replace after the original code was converting one character at the time from whatever codepage of the input stream to unicode just to be able to substitute the 'euro' character that apparently is somehow not converted properly (why this is hacked here rather than fixed in the code page converted is another story) the change consist in translating the 'native' euro character in whatever the converter think it should be, then converting the whole string at once to Unicode and finally replace the 'bad' euro character representation with the the 'good' one. This turn the allocation pattern for O(N) to O(1) where N is the length of the string. Change-Id: Ie7ffeb813346953f539cf6dc34b43f890d8b970f --- svl/source/numbers/zformat.cxx | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/svl/source/numbers/zformat.cxx b/svl/source/numbers/zformat.cxx index fe50e90ff98d..3b9f457de3a9 100644 --- a/svl/source/numbers/zformat.cxx +++ b/svl/source/numbers/zformat.cxx @@ -1898,25 +1898,15 @@ rtl::OUString SvNumberformat::LoadString( SvStream& rStream ) CharSet eStream = rStream.GetStreamCharSet(); rtl::OString aStr = read_lenPrefixed_uInt8s_ToOString(rStream); sal_Char cStream = NfCurrencyEntry::GetEuroSymbol( eStream ); - if (aStr.indexOf(cStream) == -1) + if (aStr.indexOf(cStream) < 0) { // simple conversion to unicode return rtl::OStringToOUString(aStr, eStream); } - + sal_Unicode cSource = OUString(&cStream, 1, eStream).toChar(); sal_Unicode cTarget = NfCurrencyEntry::GetEuroSymbol(); - rtl::OUStringBuffer aBuf(aStr.getLength()); - for (sal_Int32 i = 0; i < aStr.getLength(); ++i) - { - if (aStr[i] == cStream) - { - aBuf.append(cTarget); - } - else - { - aBuf.append(rtl::OUString(aStr.getStr()+i, 1, eStream).toChar()); - } - } + rtl::OUStringBuffer aBuf(rtl::OStringToOUString(aStr, eStream)); + aBuf.replace(cSource, cTarget); return aBuf.makeStringAndClear(); } -- cgit v1.2.3