From 55eeffe768c6a80c97ee4f2a58fb467872ddeb1d Mon Sep 17 00:00:00 2001
From: Caolán McNamara <caolanm@redhat.com>
Date: Sun, 12 Jun 2022 10:34:43 +0100
Subject: split out the code that extracts a lower-ascii version of a fontname
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Change-Id: I77778ecd075712c41bd29324be090ab4a8351ab9
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/135677
Tested-by: Caolán McNamara <caolanm@redhat.com>
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
---
 unotools/source/misc/fontdefs.cxx | 34 +++++++++++++++++++++-------------
 1 file changed, 21 insertions(+), 13 deletions(-)

(limited to 'unotools')

diff --git a/unotools/source/misc/fontdefs.cxx b/unotools/source/misc/fontdefs.cxx
index 568110315f33..44147ffd0927 100644
--- a/unotools/source/misc/fontdefs.cxx
+++ b/unotools/source/misc/fontdefs.cxx
@@ -226,6 +226,25 @@ OUString StripScriptFromName(const OUString& _aName)
     return 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)
+{
+    // 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;
+}
+
 OUString GetEnglishSearchFontName(std::u16string_view rInName)
 {
     OUStringBuffer rName(rInName);
@@ -270,19 +289,8 @@ OUString GetEnglishSearchFontName(std::u16string_view rInName)
         // not lowercase Ascii
         else if ( (c < 'a') || (c > 'z') )
         {
-            // To Lowercase-Ascii
-            if ( (c >= 'A') && (c <= 'Z') )
-            {
-                c += 'a' - 'A';
-                rName[ i ] = c;
-            }
-            else if( ((c < '0') || (c > '9')) && (c != ';') && (c != '(') && (c != ')') ) // not 0-9, semicolon, or brackets
-            {
-                // Remove white spaces and special characters
-                rName.remove(i,1);
-                nLen--;
-                continue;
-            }
+            if (toOnlyLowerAscii(c, rName, i, nLen))
+               continue;
         }
 
         i++;
-- 
cgit