Kaydet (Commit) 8e1a7034 authored tarafından Michael Jaumann's avatar Michael Jaumann Kaydeden (comit) Michael Meeks

fdo#82854 - use OUStringBuffer in fontdefs.cxx plus unit-test.

Change-Id: Ia3a4814467ed98bd3b1889991cc3644c0c23f515
üst 253b97cc
# -*- 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:
......@@ -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:
/* -*- 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: */
......@@ -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 )
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment