unotools/source/misc/fontdefs.cxx |   43 +++++++++++++++++---------------------
 1 file changed, 20 insertions(+), 23 deletions(-)

New commits:
commit 90d4b93c5a7e25498dce949ac6fd2e33d53b74af
Author:     Caolán McNamara <caol...@redhat.com>
AuthorDate: Sun Jun 12 13:01:04 2022 +0100
Commit:     Caolán McNamara <caol...@redhat.com>
CommitDate: Sun Jun 12 18:31:47 2022 +0200

    crashtesting: forum-mso-de-92960 GetEnglishSearchFontName varying results
    
    depending on if it's called once, or twice on the input string.
    
    The first converts from Full-Width Characters to equivalent lower ASCII
    range with non letters retained. And then the second iteration would
    convert to lower case ASCII with non letters filtered out. Presumably
    the intention is the Full-Width case should get directly to the same
    results as multiple calls.
    
    Change-Id: Idba4ebe04c907c160ee53abf6d5551550da032dd
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/135678
    Tested-by: Jenkins
    Reviewed-by: Caolán McNamara <caol...@redhat.com>

diff --git a/unotools/source/misc/fontdefs.cxx 
b/unotools/source/misc/fontdefs.cxx
index 44147ffd0927..49f0d09c65cb 100644
--- a/unotools/source/misc/fontdefs.cxx
+++ b/unotools/source/misc/fontdefs.cxx
@@ -227,20 +227,24 @@ OUString StripScriptFromName(const OUString& _aName)
 }
 
 //return true if the character is stripped from the string
-static bool toOnlyLowerAscii(sal_Unicode c, OUStringBuffer &rName, sal_Int32 
nIndex, sal_Int32& rLen)
+static bool toOnlyLowerAsciiOrStrip(sal_Unicode c, OUStringBuffer &rName, 
sal_Int32 nIndex, sal_Int32& rLen)
 {
-    // To Lowercase-Ascii
-    if ( (c >= 'A') && (c <= 'Z') )
+    // not lowercase Ascii
+    if (c < 'a' || c > 'z')
     {
-        c += 'a' - 'A';
-        rName[nIndex] = c;
-    }
-    else if( ((c < '0') || (c > '9')) && (c != ';') && (c != '(') && (c != 
')') ) // not 0-9, semicolon, or brackets
-    {
-        // Remove white spaces and special characters
-        rName.remove(nIndex, 1);
-        rLen--;
-        return true;
+        // To Lowercase-Ascii
+        if ( (c >= 'A') && (c <= 'Z') )
+        {
+            c += 'a' - 'A';
+            rName[nIndex] = c;
+        }
+        else if( ((c < '0') || (c > '9')) && (c != ';') && (c != '(') && (c != 
')') ) // not 0-9, semicolon, or brackets
+        {
+            // Remove white spaces and special characters
+            rName.remove(nIndex, 1);
+            rLen--;
+            return true;
+        }
     }
     return false;
 }
@@ -273,12 +277,9 @@ OUString GetEnglishSearchFontName(std::u16string_view 
rInName)
             if ( (c >= 0xFF00) && (c <= 0xFF5E) )
             {
                 c -= 0xFF00-0x0020;
-                // Upper to Lower
-                if ( (c >= 'A') && (c <= 'Z') )
-                    c += 'a' - 'A';
-
                 rName[ i ] = c;
-
+                if (toOnlyLowerAsciiOrStrip(c, rName, i, nLen))
+                   continue;
             }
             else
             {
@@ -286,12 +287,8 @@ OUString GetEnglishSearchFontName(std::u16string_view 
rInName)
                 bNeedTranslation = true;
             }
         }
-        // not lowercase Ascii
-        else if ( (c < 'a') || (c > 'z') )
-        {
-            if (toOnlyLowerAscii(c, rName, i, nLen))
-               continue;
-        }
+        else if (toOnlyLowerAsciiOrStrip(c, rName, i, nLen))
+            continue;
 
         i++;
     }

Reply via email to