[Libreoffice-commits] core.git: i18npool/source

Stephan Bergmann sbergman at redhat.com
Tue Jan 5 06:43:39 PST 2016


 i18npool/source/localedata/localedata.cxx |   36 ------------------------------
 1 file changed, 1 insertion(+), 35 deletions(-)

New commits:
commit c83b55564dab042e3fc1889920cbb4db8fe40117
Author: Stephan Bergmann <sbergman at redhat.com>
Date:   Tue Jan 5 15:41:52 2016 +0100

    Use OUString::replaceAll
    
    ...instead of a local function using a static (!) buffer, which just cannot work
    in a multi-threaded environment.
    
    Change-Id: Id28e1c55c32aa2e35cd3c1756f5d392241092a30

diff --git a/i18npool/source/localedata/localedata.cxx b/i18npool/source/localedata/localedata.cxx
index d685dd5..e91ac3f3 100644
--- a/i18npool/source/localedata/localedata.cxx
+++ b/i18npool/source/localedata/localedata.cxx
@@ -816,40 +816,6 @@ LocaleDataImpl::getAllCurrencies( const Locale& rLocale ) throw(RuntimeException
 }
 
 
-// return a static (!) string resulting from replacing all occurrences of
-// 'oldStr' string in 'formatCode' string with 'newStr' string
-static const sal_Unicode * replace( sal_Unicode const * const formatCode, sal_Unicode const * const oldStr, sal_Unicode const * const newStr)
-{
-    // make reasonable assumption of maximum length of formatCode.
-#define MAX_FORMATCODE_LENTH 512
-    static sal_Unicode str[MAX_FORMATCODE_LENTH];
-
-    if (oldStr[0] == 0) // no replacement requires
-        return formatCode;
-
-    sal_Int32 i = 0, k = 0;
-    while (formatCode[i] > 0 && k < MAX_FORMATCODE_LENTH) {
-        sal_Int32 j = 0, last = k;
-        // search oldStr in formatCode
-        while (formatCode[i] > 0 && oldStr[j] > 0 && k < MAX_FORMATCODE_LENTH) {
-            str[k++] = formatCode[i];
-            if (formatCode[i++] != oldStr[j++])
-                break;
-        }
-        if (oldStr[j] == 0) {
-            // matched string found, do replacement
-            k = last; j = 0;
-            while (newStr[j] > 0 && k < MAX_FORMATCODE_LENTH)
-                str[k++] = newStr[j++];
-        }
-    }
-    if (k >= MAX_FORMATCODE_LENTH) // could not complete replacement, return original formatCode
-        return formatCode;
-
-    str[k] = 0;
-    return str;
-}
-
 Sequence< FormatElement > SAL_CALL
 LocaleDataImpl::getAllFormats( const Locale& rLocale ) throw(RuntimeException, std::exception)
 {
@@ -886,7 +852,7 @@ LocaleDataImpl::getAllFormats( const Locale& rLocale ) throw(RuntimeException, s
             for (int i = 0, nOff = 0; i < section[s].formatCount; ++i, nOff += 7, ++f)
             {
                 FormatElement elem(
-                        replace( formatArray[nOff], section[s].from, section[s].to),
+                        OUString(formatArray[nOff]).replaceAll(section[s].from, section[s].to),
                         formatArray[nOff + 1],
                         formatArray[nOff + 2],
                         formatArray[nOff + 3],


More information about the Libreoffice-commits mailing list