unotools/CppunitTest_unotools_fontdefs.mk    |   34 ++++++++++++++++
 unotools/Module_unotools.mk                  |    3 +
 unotools/qa/unit/testGetEnlishSearchName.cxx |   55 +++++++++++++++++++++++++++
 unotools/source/misc/fontdefs.cxx            |   33 ++++------------
 4 files changed, 102 insertions(+), 23 deletions(-)

New commits:
commit 1f7e6bdd23600cf118b786bbeb869949c36297e7
Author: Michael Meeks <michael.me...@collabora.com>
Date:   Mon Sep 8 13:03:03 2014 +0100

    fdo#82854 - cleanup & review bits.
    
    Change-Id: Ia5b2628adb62013a22cf6c5e384154c54abc2294

diff --git a/unotools/qa/unit/testGetEnlishSearchName.cxx 
b/unotools/qa/unit/testGetEnlishSearchName.cxx
index 38b10ea..1701215 100644
--- a/unotools/qa/unit/testGetEnlishSearchName.cxx
+++ b/unotools/qa/unit/testGetEnlishSearchName.cxx
@@ -15,10 +15,8 @@
 #include "cppunit/plugin/TestPlugIn.h"
 #include <unotools/fontdefs.hxx>
 
-
 class Test: public CppUnit::TestFixture
 {
-
 public:
     virtual void setUp() SAL_OVERRIDE;
     void testSingleElement();
@@ -34,36 +32,23 @@ void Test::setUp()
 
 void Test::testSingleElement()
 {
-    {   //lowercase
-        printf("GetEnglishSearchFontName( \"SYMBOL\" )");
+    {   // lowercase
         OUString test1 = GetEnglishSearchFontName( "SYMBOL" );
         CPPUNIT_ASSERT_EQUAL(test1, OUString("symbol"));
-        printf("return %s",test1.getStr());
-        //trailingWhitespaces
-        printf("GetEnglishSearchFontName( \"SYMBOL    \" )");
+        // trailingWhitespaces
         test1 = GetEnglishSearchFontName( "Symbol    " );
         CPPUNIT_ASSERT_EQUAL(test1, OUString("symbol"));
-        printf("return %s",test1.getStr());
-        //removing Skripts
-        printf("GetEnglishSearchFontName( \"SYMBOL(skript)\" )");
+        // removing Skripts
         test1 = GetEnglishSearchFontName( "Symbol(skript)" );
         CPPUNIT_ASSERT_EQUAL(test1, OUString("symbol"));
-        printf("return %s",test1.getStr());
-        //remove Whitespaces between
-        printf("GetEnglishSearchFontName( \"SYMBOL (skript)\" )");
+        // remove Whitespaces between
         test1 = GetEnglishSearchFontName( "Symbol (skript)" );
         CPPUNIT_ASSERT_EQUAL(test1, OUString("symbol"));
-        printf("return %s",test1.getStr());
-        //trailingWhitespaces
-
+        // trailingWhitespaces
     }
-
-
 }
 
 
-
-
 CPPUNIT_TEST_SUITE_REGISTRATION(Test);
 CPPUNIT_PLUGIN_IMPLEMENT();
 
diff --git a/unotools/source/misc/fontdefs.cxx 
b/unotools/source/misc/fontdefs.cxx
index be2079f..4f0fb08 100644
--- a/unotools/source/misc/fontdefs.cxx
+++ b/unotools/source/misc/fontdefs.cxx
@@ -400,7 +400,6 @@ OUString GetEnglishSearchFontName( const OUString& rInName )
             else if( ((c < '0') || (c > '9')) && (c != ';') ) // not 0-9 or 
semicolon
             {
                 // Remove white spaces and special characters
-
                 rName.remove(i,1);
                 nLen--;
                 continue;
@@ -426,7 +425,7 @@ OUString GetEnglishSearchFontName( const OUString& rInName )
 
         FontNameDictionary::const_iterator it = aDictionary.find( rNameStr );
         if( it != aDictionary.end() )
-            rName = OUString::createFromAscii ( it->second );
+            rNameStr = OUString::createFromAscii ( it->second );
     }
 
     return rNameStr;
commit 8e1a7034ff35ee825f3f8f22e14d93189149a1aa
Author: Michael Jaumann <meta_...@yahoo.com>
Date:   Tue Sep 2 06:49:48 2014 +0000

    fdo#82854 - use OUStringBuffer in fontdefs.cxx plus unit-test.
    
    Change-Id: Ia3a4814467ed98bd3b1889991cc3644c0c23f515

diff --git a/unotools/CppunitTest_unotools_fontdefs.mk 
b/unotools/CppunitTest_unotools_fontdefs.mk
new file mode 100644
index 0000000..468838b
--- /dev/null
+++ b/unotools/CppunitTest_unotools_fontdefs.mk
@@ -0,0 +1,34 @@
+# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
+#
+# This file is part of the LibreOffice project.
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+
+$(eval $(call gb_CppunitTest_CppunitTest,unotools_fontdefs))
+
+$(eval $(call gb_CppunitTest_use_external,unotools_fontdefs,boost_headers))
+
+$(eval $(call gb_CppunitTest_use_api,unotools_fontdefs, \
+    offapi \
+    udkapi \
+))
+
+$(eval $(call gb_CppunitTest_add_exception_objects,unotools_fontdefs, \
+    unotools/qa/unit/testGetEnlishSearchName \
+))
+
+$(eval $(call gb_CppunitTest_use_libraries,unotools_fontdefs, \
+       comphelper \
+       cppu \
+       cppuhelper \
+       tl \
+       sal \
+       svt \
+       utl \
+    $(gb_UWINAPI) \
+))
+
+# vim: set noet sw=4 ts=4:
diff --git a/unotools/Module_unotools.mk b/unotools/Module_unotools.mk
index d450dfc..c8a46e3 100644
--- a/unotools/Module_unotools.mk
+++ b/unotools/Module_unotools.mk
@@ -16,5 +16,8 @@ $(eval $(call gb_Module_add_targets,unotools,\
 $(eval $(call gb_Module_add_subsequentcheck_targets,unotools,\
     JunitTest_unotools_complex \
 ))
+$(eval $(call gb_Module_add_check_targets,unotools,\
+    CppunitTest_unotools_fontdefs \
+))
 
 # vim: set noet sw=4 ts=4:
diff --git a/unotools/qa/unit/testGetEnlishSearchName.cxx 
b/unotools/qa/unit/testGetEnlishSearchName.cxx
new file mode 100644
index 0000000..38b10ea
--- /dev/null
+++ b/unotools/qa/unit/testGetEnlishSearchName.cxx
@@ -0,0 +1,70 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ */
+
+#include "cppunit/TestCase.h"
+#include "cppunit/TestFixture.h"
+#include "cppunit/TestSuite.h"
+#include "cppunit/extensions/HelperMacros.h"
+#include "cppunit/plugin/TestPlugIn.h"
+#include <unotools/fontdefs.hxx>
+
+
+class Test: public CppUnit::TestFixture
+{
+
+public:
+    virtual void setUp() SAL_OVERRIDE;
+    void testSingleElement();
+
+    CPPUNIT_TEST_SUITE(Test);
+    CPPUNIT_TEST(testSingleElement);
+
+    CPPUNIT_TEST_SUITE_END();
+};
+
+void Test::setUp()
+{};
+
+void Test::testSingleElement()
+{
+    {   //lowercase
+        printf("GetEnglishSearchFontName( \"SYMBOL\" )");
+        OUString test1 = GetEnglishSearchFontName( "SYMBOL" );
+        CPPUNIT_ASSERT_EQUAL(test1, OUString("symbol"));
+        printf("return %s",test1.getStr());
+        //trailingWhitespaces
+        printf("GetEnglishSearchFontName( \"SYMBOL    \" )");
+        test1 = GetEnglishSearchFontName( "Symbol    " );
+        CPPUNIT_ASSERT_EQUAL(test1, OUString("symbol"));
+        printf("return %s",test1.getStr());
+        //removing Skripts
+        printf("GetEnglishSearchFontName( \"SYMBOL(skript)\" )");
+        test1 = GetEnglishSearchFontName( "Symbol(skript)" );
+        CPPUNIT_ASSERT_EQUAL(test1, OUString("symbol"));
+        printf("return %s",test1.getStr());
+        //remove Whitespaces between
+        printf("GetEnglishSearchFontName( \"SYMBOL (skript)\" )");
+        test1 = GetEnglishSearchFontName( "Symbol (skript)" );
+        CPPUNIT_ASSERT_EQUAL(test1, OUString("symbol"));
+        printf("return %s",test1.getStr());
+        //trailingWhitespaces
+
+    }
+
+
+}
+
+
+
+
+CPPUNIT_TEST_SUITE_REGISTRATION(Test);
+CPPUNIT_PLUGIN_IMPLEMENT();
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/unotools/source/misc/fontdefs.cxx 
b/unotools/source/misc/fontdefs.cxx
index 3b6b722..be2079f 100644
--- a/unotools/source/misc/fontdefs.cxx
+++ b/unotools/source/misc/fontdefs.cxx
@@ -322,8 +322,7 @@ static ImplLocalizedFontName aImplLocalizedNamesList[] =
 
 OUString GetEnglishSearchFontName( const OUString& rInName )
 {
-    OUString rName( rInName );
-
+    OUStringBuffer rName( rInName.getStr());
     bool        bNeedTranslation = false;
     sal_Int32  nLen = rName.getLength();
 
@@ -332,7 +331,7 @@ OUString GetEnglishSearchFontName( const OUString& rInName )
     while ( i && (rName[ i-1 ] < 32) )
         i--;
     if ( i != nLen )
-        rName = rName.copy( 0, i );
+         rName.truncate(i);
 
     // Remove Script at the end
     // Scriptname must be the last part of the fontname and
@@ -352,7 +351,7 @@ OUString GetEnglishSearchFontName( const OUString& rInName )
                     // Remove Space at the end
                     if ( nTempLen && (rName[ nTempLen-1 ] == ' ') )
                         nTempLen--;
-                    rName = rName.copy( 0, nTempLen );
+                    rName.truncate(nTempLen);
                     nLen = nTempLen;
                     break;
                 }
@@ -379,11 +378,8 @@ OUString GetEnglishSearchFontName( const OUString& rInName 
)
                 // Upper to Lower
                 if ( (c >= 'A') && (c <= 'Z') )
                     c += 'a' - 'A';
-                //rName[ i ] = c;
 
-                OUStringBuffer aTmpStr( rName.getStr() );
-                aTmpStr[ i ] = c;
-                rName = aTmpStr.makeStringAndClear();
+                rName[ i ] = c;
 
            }
             else
@@ -399,21 +395,13 @@ OUString GetEnglishSearchFontName( const OUString& 
rInName )
             if ( (c >= 'A') && (c <= 'Z') )
             {
                 c += 'a' - 'A';
-                //rName[ i ] = c;
-
-                OUStringBuffer aTmpStr( rName.getStr() );
-                aTmpStr[ i ] = c;
-                rName = aTmpStr.makeStringAndClear();
-
+                rName[ i ] = c;
             }
             else if( ((c < '0') || (c > '9')) && (c != ';') ) // not 0-9 or 
semicolon
             {
                 // Remove white spaces and special characters
 
-                OUStringBuffer aTmpStr( rName.getStr() );
-                aTmpStr.remove(i,1);
-                rName = aTmpStr.makeStringAndClear();
-
+                rName.remove(i,1);
                 nLen--;
                 continue;
             }
@@ -421,7 +409,7 @@ OUString GetEnglishSearchFontName( const OUString& rInName )
 
         i++;
     }
-
+    OUString rNameStr = rName.makeStringAndClear();
     // translate normalized localized name to its normalized English ASCII name
     if( bNeedTranslation )
     {
@@ -436,12 +424,12 @@ OUString GetEnglishSearchFontName( const OUString& 
rInName )
                 aDictionary[ pList->mpLocalizedNames ] = pList->mpEnglishName;
         }
 
-        FontNameDictionary::const_iterator it = aDictionary.find( rName );
+        FontNameDictionary::const_iterator it = aDictionary.find( rNameStr );
         if( it != aDictionary.end() )
             rName = OUString::createFromAscii ( it->second );
     }
 
-    return rName;
+    return rNameStr;
 }
 
 OUString GetNextFontToken( const OUString& rTokenStr, sal_Int32& rIndex )
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to