svx/source/dialog/fntctrl.cxx |   21 ++++++---------------
 1 file changed, 6 insertions(+), 15 deletions(-)

New commits:
commit d8326fc81f7225047178e1b8a7605d32109fa08c
Author:     Julien Nabet <serval2...@yahoo.fr>
AuthorDate: Thu Sep 1 18:00:35 2022 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Fri Sep 2 09:34:51 2022 +0200

    tdf#150712: Format->Conditional->Condition 100% CPU (2nd try)
    
    Change-Id: I5f7fe01141ecd057840c01a9080ff7fd2b941049
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/139226
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>

diff --git a/svx/source/dialog/fntctrl.cxx b/svx/source/dialog/fntctrl.cxx
index 58b412f1e822..a2d466c1e232 100644
--- a/svx/source/dialog/fntctrl.cxx
+++ b/svx/source/dialog/fntctrl.cxx
@@ -122,18 +122,11 @@ void setFont(const SvxFont& rNewFont, SvxFont& rImplFont)
  * removes line feeds and carriage returns from string
  * returns if param is empty
  */
-bool CleanAndCheckEmpty(OUString& rText)
+OUString removeCRLF(const OUString& rText)
 {
-    bool bEmpty = true;
-    for (sal_Int32 i = 0; i < rText.getLength(); ++i)
-    {
-        if (0xa == rText[i] || 0xd == rText[i])
-            rText = rText.replaceAt(i, 1, u" ");
-        else
-            bEmpty = false;
-    }
-    return bEmpty;
+    return rText.replace(0xa, ' ').replace(0xd, ' ').trim();
 }
+
 } // end anonymous namespace
 
 class FontPrevWin_Impl
@@ -635,9 +628,9 @@ void SvxFontPrevWindow::Paint(vcl::RenderContext& 
rRenderContext, const tools::R
 
             if (pSh && !pImpl->mbGetSelection && !pImpl->mbUseFontNameAsText)
             {
-                pImpl->maText = pSh->GetSelectionText();
+                pImpl->maText = removeCRLF(pSh->GetSelectionText());
                 pImpl->mbGetSelection = true;
-                pImpl->mbSelection = !CleanAndCheckEmpty(pImpl->maText);
+                pImpl->mbSelection = !(pImpl->maText.isEmpty());
             }
 
             if (!pImpl->mbSelection || pImpl->mbUseFontNameAsText)
@@ -670,9 +663,7 @@ void SvxFontPrevWindow::Paint(vcl::RenderContext& 
rRenderContext, const tools::R
                 pImpl->maText = makeRepresentativeTextForFont(LATIN, rFont);
             }
 
-            bool bEmpty = CleanAndCheckEmpty(pImpl->maText);
-            if (bEmpty)
-                pImpl->maText = OUString();
+            pImpl->maText = removeCRLF(pImpl->maText);
 
             if (pImpl->maText.getLength() > (TEXT_WIDTH - 1))
             {

Reply via email to