summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Jaumann <meta_dev@yahoo.com>2014-09-02 06:49:48 +0000
committerMichael Meeks <michael.meeks@collabora.com>2014-09-08 14:27:19 +0100
commit8e1a7034ff35ee825f3f8f22e14d93189149a1aa (patch)
tree6de827ee3abd1e413f0471c412a422d31f1f97a5
parent253b97cc353731dfec6fa6dc9923f34a946b0d21 (diff)
fdo#82854 - use OUStringBuffer in fontdefs.cxx plus unit-test.
Change-Id: Ia3a4814467ed98bd3b1889991cc3644c0c23f515
-rw-r--r--unotools/CppunitTest_unotools_fontdefs.mk34
-rw-r--r--unotools/Module_unotools.mk3
-rw-r--r--unotools/qa/unit/testGetEnlishSearchName.cxx70
-rw-r--r--unotools/source/misc/fontdefs.cxx30
4 files changed, 116 insertions, 21 deletions
diff --git a/unotools/CppunitTest_unotools_fontdefs.mk b/unotools/CppunitTest_unotools_fontdefs.mk
new file mode 100644
index 000000000000..468838b1298d
--- /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 d450dfc1fe6f..c8a46e33e22c 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 000000000000..38b10eafb516
--- /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 3b6b72278079..be2079fe711a 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 )