[Libreoffice-commits] core.git: i18npool/source
Khaled Hosny
khaledhosny at eglug.org
Wed Jan 18 01:18:15 UTC 2017
i18npool/source/transliteration/ignoreDiacritics_CTL.cxx | 51 ++++++++-------
1 file changed, 29 insertions(+), 22 deletions(-)
New commits:
commit fa2eb4b43fc872c171129d477cfabe9fa29d78ce
Author: Khaled Hosny <khaledhosny at eglug.org>
Date: Tue Jan 17 15:15:36 2017 +0200
Some cleanups, tdf#105170 follow-up
* Do some sanity checks on the arguments.
* Use OUStringBuffer and append to it, instead of OUString.
* Fold the string at once when offsets aren’t needed.
Change-Id: I9c450f4cbb938b18ddfec2b9aca12a290b114c98
Reviewed-on: https://gerrit.libreoffice.org/33219
Reviewed-by: Eike Rathke <erack at redhat.com>
Tested-by: Jenkins <ci at libreoffice.org>
diff --git a/i18npool/source/transliteration/ignoreDiacritics_CTL.cxx b/i18npool/source/transliteration/ignoreDiacritics_CTL.cxx
index c910b94..7f611bb 100644
--- a/i18npool/source/transliteration/ignoreDiacritics_CTL.cxx
+++ b/i18npool/source/transliteration/ignoreDiacritics_CTL.cxx
@@ -7,9 +7,10 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
+#include <rtl/ustrbuf.hxx>
#include <transliteration_Ignore.hxx>
-#include <unicode/uchar.h>
#include <unicode/translit.h>
+#include <unicode/uchar.h>
namespace com { namespace sun { namespace star { namespace i18n {
@@ -56,37 +57,43 @@ ignoreDiacritics_CTL::folding(const OUString& rInStr, sal_Int32 nStartPos,
if (!m_transliterator)
throw css::uno::RuntimeException();
- OUString aOutStr;
+ if (nStartPos < 0 || nStartPos + nCount > rInStr.getLength())
+ throw css::uno::RuntimeException();
- sal_Int32 nPosition = nStartPos;
- sal_Int32 nOffset = 0;
if (useOffset)
+ {
+ OUStringBuffer aOutBuf(nCount);
rOffset.realloc(nCount);
- while (nPosition < nStartPos + nCount)
- {
- sal_Int32 nIndex = nPosition;
- UChar32 nChar = rInStr.iterateCodePoints(&nIndex);
- UnicodeString aChar(nChar);
- m_transliterator->transliterate(aChar);
+ sal_Int32 nPosition = nStartPos;
+ sal_Int32 nOffset = 0;
+ while (nPosition < nStartPos + nCount)
+ {
+ sal_Int32 nIndex = nPosition;
+ UChar32 nChar = rInStr.iterateCodePoints(&nIndex);
+ UnicodeString aUStr(nChar);
+ m_transliterator->transliterate(aUStr);
- if (useOffset && nOffset + aChar.length() > rOffset.getLength())
- rOffset.realloc(rOffset.getLength() + aChar.length());
+ if (nOffset + aUStr.length() > rOffset.getLength())
+ rOffset.realloc(rOffset.getLength() + aUStr.length());
- for (int32_t i = 0; i < aChar.length(); i++)
- {
- aOutStr += OUStringLiteral1(aChar[i]);
- if (useOffset)
+ aOutBuf.append(reinterpret_cast<const sal_Unicode*>(aUStr.getBuffer()), aUStr.length());
+
+ for (int32_t i = 0; i < aUStr.length(); i++)
rOffset[nOffset++] = nPosition;
+
+ nPosition = nIndex;
}
- nPosition = nIndex;
+ rOffset.realloc(aOutBuf.getLength());
+ return aOutBuf.makeStringAndClear();
+ }
+ else
+ {
+ UnicodeString aUStr(reinterpret_cast<const UChar*>(rInStr.getStr()) + nStartPos, nCount);
+ m_transliterator->transliterate(aUStr);
+ return OUString(reinterpret_cast<const sal_Unicode*>(aUStr.getBuffer()), aUStr.length());
}
-
- if (useOffset)
- rOffset.realloc(aOutStr.getLength());
-
- return aOutStr;
}
} } } }
More information about the Libreoffice-commits
mailing list