summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCaolán McNamara <caolanm@redhat.com>2011-11-23 17:24:38 +0000
committerCaolán McNamara <caolanm@redhat.com>2011-11-23 23:16:44 +0000
commit0dbc4fa3efdea90ba23e17e12c2bfe15d763acbf (patch)
tree857875b2edaee72abb836c8235c4bb87e6e6a18b
parent2dba28faae2266e72c05d8f3d55bfbc3e5771adb (diff)
add string::strip, can replace EraseLeadingAndTrailingChars
-rw-r--r--comphelper/inc/comphelper/string.hxx20
-rw-r--r--comphelper/qa/string/test_string.cxx22
-rw-r--r--comphelper/source/misc/string.cxx10
-rw-r--r--l10ntools/source/export2.cxx4
-rw-r--r--l10ntools/source/merge.cxx2
-rw-r--r--linguistic/source/dicimp.cxx3
-rw-r--r--svx/source/dialog/fntctrl.cxx10
7 files changed, 66 insertions, 5 deletions
diff --git a/comphelper/inc/comphelper/string.hxx b/comphelper/inc/comphelper/string.hxx
index c1f56497da4c..878b557db862 100644
--- a/comphelper/inc/comphelper/string.hxx
+++ b/comphelper/inc/comphelper/string.hxx
@@ -260,6 +260,26 @@ COMPHELPER_DLLPUBLIC rtl::OString stripEnd(const rtl::OString &rIn,
COMPHELPER_DLLPUBLIC rtl::OUString stripEnd(const rtl::OUString &rIn,
sal_Unicode c);
+/** Strips occurrences of a character from the start and end of the source string
+
+ @param rIn The input OString
+ @param c The character to be stripped from the start and end
+
+ @return The resulting OString
+ */
+COMPHELPER_DLLPUBLIC rtl::OString strip(const rtl::OString &rIn,
+ sal_Char c);
+
+/** Strips occurrences of a character from the start and end of the source string
+
+ @param rIn The input OUString
+ @param c The character to be stripped from the start and end
+
+ @return The resulting OUString
+ */
+COMPHELPER_DLLPUBLIC rtl::OUString strip(const rtl::OUString &rIn,
+ sal_Unicode c);
+
/** Returns a token in the OString
@param token the number of the token to return
diff --git a/comphelper/qa/string/test_string.cxx b/comphelper/qa/string/test_string.cxx
index 1e89408930bf..5c161a21d4ee 100644
--- a/comphelper/qa/string/test_string.cxx
+++ b/comphelper/qa/string/test_string.cxx
@@ -51,6 +51,7 @@ public:
void testRemove();
void testStripStart();
void testStripEnd();
+ void testStrip();
void testToken();
void testDecimalStringToNumber();
void testIsdigitAsciiString();
@@ -66,6 +67,7 @@ public:
CPPUNIT_TEST(testRemove);
CPPUNIT_TEST(testStripStart);
CPPUNIT_TEST(testStripEnd);
+ CPPUNIT_TEST(testStrip);
CPPUNIT_TEST(testToken);
CPPUNIT_TEST(testDecimalStringToNumber);
CPPUNIT_TEST(testIsdigitAsciiString);
@@ -474,6 +476,26 @@ void TestString::testStripEnd()
CPPUNIT_ASSERT(aOut.equalsL(RTL_CONSTASCII_STRINGPARAM("ab")));
}
+void TestString::testStrip()
+{
+ ::rtl::OString aIn(RTL_CONSTASCII_STRINGPARAM("abc"));
+ ::rtl::OString aOut;
+
+ aOut = ::comphelper::string::strip(aIn, 'b');
+ CPPUNIT_ASSERT(aOut.equalsL(RTL_CONSTASCII_STRINGPARAM("abc")));
+
+ aOut = ::comphelper::string::strip(aIn, 'c');
+ CPPUNIT_ASSERT(aOut.equalsL(RTL_CONSTASCII_STRINGPARAM("ab")));
+
+ aIn = rtl::OString(RTL_CONSTASCII_STRINGPARAM("aaa"));
+ aOut = ::comphelper::string::strip(aIn, 'a');
+ CPPUNIT_ASSERT(aOut.isEmpty());
+
+ aIn = rtl::OString(RTL_CONSTASCII_STRINGPARAM("aba"));
+ aOut = ::comphelper::string::strip(aIn, 'a');
+ CPPUNIT_ASSERT(aOut.equalsL(RTL_CONSTASCII_STRINGPARAM("b")));
+}
+
void TestString::testToken()
{
::rtl::OString aIn(RTL_CONSTASCII_STRINGPARAM("10.11.12"));
diff --git a/comphelper/source/misc/string.cxx b/comphelper/source/misc/string.cxx
index 02d1cd4d104c..2e8d631edf37 100644
--- a/comphelper/source/misc/string.cxx
+++ b/comphelper/source/misc/string.cxx
@@ -231,6 +231,16 @@ rtl::OUString stripEnd(const rtl::OUString &rIn, sal_Unicode c)
return tmpl_stripEnd<rtl::OUString, sal_Unicode>(rIn, c);
}
+rtl::OString strip(const rtl::OString &rIn, sal_Char c)
+{
+ return stripEnd(stripStart(rIn, c), c);
+}
+
+rtl::OUString strip(const rtl::OUString &rIn, sal_Unicode c)
+{
+ return stripEnd(stripStart(rIn, c), c);
+}
+
sal_uInt32 decimalStringToNumber(
::rtl::OUString const & str )
{
diff --git a/l10ntools/source/export2.cxx b/l10ntools/source/export2.cxx
index 72ffde06f777..020e67a5553e 100644
--- a/l10ntools/source/export2.cxx
+++ b/l10ntools/source/export2.cxx
@@ -354,7 +354,7 @@ void Export::InitLanguages( bool bMergeMode ){
ByteStringBoolHashMap aEnvLangs;
for ( sal_uInt16 x = 0; x < sLanguages.GetTokenCount( ',' ); x++ ){
sTmp = getToken(getToken(sLanguages, x, ','), 0, '=');
- sTmp.EraseLeadingAndTrailingChars();
+ sTmp = comphelper::string::strip(sTmp, ' ');
if( bMergeMode && !isAllowed( sTmp ) ){}
else if( !( (sTmp.GetChar(0)=='x' || sTmp.GetChar(0)=='X') && sTmp.GetChar(1)=='-' ) ){
aLanguages.push_back( sTmp );
@@ -371,7 +371,7 @@ void Export::InitForcedLanguages( bool bMergeMode ){
ByteStringBoolHashMap aEnvLangs;
for ( sal_uInt16 x = 0; x < sForcedLanguages.GetTokenCount( ',' ); x++ ){
sTmp = getToken(getToken(sForcedLanguages, x, ','), 0, '=');
- sTmp.EraseLeadingAndTrailingChars();
+ sTmp = comphelper::string::strip(sTmp, ' ');
if( bMergeMode && isAllowed( sTmp ) ){}
else if( !( (sTmp.GetChar(0)=='x' || sTmp.GetChar(0)=='X') && sTmp.GetChar(1)=='-' ) )
aForcedLanguages.push_back( sTmp );
diff --git a/l10ntools/source/merge.cxx b/l10ntools/source/merge.cxx
index a42f058cd160..8c409f49b813 100644
--- a/l10ntools/source/merge.cxx
+++ b/l10ntools/source/merge.cxx
@@ -216,7 +216,7 @@ MergeDataFile::MergeDataFile(
ByteString sPFO = sLine.GetToken( 1, '\t', rIdx ); // 7
sPFO = sHACK;
ByteString nLANG = sLine.GetToken( 1, '\t', rIdx ); // 9
- nLANG.EraseLeadingAndTrailingChars();
+ nLANG = comphelper::string::strip(nLANG, ' ');
const ByteString sTEXT = sLine.GetToken( 0, '\t', rIdx ); // 10
const ByteString sQHTEXT = sLine.GetToken( 1, '\t', rIdx ); // 12
const ByteString sTITLE = sLine.GetToken( 0, '\t', rIdx ); // 13
diff --git a/linguistic/source/dicimp.cxx b/linguistic/source/dicimp.cxx
index 22927eb4d163..8ebb01169c16 100644
--- a/linguistic/source/dicimp.cxx
+++ b/linguistic/source/dicimp.cxx
@@ -41,6 +41,7 @@
#include <tools/string.hxx>
#include <tools/urlobj.hxx>
#include <comphelper/processfactory.hxx>
+#include <comphelper/string.hxx>
#include <unotools/ucbstreamhelper.hxx>
#include <com/sun/star/ucb/XSimpleFileAccess.hpp>
@@ -88,7 +89,7 @@ static sal_Bool getTag(const ByteString &rLine,
if (nPos == STRING_NOTFOUND)
return sal_False;
- rTagValue = rLine.Copy( nPos + sal::static_int_cast< xub_StrLen >(strlen( pTagName )) ).EraseLeadingAndTrailingChars();
+ rTagValue = comphelper::string::strip(rLine.Copy(nPos + sal::static_int_cast< xub_StrLen >(strlen( pTagName ))), ' ');
return sal_True;
}
diff --git a/svx/source/dialog/fntctrl.cxx b/svx/source/dialog/fntctrl.cxx
index 73f60c49c7d8..a40474d72ea9 100644
--- a/svx/source/dialog/fntctrl.cxx
+++ b/svx/source/dialog/fntctrl.cxx
@@ -682,7 +682,15 @@ void SvxFontPrevWindow::Paint( const Rectangle& )
if ( !pImpl->bSelection || pImpl->bUseFontNameAsText )
{
using namespace com::sun::star::i18n::ScriptType;
- pImpl->aText = rFont.GetName();
+
+ //If we're showing multiple sample texts, then they're all
+ //sample texts. If only showing Latin, continue to use
+ //the fontname as the preview
+ if ((pImpl->m_bCJKEnabled) || (pImpl->m_bCTLEnabled))
+ pImpl->aText = makeRepresentativeTextForFont(LATIN, rFont);
+ else
+ pImpl->aText = rFont.GetName();
+
if (pImpl->m_bCJKEnabled)
{
if (pImpl->aText.Len())