From 9ab0b38e95133dab720408cc2c80093b8a201c10 Mon Sep 17 00:00:00 2001 From: Stephan Bergmann Date: Wed, 15 Feb 2012 15:26:43 +0100 Subject: Various string function clean up Added: * rtl::OString::matchL * rtl::OString::endsWith * rtl::OString::endsWithL * rtl::OString::indexOfL * rtl::OString::replaceFirst * rtl::OString::replaceAll * rtl::OString::getToken * rtl::OUString::endsWith * rtl::OUString::replaceFirst * rtl::OUString::replaceFirstAsciiL * rtl::OUString::replaceFirstAsciiLAsciiL * rtl::OUString::replaceAll * rtl::OUString::replaceAllAsciiL * rtl::OUString::replaceAllAsciiLAsciiL * rtl::OUString::getToken plus underlying C functions where necessary Deprecated: * comphelper::string::remove * comphelper::string::getToken Removed: * comphelper::string::searchAndReplaceAsciiL * comphelper::string::searchAndReplaceAllAsciiWithAscii * comphelper::string::searchAndReplaceAsciiI * comphelper::string::replace * comphelper::string::matchL * comphelper::string::matchIgnoreAsciiCaseL * comphelper::string::indexOfL Also fixed some apparent misuses of RTL_CONSTASCII_USTRINGPARAM -> RTL_CONSTASCII_STRINGPARAM. --- basctl/source/basicide/baside3.cxx | 5 +- basctl/source/basicide/basides1.cxx | 5 +- basctl/source/basicide/bastypes.cxx | 7 +- basctl/source/basicide/brkdlg.cxx | 13 +- basctl/source/basicide/moduldl2.cxx | 14 +- basctl/source/dlged/managelang.cxx | 5 +- comphelper/inc/comphelper/string.hxx | 192 ++---------- comphelper/qa/string/test_string.cxx | 106 ------- comphelper/source/misc/string.cxx | 120 ------- dbaccess/source/core/dataaccess/datasource.cxx | 6 +- .../source/core/dataaccess/documentcontainer.cxx | 12 +- .../source/ext/macromigration/migrationengine.cxx | 39 ++- .../source/ext/macromigration/migrationlog.cxx | 107 ++++--- dbaccess/source/ui/app/AppController.cxx | 9 +- dbaccess/source/ui/uno/copytablewizard.cxx | 7 +- .../deployment/gui/dp_gui_extensioncmdqueue.cxx | 26 +- desktop/source/deployment/misc/dp_dependencies.cxx | 5 +- extensions/source/scanner/sanedlg.cxx | 9 +- framework/source/services/autorecovery.cxx | 8 +- l10ntools/inc/export.hxx | 10 +- l10ntools/source/cfgmerge.cxx | 46 +-- l10ntools/source/export.cxx | 215 ++++++------- l10ntools/source/export2.cxx | 7 +- l10ntools/source/gsicheck.cxx | 2 +- l10ntools/source/helper.hxx | 78 ----- l10ntools/source/helpmerge.cxx | 25 +- l10ntools/source/lngmerge.cxx | 26 +- l10ntools/source/localize.cxx | 8 +- l10ntools/source/merge.cxx | 3 +- l10ntools/source/xrmmerge.cxx | 39 ++- linguistic/source/dicimp.cxx | 2 +- oox/source/export/drawingml.cxx | 4 +- padmin/source/adddlg.cxx | 11 +- rsc/source/rsc/rsc.cxx | 9 +- sal/CppunitTest_sal_rtl_strings.mk | 1 + sal/inc/rtl/string.h | 60 ++++ sal/inc/rtl/string.hxx | 152 +++++++++ sal/inc/rtl/ustring.h | 159 ++++++++++ sal/inc/rtl/ustring.hxx | 204 ++++++++++++ sal/qa/rtl/strings/test_strings_replace.cxx | 349 +++++++++++++++++++++ sal/rtl/source/string.cxx | 59 ++++ sal/rtl/source/ustring.cxx | 178 +++++++++++ sal/util/sal.map | 8 + sc/source/ui/app/inputhdl.cxx | 16 +- sot/source/sdstor/ucbstorage.cxx | 4 +- starmath/source/ooxmlimport.cxx | 7 +- svtools/bmpmaker/bmpcore.cxx | 10 +- svtools/bmpmaker/bmpsum.cxx | 10 +- svtools/source/filter/ixbm/xbmread.cxx | 5 +- svtools/source/filter/sgvtext.cxx | 33 +- svtools/source/misc/imap2.cxx | 8 +- svtools/source/svhtml/parhtml.cxx | 3 +- tools/bootstrp/cppdep.cxx | 9 +- tools/source/fsys/dirent.cxx | 4 +- tools/source/inet/inetstrm.cxx | 2 +- vcl/generic/print/common_gfx.cxx | 9 +- vcl/generic/print/genprnpsp.cxx | 11 +- vcl/unx/generic/printer/jobdata.cxx | 30 +- vcl/unx/gtk/app/gtksys.cxx | 5 +- 59 files changed, 1618 insertions(+), 898 deletions(-) create mode 100644 sal/qa/rtl/strings/test_strings_replace.cxx diff --git a/basctl/source/basicide/baside3.cxx b/basctl/source/basicide/baside3.cxx index 7db5434d3b74..67c8b006ce93 100644 --- a/basctl/source/basicide/baside3.cxx +++ b/basctl/source/basicide/baside3.cxx @@ -58,14 +58,12 @@ #include #include #include -#include #include #include #include #include #include -using namespace comphelper; using namespace ::com::sun::star; using namespace ::com::sun::star::uno; using namespace ::com::sun::star::ucb; @@ -1065,7 +1063,8 @@ sal_Bool implImportDialog( Window* pWin, const ::rtl::OUString& rCurPath, const { ::rtl::OUString aQueryBoxTitle(ResId::toString(IDEResId(RID_STR_DLGIMP_CLASH_TITLE))); ::rtl::OUString aQueryBoxText(ResId::toString(IDEResId(RID_STR_DLGIMP_CLASH_TEXT))); - aQueryBoxText = ::comphelper::string::replace(aQueryBoxText, ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("$(ARG1)")), aXmlDlgName); + aQueryBoxText = aQueryBoxText.replaceAllAsciiL( + RTL_CONSTASCII_STRINGPARAM("$(ARG1)"), aXmlDlgName); NameClashQueryBox aQueryBox( pWin, aQueryBoxTitle, aQueryBoxText ); sal_uInt16 nRet = aQueryBox.Execute(); diff --git a/basctl/source/basicide/basides1.cxx b/basctl/source/basicide/basides1.cxx index f404f37c83fe..63cc273de0cb 100644 --- a/basctl/source/basicide/basides1.cxx +++ b/basctl/source/basicide/basides1.cxx @@ -53,7 +53,6 @@ #include #include #include -#include #include #include #include @@ -178,7 +177,9 @@ void BasicIDEShell::ExecuteCurrent( SfxRequest& rReq ) nFound = ((ModulWindow*)pCurWin)->StartSearchAndReplace( (const SvxSearchItem&)rItem ); ::rtl::OUString aReplStr(ResId::toString(IDEResId(RID_STR_SEARCHREPLACES))); - aReplStr = ::comphelper::string::replace(aReplStr, ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("XX")), ::rtl::OUString::valueOf(nFound)); + aReplStr = aReplStr.replaceAllAsciiL( + RTL_CONSTASCII_STRINGPARAM("XX"), + rtl::OUString::valueOf(nFound)); InfoBox( pCurWin, aReplStr ).Execute(); } else diff --git a/basctl/source/basicide/bastypes.cxx b/basctl/source/basicide/bastypes.cxx index f1987d19de87..67244eac269c 100644 --- a/basctl/source/basicide/bastypes.cxx +++ b/basctl/source/basicide/bastypes.cxx @@ -38,7 +38,6 @@ #include #include #include -#include #include #include #include @@ -757,7 +756,8 @@ bool QueryDel( const ::rtl::OUString& rName, const ResId& rId, Window* pParent ) ::rtl::OUStringBuffer aNameBuf( rName ); aNameBuf.append('\''); aNameBuf.insert(sal_Int32(0), sal_Unicode('\'')); - aQuery = ::comphelper::string::replace(aQuery, ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "XX")), aNameBuf.makeStringAndClear()); + aQuery = aQuery.replaceAllAsciiL( + RTL_CONSTASCII_STRINGPARAM("XX"), aNameBuf.makeStringAndClear()); QueryBox aQueryBox( pParent, WB_YES_NO | WB_DEF_YES, aQuery ); return ( aQueryBox.Execute() == RET_YES ); } @@ -802,7 +802,8 @@ bool QueryPassword( const Reference< script::XLibraryContainer >& xLibContainer, if ( bNewTitle ) { ::rtl::OUString aTitle(ResId::toString(IDEResId(RID_STR_ENTERPASSWORD))); - aTitle = ::comphelper::string::replace(aTitle, ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("XX")), rLibName); + aTitle = aTitle.replaceAllAsciiL( + RTL_CONSTASCII_STRINGPARAM("XX"), rLibName); pDlg->SetText( aTitle ); } diff --git a/basctl/source/basicide/brkdlg.cxx b/basctl/source/basicide/brkdlg.cxx index 3365e13897cb..917a95f6c55a 100644 --- a/basctl/source/basicide/brkdlg.cxx +++ b/basctl/source/basicide/brkdlg.cxx @@ -36,28 +36,29 @@ #include "basidesh.hrc" #include "iderdll.hxx" -#include #include #include // FIXME Why does BreakPointDialog allow only sal_uInt16 for break-point line // numbers, whereas BreakPoint supports sal_uLong? -bool lcl_ParseText( const String &rText, size_t& rLineNr ) +bool lcl_ParseText(rtl::OUString const &rText, size_t& rLineNr ) { // aText should look like "# n" where // n > 0 && n < std::numeric_limits< sal_uInt16 >::max(). // All spaces are ignored, so there can even be spaces within the // number n. (Maybe it would be better to ignore all whitespace instead // of just spaces.) - String aText = comphelper::string::remove(rText, ' '); - sal_Unicode cFirst = aText.GetChar(0); + rtl::OUString aText( + rText.replaceAllAsciiL( + RTL_CONSTASCII_STRINGPARAM(" "), rtl::OUString())); + sal_Unicode cFirst = aText[0]; if (cFirst != '#' && !(cFirst >= '0' && cFirst <= '9')) return false; if (cFirst == '#') - aText.Erase(0, 1); + aText = aText.copy(1); // XXX Assumes that sal_uInt16 is contained within sal_Int32: - sal_Int32 n = aText.ToInt32(); + sal_Int32 n = aText.toInt32(); if ( n <= 0 ) return false; rLineNr = static_cast< size_t >(n); diff --git a/basctl/source/basicide/moduldl2.cxx b/basctl/source/basicide/moduldl2.cxx index 60f01a910d96..0f7a1ce0d65d 100644 --- a/basctl/source/basicide/moduldl2.cxx +++ b/basctl/source/basicide/moduldl2.cxx @@ -62,12 +62,10 @@ #include "com/sun/star/packages/manifest/XManifestWriter.hpp" #include #include -#include #include #include -using namespace ::comphelper; using ::rtl::OUString; using namespace ::com::sun::star; using namespace ::com::sun::star::uno; @@ -964,7 +962,9 @@ void LibPage::InsertLib() ( xDlgLibContainer.is() && xDlgLibContainer->hasByName( aLibName ) && xDlgLibContainer->isLibraryReadOnly( aLibName ) && !xDlgLibContainer->isLibraryLink( aLibName ) ) ) { ::rtl::OUString aErrStr( ResId::toString( IDEResId( RID_STR_REPLACELIB ) ) ); - aErrStr = ::comphelper::string::replace(aErrStr, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "XX" ) ), aLibName); + aErrStr = aErrStr.replaceAllAsciiL( + RTL_CONSTASCII_STRINGPARAM("XX"), + aLibName); aErrStr += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\n")); aErrStr += ResId::toString( IDEResId( RID_STR_LIBISREADONLY ) ); ErrorBox( this, WB_OK | WB_DEF_OK, aErrStr ).Execute(); @@ -981,7 +981,9 @@ void LibPage::InsertLib() aErrStr = ResId::toString( IDEResId( RID_STR_REFNOTPOSSIBLE ) ); else aErrStr = ResId::toString( IDEResId( RID_STR_IMPORTNOTPOSSIBLE ) ); - aErrStr = ::comphelper::string::replace(aErrStr, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "XX" ) ), aLibName); + aErrStr = aErrStr.replaceAllAsciiL( + RTL_CONSTASCII_STRINGPARAM("XX"), + aLibName); aErrStr += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\n")); aErrStr += ResId::toString( IDEResId( RID_STR_SBXNAMEALLREADYUSED ) ); ErrorBox( this, WB_OK | WB_DEF_OK, aErrStr ).Execute(); @@ -1002,7 +1004,9 @@ void LibPage::InsertLib() if ( !bOK ) { ::rtl::OUString aErrStr( ResId::toString( IDEResId( RID_STR_NOIMPORT ) ) ); - aErrStr = ::comphelper::string::replace(aErrStr, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "XX" ) ), aLibName); + aErrStr = aErrStr.replaceAllAsciiL( + RTL_CONSTASCII_STRINGPARAM("XX"), + aLibName); ErrorBox( this, WB_OK | WB_DEF_OK, aErrStr ).Execute(); continue; } diff --git a/basctl/source/dlged/managelang.cxx b/basctl/source/dlged/managelang.cxx index 58fd9484d25e..c224f85e0424 100644 --- a/basctl/source/dlged/managelang.cxx +++ b/basctl/source/dlged/managelang.cxx @@ -37,8 +37,9 @@ #include "helpid.hrc" #include "managelang.hrc" +#include #include -#include +#include #include #include #include @@ -120,7 +121,7 @@ void ManageLanguageDialog::Init() ::rtl::OUString sLibName = pIDEShell->GetCurLibName(); // set dialog title with library name ::rtl::OUString sText = GetText(); - ::comphelper::string::replace(sText, ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("$1")), sLibName); + sText = sText.replaceAllAsciiL(RTL_CONSTASCII_STRINGPARAM("$1"), sLibName); SetText( sText ); // set handler m_aAddPB.SetClickHdl( LINK( this, ManageLanguageDialog, AddHdl ) ); diff --git a/comphelper/inc/comphelper/string.hxx b/comphelper/inc/comphelper/string.hxx index 2c63954a3535..f52021d9b68f 100644 --- a/comphelper/inc/comphelper/string.hxx +++ b/comphelper/inc/comphelper/string.hxx @@ -112,113 +112,33 @@ COMPHELPER_DLLPUBLIC inline rtl_String * SAL_CALL rtl_string_alloc(sal_Int32 nLe return detail::string_alloc(nLen); } -/** - Replace the first occurrence of a substring with another string. - - @param source - The source string, in which the search will take place. - - @param from - The ASCII substring to search for. Must point to at least fromLength ASCII - characters. - - @param fromLength - The length of the from substring. Must not be negative. - - @param to - The string to use as replacement. - - @param beginAt - The index at which to begin the search. Must be between zero and the length - of source, inclusive. - - @param replacedAt - If non-null, receives the starting index at which the replacement took place - or -1 if from was not found. - - @return - The resulting string, in which the replacement has taken place. -*/ -COMPHELPER_DLLPUBLIC rtl::OUString searchAndReplaceAsciiL( - rtl::OUString const & source, char const * from, sal_Int32 fromLength, - rtl::OUString const & to, sal_Int32 beginAt = 0, - sal_Int32 * replacedAt = NULL); - -/** replaces, in the given source string, all occurrences of a given ASCII pattern - with another ASCII pattern -*/ -COMPHELPER_DLLPUBLIC ::rtl::OUString searchAndReplaceAllAsciiWithAscii( - const ::rtl::OUString& source, const sal_Char* from, const sal_Char* to, - const sal_Int32 beginAt = 0 ); - -/** does an in-place replacement of the first occurrence of a sub string with - another string - - @param source - the string to search and replace in. - @param asciiPattern - the ASCII sub string to search for. Must point to a 0-terminated string. - @param replace - The string to use as replacement. - @param beginAt - The index at which to begin the search. Must be between zero and the length - of source, inclusive. - - @param replacedAt - If non-null, receives the starting index at which the replacement took place - or -1 if from was not found. - - @return - a reference to source -*/ -COMPHELPER_DLLPUBLIC ::rtl::OUString& - searchAndReplaceAsciiI( ::rtl::OUString & source, sal_Char const * asciiPattern, - ::rtl::OUString const & replace, sal_Int32 beginAt = 0, - sal_Int32 * replacedAt = NULL ); - -/** Replaces each substring of this OString that matches the search OString - with the specified replacement OString - - @param rIn The input OString - @param rSearch The substring to be replaced - @param rReplace The replacement substring - - @return The resulting OString - */ -COMPHELPER_DLLPUBLIC rtl::OString replace(const rtl::OString &rIn, - const rtl::OString &rSearch, const rtl::OString &rReplace); - -/** Replaces each substring of this OUString that matches the search OUString - with the specified replacement OUString - - @param rIn The input OUString - @param rSearch The substring to be replaced - @param rReplace The replacement substring - - @return The resulting OUString - */ -COMPHELPER_DLLPUBLIC rtl::OUString replace(const rtl::OUString &rIn, - const rtl::OUString &rSearch, const rtl::OUString &rReplace); - /** Removes all occurrences of a character from within the source string + @deprecated Use rtl::OString::replaceAll(rtl::OString(c), rtl::OString()) + instead. + @param rIn The input OString @param c The character to be removed @return The resulting OString */ -COMPHELPER_DLLPUBLIC rtl::OString remove(const rtl::OString &rIn, - sal_Char c); +inline rtl::OString remove(const rtl::OString &rIn, + sal_Char c) +{ return rIn.replaceAll(rtl::OString(c), rtl::OString()); } /** Removes all occurrences of a character from within the source string + @deprecated Use + rtl::OUString::replaceAll(rtl::OUString(c), rtl::OUString()) instead. + @param rIn The input OUString @param c The character to be removed @return The resulting OUString */ -COMPHELPER_DLLPUBLIC rtl::OUString remove(const rtl::OUString &rIn, - sal_Unicode c); +inline rtl::OUString remove(const rtl::OUString &rIn, + sal_Unicode c) +{ return rIn.replaceAll(rtl::OUString(c), rtl::OUString()); } /** Strips occurrences of a character from the start of the source string @@ -282,32 +202,34 @@ COMPHELPER_DLLPUBLIC rtl::OUString strip(const rtl::OUString &rIn, /** Returns a token in an OString + @deprecated Use rtl::OString::getToken(nToken, cTok) instead. + @param rIn the input OString @param nToken the number of the token to return @param cTok the character which seperate the tokens. @return the token if token is negative or doesn't exist an empty token is returned */ -COMPHELPER_DLLPUBLIC inline rtl::OString getToken(const rtl::OString &rIn, +inline rtl::OString getToken(const rtl::OString &rIn, sal_Int32 nToken, sal_Char cTok) SAL_THROW(()) { - sal_Int32 nIndex = 0; - return rIn.getToken(nToken, cTok, nIndex); + return rIn.getToken(nToken, cTok); } /** Returns a token in an OUString + @deprecated Use rtl::OUString::getToken(nToken, cTok) instead. + @param rIn the input OUString @param nToken the number of the token to return @param cTok the character which seperate the tokens. @return the token if token is negative or doesn't exist an empty token is returned */ -COMPHELPER_DLLPUBLIC inline rtl::OUString getToken(const rtl::OUString &rIn, +inline rtl::OUString getToken(const rtl::OUString &rIn, sal_Int32 nToken, sal_Unicode cTok) SAL_THROW(()) { - sal_Int32 nIndex = 0; - return rIn.getToken(nToken, cTok, nIndex); + return rIn.getToken(nToken, cTok); } /** Returns number of tokens in an OUString @@ -326,80 +248,6 @@ COMPHELPER_DLLPUBLIC sal_Int32 getTokenCount(const rtl::OString &rIn, sal_Char c */ COMPHELPER_DLLPUBLIC sal_Int32 getTokenCount(const rtl::OUString &rIn, sal_Unicode cTok); -/** - Match against a substring appearing in another string. - - The result is true if and only if the second string appears as a substring - of the first string, at the given position. - This function can't be used for language specific comparison. - - @param rStr The string that pMatch will be compared to. - @param pMatch The substring rStr is to be compared against - @param nMatchLen The length of pMatch - @param fromIndex The index to start the comparion from. - The index must be greater or equal than 0 - and less or equal as the string length. - @return sal_True if pMatch match with the characters in the string - at the given position; - sal_False, otherwise. -*/ -COMPHELPER_DLLPUBLIC inline sal_Bool matchL(const rtl::OString& rStr, const char *pMatch, sal_Int32 nMatchLen, sal_Int32 fromIndex = 0) SAL_THROW(()) -{ - return rtl_str_shortenedCompare_WithLength( rStr.pData->buffer+fromIndex, - rStr.pData->length-fromIndex, pMatch, nMatchLen, nMatchLen ) == 0; -} - -/** - Match against a substring appearing in this string, ignoring the case of - ASCII letters. - - The result is true if and only if the second string appears as a substring - of this string, at the given position. - Character values between 65 and 90 (ASCII A-Z) are interpreted as - values between 97 and 122 (ASCII a-z). - This function can't be used for language specific comparison. - - @param rStr The string that pMatch will be compared to. - @param pMatch The substring rStr is to be compared against - @param nMatchLen The length of pMatch - @param fromIndex the index to start the comparion from. - The index must be greater or equal than 0 - and less or equal as the string length. - @return sal_True if str match with the characters in the string - at the given position; - sal_False, otherwise. -*/ -COMPHELPER_DLLPUBLIC inline sal_Bool matchIgnoreAsciiCaseL(const rtl::OString& rStr, const char *pMatch, sal_Int32 nMatchLen, sal_Int32 fromIndex = 0) SAL_THROW(()) -{ - return rtl_str_shortenedCompareIgnoreAsciiCase_WithLength( rStr.pData->buffer+fromIndex, rStr.pData->length-fromIndex, - pMatch, nMatchLen, - nMatchLen ) == 0; -} - -/** - Returns the index within this string of the first occurrence of the - specified substring, starting at the specified index. - - If str doesn't include any character, always -1 is - returned. This is also the case, if both strings are empty. - - @param rStr The string that pSearch will be searched within. - @param pSearch the substring to search for. - @param nSearchLen the length of pSearch - @param fromIndex the index to start the search from. - @return If the string argument occurs one or more times as a substring - within this string at the starting index, then the index - of the first character of the first such substring is - returned. If it does not occur as a substring starting - at fromIndex or beyond, -1 is returned. -*/ -COMPHELPER_DLLPUBLIC inline sal_Int32 indexOfL(const rtl::OString& rStr, const char *pSearch, sal_Int32 nSearchLen, sal_Int32 fromIndex = 0) SAL_THROW(()) -{ - sal_Int32 ret = rtl_str_indexOfStr_WithLength(rStr.pData->buffer+fromIndex, - rStr.pData->length-fromIndex, pSearch, nSearchLen); - return (ret < 0 ? ret : ret+fromIndex); -} - namespace detail { template B& truncateToLength(B& rBuffer, sal_Int32 nLen) diff --git a/comphelper/qa/string/test_string.cxx b/comphelper/qa/string/test_string.cxx index e53ae9030fa4..b775e01804da 100644 --- a/comphelper/qa/string/test_string.cxx +++ b/comphelper/qa/string/test_string.cxx @@ -44,9 +44,7 @@ namespace { class TestString: public CppUnit::TestFixture { public: - void testSearchAndReplaceAsciiL(); void testNatural(); - void testReplace(); void testRemove(); void testStripStart(); void testStripEnd(); @@ -56,12 +54,9 @@ public: void testDecimalStringToNumber(); void testIsdigitAsciiString(); void testIndexOfL(); - void testMatchIgnoreAsciiCaseL(); CPPUNIT_TEST_SUITE(TestString); - CPPUNIT_TEST(testSearchAndReplaceAsciiL); CPPUNIT_TEST(testNatural); - CPPUNIT_TEST(testReplace); CPPUNIT_TEST(testRemove); CPPUNIT_TEST(testStripStart); CPPUNIT_TEST(testStripEnd); @@ -70,41 +65,9 @@ public: CPPUNIT_TEST(testTokenCount); CPPUNIT_TEST(testDecimalStringToNumber); CPPUNIT_TEST(testIsdigitAsciiString); - CPPUNIT_TEST(testIndexOfL); - CPPUNIT_TEST(testMatchIgnoreAsciiCaseL); CPPUNIT_TEST_SUITE_END(); }; -void TestString::testSearchAndReplaceAsciiL() -{ - rtl::OUString s1(RTL_CONSTASCII_USTRINGPARAM("foobarbar")); - sal_Int32 n1; - rtl::OUString s2( - comphelper::string::searchAndReplaceAsciiL( - s1, RTL_CONSTASCII_STRINGPARAM("bar"), - rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("baaz")), 0, &n1)); - CPPUNIT_ASSERT( - s2 == rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("foobaazbar"))); - CPPUNIT_ASSERT(n1 == 3); - sal_Int32 n2; - rtl::OUString s3( - comphelper::string::searchAndReplaceAsciiL( - s2, RTL_CONSTASCII_STRINGPARAM("bar"), - rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("bz")), - n1 + RTL_CONSTASCII_LENGTH("baaz"), &n2)); - CPPUNIT_ASSERT( - s3 == rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("foobaazbz"))); - CPPUNIT_ASSERT(n2 == 7); - sal_Int32 n3; - rtl::OUString s4( - comphelper::string::searchAndReplaceAsciiL( - s3, RTL_CONSTASCII_STRINGPARAM("bar"), - rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("baz")), - n2 + RTL_CONSTASCII_LENGTH("bz"), &n3)); - CPPUNIT_ASSERT(s4 == s3); - CPPUNIT_ASSERT(n3 == -1); -} - void TestString::testDecimalStringToNumber() { rtl::OUString s1(RTL_CONSTASCII_USTRINGPARAM("1234")); @@ -129,40 +92,6 @@ void TestString::testIsdigitAsciiString() CPPUNIT_ASSERT_EQUAL(comphelper::string::isdigitAsciiString(s3), true); } -void TestString::testIndexOfL() -{ - rtl::OString s1(RTL_CONSTASCII_STRINGPARAM("one two three")); - - CPPUNIT_ASSERT_EQUAL(comphelper::string::indexOfL(s1, - RTL_CONSTASCII_STRINGPARAM("one")), static_cast(0)); - - CPPUNIT_ASSERT_EQUAL(comphelper::string::indexOfL(s1, - RTL_CONSTASCII_STRINGPARAM("two")), static_cast(4)); - - CPPUNIT_ASSERT_EQUAL(comphelper::string::indexOfL(s1, - RTL_CONSTASCII_STRINGPARAM("four")), static_cast(-1)); - - CPPUNIT_ASSERT_EQUAL(comphelper::string::indexOfL(s1, - RTL_CONSTASCII_STRINGPARAM("two"), 5), static_cast(-1)); -} - -void TestString::testMatchIgnoreAsciiCaseL() -{ - rtl::OString s1(RTL_CONSTASCII_STRINGPARAM("one two three")); - - CPPUNIT_ASSERT_EQUAL(comphelper::string::matchIgnoreAsciiCaseL(s1, - RTL_CONSTASCII_STRINGPARAM("one")), sal_True); - - CPPUNIT_ASSERT_EQUAL(comphelper::string::matchIgnoreAsciiCaseL(s1, - RTL_CONSTASCII_STRINGPARAM("ONE")), sal_True); - - CPPUNIT_ASSERT_EQUAL(comphelper::string::matchIgnoreAsciiCaseL(s1, - RTL_CONSTASCII_STRINGPARAM("two")), sal_False); - - CPPUNIT_ASSERT_EQUAL(comphelper::string::matchIgnoreAsciiCaseL(s1, - RTL_CONSTASCII_STRINGPARAM("two"), 4), sal_True); -} - using namespace ::com::sun::star; class testCollator : public cppu::WeakImplHelper1< i18n::XCollator > @@ -357,41 +286,6 @@ void TestString::testNatural() ); } -void TestString::testReplace() -{ - ::rtl::OString aIn(RTL_CONSTASCII_STRINGPARAM("aaa")); - ::rtl::OString aOut; - - aOut = ::comphelper::string::replace(aIn, - rtl::OString(RTL_CONSTASCII_STRINGPARAM("aa")), - rtl::OString(RTL_CONSTASCII_STRINGPARAM("b"))); - CPPUNIT_ASSERT(aOut.equalsL(RTL_CONSTASCII_STRINGPARAM("ba"))); - - aOut = ::comphelper::string::replace(aIn, - rtl::OString(), - rtl::OString(RTL_CONSTASCII_STRINGPARAM("whatever"))); - CPPUNIT_ASSERT(aOut.equalsL(RTL_CONSTASCII_STRINGPARAM("aaa"))); - - aOut = ::comphelper::string::replace(aIn, - rtl::OString(RTL_CONSTASCII_STRINGPARAM("aaa")), - rtl::OString()); - CPPUNIT_ASSERT(aOut.isEmpty()); - - aIn = rtl::OString(RTL_CONSTASCII_STRINGPARAM("aaa foo aaa foo bbb")); - - aOut = ::comphelper::string::replace(aIn, - rtl::OString(RTL_CONSTASCII_STRINGPARAM("foo")), - rtl::OString(RTL_CONSTASCII_STRINGPARAM("bar"))); - CPPUNIT_ASSERT(aOut.equalsL( - RTL_CONSTASCII_STRINGPARAM("aaa bar aaa bar bbb"))); - - aOut = ::comphelper::string::replace(aIn, - rtl::OString(' '), - rtl::OString()); - CPPUNIT_ASSERT(aOut.equalsL( - RTL_CONSTASCII_STRINGPARAM("aaafooaaafoobbb"))); -} - void TestString::testRemove() { ::rtl::OString aIn(RTL_CONSTASCII_STRINGPARAM("abc")); diff --git a/comphelper/source/misc/string.cxx b/comphelper/source/misc/string.cxx index 8514a83872c6..3547de626318 100644 --- a/comphelper/source/misc/string.cxx +++ b/comphelper/source/misc/string.cxx @@ -48,126 +48,6 @@ namespace comphelper { namespace string { -rtl::OUString searchAndReplaceAsciiL( - rtl::OUString const & source, char const * from, sal_Int32 fromLength, - rtl::OUString const & to, sal_Int32 beginAt, sal_Int32 * replacedAt) -{ - sal_Int32 n = source.indexOfAsciiL(from, fromLength, beginAt); - if (replacedAt != NULL) { - *replacedAt = n; - } - return n == -1 ? source : source.replaceAt(n, fromLength, to); -} - -::rtl::OUString searchAndReplaceAllAsciiWithAscii( - const ::rtl::OUString& _source, const sal_Char* _from, const sal_Char* _to, - const sal_Int32 _beginAt ) -{ - sal_Int32 fromLength = strlen( _from ); - sal_Int32 n = _source.indexOfAsciiL( _from, fromLength, _beginAt ); - if ( n == -1 ) - return _source; - - ::rtl::OUString dest( _source ); - ::rtl::OUString to( ::rtl::OUString::createFromAscii( _to ) ); - do - { - dest = dest.replaceAt( n, fromLength, to ); - n = dest.indexOfAsciiL( _from, fromLength, n + to.getLength() ); - } - while ( n != -1 ); - - return dest; -} - -::rtl::OUString& searchAndReplaceAsciiI( - ::rtl::OUString & _source, sal_Char const * _asciiPattern, ::rtl::OUString const & _replace, - sal_Int32 _beginAt, sal_Int32 * _replacedAt ) -{ - sal_Int32 fromLength = strlen( _asciiPattern ); - sal_Int32 n = _source.indexOfAsciiL( _asciiPattern, fromLength, _beginAt ); - if ( _replacedAt != NULL ) - *_replacedAt = n; - - if ( n != -1 ) - _source = _source.replaceAt( n, fromLength, _replace ); - - return _source; -} - -namespace -{ - template T tmpl_replace(const T &rIn, - const T &rSearch, const T &rReplace) - { - if (rIn.isEmpty() || rSearch.isEmpty()) - return rIn; - - O aRet; - - sal_Int32 nFromIndex = 0; - while (nFromIndex < rIn.getLength()) - { - sal_Int32 nIndex = rIn.indexOf(rSearch, nFromIndex); - if (nIndex == -1) - { - aRet.append(rIn.copy(nFromIndex)); - break; - } - aRet.append(rIn.copy(nFromIndex, nIndex-nFromIndex)); - aRet.append(rReplace); - nFromIndex = nIndex+rSearch.getLength(); - } - - return aRet.makeStringAndClear(); - } -} - -rtl::OString replace(const rtl::OString &rIn, const rtl::OString &rSearch, - const rtl::OString &rReplace) -{ - return tmpl_replace(rIn, rSearch, - rReplace); -} - -rtl::OUString replace(const rtl::OUString &rIn, const rtl::OUString &rSearch, - const rtl::OUString &rReplace) -{ - return tmpl_replace(rIn, rSearch, - rReplace); -} - -namespace -{ - template T tmpl_remove(const T &rIn, - const C cRemove) - { - if (rIn.isEmpty()) - return rIn; - - O aRet; - - for (sal_Int32 i = 0; i < rIn.getLength(); ++i) - { - C cChar = rIn[i]; - if (cChar != cRemove) - aRet.append(cChar); - } - - return aRet.makeStringAndClear(); - } -} - -rtl::OString remove(const rtl::OString &rIn, sal_Char c) -{ - return tmpl_remove(rIn, c); -} - -rtl::OUString remove(const rtl::OUString &rIn, sal_Unicode c) -{ - return tmpl_remove(rIn, c); -} - namespace { template T tmpl_stripStart(const T &rIn, diff --git a/dbaccess/source/core/dataaccess/datasource.cxx b/dbaccess/source/core/dataaccess/datasource.cxx index 8a077a581aeb..ae8971729bb2 100644 --- a/dbaccess/source/core/dataaccess/datasource.cxx +++ b/dbaccess/source/core/dataaccess/datasource.cxx @@ -66,7 +66,6 @@ #include #include #include -#include #include #include #include @@ -747,8 +746,9 @@ Reference< XConnection > ODatabaseSource::buildLowLevelConnection(const ::rtl::O ::rtl::OUString sMessage = DBACORE_RESSTRING( nExceptionMessageId ); SQLContext aContext; - aContext.Message = DBACORE_RESSTRING( RID_STR_CONNECTION_REQUEST ); - ::comphelper::string::searchAndReplaceAsciiI( aContext.Message, "$name$", m_pImpl->m_sConnectURL ); + aContext.Message = DBACORE_RESSTRING(RID_STR_CONNECTION_REQUEST). + replaceFirstAsciiL( + RTL_CONSTASCII_STRINGPARAM("$name$"), m_pImpl->m_sConnectURL); throwGenericSQLException( sMessage, static_cast< XDataSource* >( this ), makeAny( aContext ) ); } diff --git a/dbaccess/source/core/dataaccess/documentcontainer.cxx b/dbaccess/source/core/dataaccess/documentcontainer.cxx index e5c485e6d4e9..082a6f315f96 100644 --- a/dbaccess/source/core/dataaccess/documentcontainer.cxx +++ b/dbaccess/source/core/dataaccess/documentcontainer.cxx @@ -43,7 +43,6 @@ #include "datasource.hxx" #include #include -#include #include #include "core_resource.hxx" #include "core_resource.hrc" @@ -542,8 +541,9 @@ Reference< XComponent > SAL_CALL ODocumentContainer::loadComponentFromURL( const ::rtl::OUString sName; if ( !lcl_queryContent(_sURL,xNameContainer,aContent,sName) ) { - ::rtl::OUString sMessage( DBA_RES( RID_STR_NAME_NOT_FOUND ) ); - ::comphelper::string::searchAndReplaceAsciiI( sMessage, "$name$", _sURL ); + ::rtl::OUString sMessage( + DBA_RES(RID_STR_NAME_NOT_FOUND).replaceFirstAsciiL( + RTL_CONSTASCII_STRINGPARAM("$name$"), _sURL)); throw IllegalArgumentException( sMessage, *this, 1 ); } @@ -611,9 +611,11 @@ void SAL_CALL ODocumentContainer::insertByHierarchicalName( const ::rtl::OUStrin if ( !xNameContainer.is() ) { - ::rtl::OUString sMessage( DBA_RES( RID_STR_NO_SUB_FOLDER ) ); sal_Int32 index = sName.getLength(); - ::comphelper::string::searchAndReplaceAsciiI( sMessage, "$folder$", _sName.getToken(0,'/',index) ); + ::rtl::OUString sMessage( + DBA_RES(RID_STR_NO_SUB_FOLDER).replaceFirstAsciiL( + RTL_CONSTASCII_STRINGPARAM("$folder$"), + _sName.getToken(0,'/',index))); throw IllegalArgumentException( sMessage, *this, 1 ); } diff --git a/dbaccess/source/ext/macromigration/migrationengine.cxx b/dbaccess/source/ext/macromigration/migrationengine.cxx index 65155866bd92..5bdde99a1407 100644 --- a/dbaccess/source/ext/macromigration/migrationengine.cxx +++ b/dbaccess/source/ext/macromigration/migrationengine.cxx @@ -72,7 +72,6 @@ #include #include #include -#include #include #include #include @@ -254,8 +253,13 @@ namespace dbmm //---------------------------------------------------------------- ::rtl::OUString lcl_getSubDocumentDescription( const SubDocument& _rDocument ) { - ::rtl::OUString sObjectName = ResId::toString(MacroMigrationResId( _rDocument.eType == eForm ? STR_FORM : STR_REPORT)); - ::comphelper::string::searchAndReplaceAsciiI( sObjectName, "$name$", _rDocument.sHierarchicalName ); + ::rtl::OUString sObjectName( + ResId::toString( + MacroMigrationResId( + _rDocument.eType == eForm ? STR_FORM : STR_REPORT)). + replaceFirstAsciiL( + RTL_CONSTASCII_STRINGPARAM("$name$"), + _rDocument.sHierarchicalName)); return sObjectName; } @@ -1025,8 +1029,11 @@ namespace dbmm // initialize global progress sal_Int32 nOverallRange( m_aSubDocs.size() ); - String sProgressSkeleton = ResId::toString(MacroMigrationResId( STR_OVERALL_PROGRESS)); - sProgressSkeleton.SearchAndReplaceAscii( "$overall$", String::CreateFromInt32( nOverallRange ) ); + rtl::OUString sProgressSkeleton( + ResId::toString(MacroMigrationResId( STR_OVERALL_PROGRESS)). + replaceFirstAsciiL( + RTL_CONSTASCII_STRINGPARAM("$overall$"), + rtl::OUString::valueOf(nOverallRange))); m_rProgress.start( nOverallRange ); @@ -1037,8 +1044,10 @@ namespace dbmm { sal_Int32 nOverallProgressValue( doc - m_aSubDocs.begin() + 1 ); // update overall progress text - ::rtl::OUString sOverallProgress( sProgressSkeleton ); - ::comphelper::string::searchAndReplaceAsciiI( sOverallProgress, "$current$", ::rtl::OUString::valueOf( nOverallProgressValue ) ); + ::rtl::OUString sOverallProgress( + sProgressSkeleton.replaceFirstAsciiL( + RTL_CONSTASCII_STRINGPARAM("$current$"), + ::rtl::OUString::valueOf(nOverallProgressValue))); m_rProgress.setOverallProgressText( sOverallProgress ); // migrate document @@ -1927,12 +1936,16 @@ namespace dbmm const ScriptType _eScriptType, const ::rtl::OUString& _rLibraryName ) const { // a human-readable description of the affected library - ::rtl::OUString sLibraryDescription( ResId::toString( - MacroMigrationResId( STR_LIBRARY_TYPE_AND_NAME ) ) ); - ::comphelper::string::searchAndReplaceAsciiI( sLibraryDescription, "$type$", - getScriptTypeDisplayName( _eScriptType ) ); - ::comphelper::string::searchAndReplaceAsciiI( sLibraryDescription, "$library$", - _rLibraryName ); + ::rtl::OUString sLibraryDescription( + ResId::toString(MacroMigrationResId(STR_LIBRARY_TYPE_AND_NAME)). + replaceFirstAsciiL( + RTL_CONSTASCII_STRINGPARAM("$type$"), + getScriptTypeDisplayName(_eScriptType)). + replaceFirstAsciiL( + RTL_CONSTASCII_STRINGPARAM("$library$"), _rLibraryName)); + //TODO: probably broken if first replaceFirstAsciiL can produce + // fresh instance of "$library$" in subject string of second + // replaceFirstAsciiL InteractionHandler aHandler( m_aContext, m_xDocumentModel ); ::rtl::OUString sPassword; diff --git a/dbaccess/source/ext/macromigration/migrationlog.cxx b/dbaccess/source/ext/macromigration/migrationlog.cxx index 38ded5ae0d80..06391ce600f9 100644 --- a/dbaccess/source/ext/macromigration/migrationlog.cxx +++ b/dbaccess/source/ext/macromigration/migrationlog.cxx @@ -36,7 +36,6 @@ /** === end UNO includes === **/ #include -#include #include #include @@ -240,22 +239,25 @@ namespace dbmm static void lcl_appendErrorDescription( ::rtl::OUStringBuffer& _inout_rBuffer, const MigrationError& _rError ) { const sal_Char* pAsciiErrorDescription( NULL ); - ::std::vector< const sal_Char* > aAsciiParameterNames; + ::std::vector< rtl::OUString > aParameterNames; switch ( _rError.eType ) { case ERR_OPENING_SUB_DOCUMENT_FAILED: pAsciiErrorDescription = "opening '#doc#' failed"; - aAsciiParameterNames.push_back( "#doc#" ); + aParameterNames.push_back( + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("#doc#"))); break; case ERR_CLOSING_SUB_DOCUMENT_FAILED: pAsciiErrorDescription = "closing '#doc#' failed"; - aAsciiParameterNames.push_back( "#doc#" ); + aParameterNames.push_back( + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("#doc#"))); break; case ERR_STORAGE_COMMIT_FAILED: pAsciiErrorDescription = "committing the changes for document '#doc#' failed"; - aAsciiParameterNames.push_back( "#doc#" ); + aParameterNames.push_back( + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("#doc#"))); break; case ERR_STORING_DATABASEDOC_FAILED: @@ -268,52 +270,66 @@ namespace dbmm case ERR_UNEXPECTED_LIBSTORAGE_ELEMENT: pAsciiErrorDescription = "unexpected #lib# storage element in document '#doc#', named '#element#'"; - aAsciiParameterNames.push_back( "#doc#" ); - aAsciiParameterNames.push_back( "#libstore#" ); - aAsciiParameterNames.push_back( "#element#" ); + aParameterNames.push_back( + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("#doc#"))); + aParameterNames.push_back( + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("#libstore#"))); + aParameterNames.push_back( + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("#element#"))); break; case ERR_CREATING_DBDOC_SCRIPT_STORAGE_FAILED: pAsciiErrorDescription = "creating the database document's storage for #scripttype# scripts failed"; - aAsciiParameterNames.push_back( "#scripttype#" ); + aParameterNames.push_back( + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("#scripttype#"))); break; case ERR_COMMITTING_SCRIPT_STORAGES_FAILED: pAsciiErrorDescription = "saving the #scripttype# scripts for document '#doc#' failed"; - aAsciiParameterNames.push_back( "#scripttype#" ); - aAsciiParameterNames.push_back( "#doc#" ); + aParameterNames.push_back( + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("#scripttype#"))); + aParameterNames.push_back( + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("#doc#"))); break; case ERR_GENERAL_SCRIPT_MIGRATION_FAILURE: pAsciiErrorDescription = "general error while migrating #scripttype# scripts of document '#doc#'"; - aAsciiParameterNames.push_back( "#scripttype#" ); - aAsciiParameterNames.push_back( "#doc#" ); + aParameterNames.push_back( + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("#scripttype#"))); + aParameterNames.push_back( + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("#doc#"))); break; case ERR_GENERAL_MACRO_MIGRATION_FAILURE: pAsciiErrorDescription = "general error during macro migration of document '#doc#'"; - aAsciiParameterNames.push_back( "#doc#" ); + aParameterNames.push_back( + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("#doc#"))); break; case ERR_UNKNOWN_SCRIPT_TYPE: pAsciiErrorDescription = "unknown script type: #type#"; - aAsciiParameterNames.push_back( "#type#" ); + aParameterNames.push_back( + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("#type#"))); break; case ERR_UNKNOWN_SCRIPT_LANGUAGE: pAsciiErrorDescription = "unknown script language: #lang#"; - aAsciiParameterNames.push_back( "#lang#" ); + aParameterNames.push_back( + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("#lang#"))); break; case ERR_UNKNOWN_SCRIPT_NAME_FORMAT: pAsciiErrorDescription = "unknown script name format: #script#"; - aAsciiParameterNames.push_back( "#script#" ); + aParameterNames.push_back( + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("#script#"))); break; case ERR_SCRIPT_TRANSLATION_FAILURE: pAsciiErrorDescription = "analyzing/translating the script URL failed; script type: #type#; script: #code#"; - aAsciiParameterNames.push_back( "#type#" ); - aAsciiParameterNames.push_back( "#code#" ); + aParameterNames.push_back( + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("#type#"))); + aParameterNames.push_back( + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("#code#"))); break; case ERR_INVALID_SCRIPT_DESCRIPTOR_FORMAT: @@ -322,57 +338,72 @@ namespace dbmm case ERR_ADJUSTING_DOCUMENT_EVENTS_FAILED: pAsciiErrorDescription = "adjusting events for document '#doc#' failed"; - aAsciiParameterNames.push_back( "#doc#" ); + aParameterNames.push_back( + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("#doc#"))); break; case ERR_ADJUSTING_DIALOG_EVENTS_FAILED: pAsciiErrorDescription = "adjusting events for dialog #lib#.#dlg# in document '#doc#' failed"; - aAsciiParameterNames.push_back( "#doc#" ); - aAsciiParameterNames.push_back( "#lib#" ); - aAsciiParameterNames.push_back( "#dlg#" ); + aParameterNames.push_back( + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("#doc#"))); + aParameterNames.push_back( + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("#lib#"))); + aParameterNames.push_back( + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("#dlg#"))); break; case ERR_ADJUSTING_FORMCOMP_EVENTS_FAILED: pAsciiErrorDescription = "adjusting form component events for '#doc#' failed"; - aAsciiParameterNames.push_back( "#doc#" ); + aParameterNames.push_back( + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("#doc#"))); break; case ERR_BIND_SCRIPT_STORAGE_FAILED: pAsciiErrorDescription = "binding to the script storage failed for document '#doc#'"; - aAsciiParameterNames.push_back( "#doc#" ); + aParameterNames.push_back( + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("#doc#"))); break; case ERR_REMOVE_SCRIPTS_STORAGE_FAILED: pAsciiErrorDescription = "removing a scripts storage failed for document '#doc#'"; - aAsciiParameterNames.push_back( "#doc#" ); + aParameterNames.push_back( + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("#doc#"))); break; case ERR_DOCUMENT_BACKUP_FAILED: pAsciiErrorDescription = "backing up the document to #location# failed"; - aAsciiParameterNames.push_back( "#location#" ); + aParameterNames.push_back( + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("#location#"))); break; case ERR_UNKNOWN_SCRIPT_FOLDER: pAsciiErrorDescription = "unknown script folder '#name#' in document '#doc#'"; - aAsciiParameterNames.push_back( "#doc#" ); - aAsciiParameterNames.push_back( "#name#" ); + aParameterNames.push_back( + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("#doc#"))); + aParameterNames.push_back( + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("#name#"))); break; case ERR_EXAMINING_SCRIPTS_FOLDER_FAILED: pAsciiErrorDescription = "examining the 'Scripts' folder failed for document '#doc#'"; - aAsciiParameterNames.push_back( "#doc#" ); + aParameterNames.push_back( + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("#doc#"))); break; case ERR_PASSWORD_VERIFICATION_FAILED: pAsciiErrorDescription = "password verification failed for document '#doc#', #libtype# library '#name#'"; - aAsciiParameterNames.push_back( "#doc#" ); - aAsciiParameterNames.push_back( "#libtype#" ); - aAsciiParameterNames.push_back( "#name#" ); + aParameterNames.push_back( + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("#doc#"))); + aParameterNames.push_back( + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("#libtype#"))); + aParameterNames.push_back( + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("#name#"))); break; case ERR_NEW_STYLE_REPORT: pAsciiErrorDescription = "#doc# could not be processed, since you don't have the Oracle Report Builder (TM) extension installed."; - aAsciiParameterNames.push_back( "#doc#" ); + aParameterNames.push_back( + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("#doc#"))); break; // do *not* add a default case here: Without a default, some compilers will warn you when @@ -382,13 +413,13 @@ namespace dbmm if ( pAsciiErrorDescription ) { ::rtl::OUString sSubstituted( ::rtl::OUString::createFromAscii( pAsciiErrorDescription ) ); - OSL_ENSURE( aAsciiParameterNames.size() == _rError.aErrorDetails.size(), + OSL_ENSURE( aParameterNames.size() == _rError.aErrorDetails.size(), "lcl_appendErrorDescription: unexpected number of error message parameters!" ); - for ( size_t i=0; i < ::std::min( aAsciiParameterNames.size(), _rError.aErrorDetails.size() ); ++i ) + for ( size_t i=0; i < ::std::min( aParameterNames.size(), _rError.aErrorDetails.size() ); ++i ) { - ::comphelper::string::searchAndReplaceAsciiI( sSubstituted, aAsciiParameterNames[i], - _rError.aErrorDetails[i] ); + sSubstituted = sSubstituted.replaceFirst( + aParameterNames[i], _rError.aErrorDetails[i]); } _inout_rBuffer.append( sSubstituted ); diff --git a/dbaccess/source/ui/app/AppController.cxx b/dbaccess/source/ui/app/AppController.cxx index 3fd0762bcf87..b3f34f325871 100644 --- a/dbaccess/source/ui/app/AppController.cxx +++ b/dbaccess/source/ui/app/AppController.cxx @@ -90,7 +90,6 @@ #include #include -#include #include #include #include @@ -2964,8 +2963,12 @@ void SAL_CALL OApplicationController::removeSelectionChangeListener( const Refer default: case DatabaseObjectContainer::DATA_SOURCE: { - ::rtl::OUString sMessage = String(ModuleRes( RID_STR_UNSUPPORTED_OBJECT_TYPE )); - ::comphelper::string::searchAndReplaceAsciiI( sMessage, "$type$", ::rtl::OUString::valueOf(sal_Int32( pObject->Type )) ); + ::rtl::OUString sMessage( + rtl::OUString( + String(ModuleRes(RID_STR_UNSUPPORTED_OBJECT_TYPE))). + replaceFirstAsciiL( + RTL_CONSTASCII_STRINGPARAM("$type$"), + ::rtl::OUString::valueOf(sal_Int32(pObject->Type)))); throw IllegalArgumentException(sMessage, *this, sal_Int16( pObject - aSelectedObjects.getConstArray() )); } } diff --git a/dbaccess/source/ui/uno/copytablewizard.cxx b/dbaccess/source/ui/uno/copytablewizard.cxx index 129721b4c19a..cfcadfcf2e26 100644 --- a/dbaccess/source/ui/uno/copytablewizard.cxx +++ b/dbaccess/source/ui/uno/copytablewizard.cxx @@ -68,7 +68,6 @@ #include #include #include -#include #include #include #include @@ -762,8 +761,10 @@ void CopyTableWizard::impl_checkForUnsupportedSettings_throw( const Reference< X if ( !sUnsupportedSetting.isEmpty() ) { - ::rtl::OUString sMessage( String(ModuleRes( STR_CTW_ERROR_UNSUPPORTED_SETTING )) ); - ::comphelper::string::searchAndReplaceAsciiI( sMessage, "$name$", sUnsupportedSetting ); + ::rtl::OUString sMessage( + rtl::OUString(String(ModuleRes(STR_CTW_ERROR_UNSUPPORTED_SETTING))). + replaceFirstAsciiL( + RTL_CONSTASCII_STRINGPARAM("$name$"), sUnsupportedSetting)); throw IllegalArgumentException( sMessage, *const_cast< CopyTableWizard* >( this ), diff --git a/desktop/source/deployment/gui/dp_gui_extensioncmdqueue.cxx b/desktop/source/deployment/gui/dp_gui_extensioncmdqueue.cxx index 53a179403e3d..62347ce12804 100644 --- a/desktop/source/deployment/gui/dp_gui_extensioncmdqueue.cxx +++ b/desktop/source/deployment/gui/dp_gui_extensioncmdqueue.cxx @@ -75,10 +75,8 @@ #include "cppuhelper/exc_hlp.hxx" #include "cppuhelper/implbase3.hxx" #include "comphelper/anytostring.hxx" -#include "comphelper/string.hxx" #include "vcl/msgbox.hxx" #include "toolkit/helper/vclunohelper.hxx" -#include "comphelper/processfactory.hxx" #include "dp_gui.h" #include "dp_gui_thread.hxx" @@ -899,7 +897,9 @@ void ExtensionCmdQueue::Thread::_addExtension( ::rtl::Reference< ProgressCmdEnv rCmdEnv->setWarnUser( bWarnUser ); uno::Reference< deployment::XExtensionManager > xExtMgr = m_pManager->getExtensionManager(); uno::Reference< task::XAbortChannel > xAbortChannel( xExtMgr->createAbortChannel() ); - OUString sTitle = comphelper::string::replace(m_sAddingPackages, OUSTR("%EXTENSION_NAME"), sName); + OUString sTitle( + m_sAddingPackages.replaceAllAsciiL( + RTL_CONSTASCII_STRINGPARAM("%EXTENSION_NAME"), sName)); rCmdEnv->progressSection( sTitle, xAbortChannel ); try @@ -926,7 +926,10 @@ void ExtensionCmdQueue::Thread::_removeExtension( ::rtl::Reference< ProgressCmdE { uno::Reference< deployment::XExtensionManager > xExtMgr = m_pManager->getExtensionManager(); uno::Reference< task::XAbortChannel > xAbortChannel( xExtMgr->createAbortChannel() ); - OUString sTitle = comphelper::string::replace(m_sRemovingPackages, OUSTR("%EXTENSION_NAME"), xPackage->getDisplayName()); + OUString sTitle( + m_sRemovingPackages.replaceAllAsciiL( + RTL_CONSTASCII_STRINGPARAM("%EXTENSION_NAME"), + xPackage->getDisplayName())); rCmdEnv->progressSection( sTitle, xAbortChannel ); OUString id( dp_misc::getIdentifier( xPackage ) ); @@ -1009,7 +1012,10 @@ void ExtensionCmdQueue::Thread::_enableExtension( ::rtl::Reference< ProgressCmdE uno::Reference< deployment::XExtensionManager > xExtMgr = m_pManager->getExtensionManager(); uno::Reference< task::XAbortChannel > xAbortChannel( xExtMgr->createAbortChannel() ); - OUString sTitle = comphelper::string::replace(m_sEnablingPackages, OUSTR("%EXTENSION_NAME"), xPackage->getDisplayName()); + OUString sTitle( + m_sEnablingPackages.replaceAllAsciiL( + RTL_CONSTASCII_STRINGPARAM("%EXTENSION_NAME"), + xPackage->getDisplayName())); rCmdEnv->progressSection( sTitle, xAbortChannel ); try @@ -1031,7 +1037,10 @@ void ExtensionCmdQueue::Thread::_disableExtension( ::rtl::Reference< ProgressCmd uno::Reference< deployment::XExtensionManager > xExtMgr = m_pManager->getExtensionManager(); uno::Reference< task::XAbortChannel > xAbortChannel( xExtMgr->createAbortChannel() ); - OUString sTitle = comphelper::string::replace(m_sDisablingPackages, OUSTR("%EXTENSION_NAME"), xPackage->getDisplayName()); + OUString sTitle( + m_sDisablingPackages.replaceAllAsciiL( + RTL_CONSTASCII_STRINGPARAM("%EXTENSION_NAME"), + xPackage->getDisplayName())); rCmdEnv->progressSection( sTitle, xAbortChannel ); try @@ -1053,7 +1062,10 @@ void ExtensionCmdQueue::Thread::_acceptLicense( ::rtl::Reference< ProgressCmdEnv uno::Reference< deployment::XExtensionManager > xExtMgr = m_pManager->getExtensionManager(); uno::Reference< task::XAbortChannel > xAbortChannel( xExtMgr->createAbortChannel() ); - OUString sTitle = comphelper::string::replace(m_sAcceptLicense, OUSTR("%EXTENSION_NAME"), xPackage->getDisplayName()); + OUString sTitle( + m_sAcceptLicense.replaceAllAsciiL( + RTL_CONSTASCII_STRINGPARAM("%EXTENSION_NAME"), + xPackage->getDisplayName())); rCmdEnv->progressSection( sTitle, xAbortChannel ); try diff --git a/desktop/source/deployment/misc/dp_dependencies.cxx b/desktop/source/deployment/misc/dp_dependencies.cxx index 7581af831a83..e24873f7c017 100644 --- a/desktop/source/deployment/misc/dp_dependencies.cxx +++ b/desktop/source/deployment/misc/dp_dependencies.cxx @@ -32,7 +32,6 @@ #include "com/sun/star/uno/Sequence.hxx" #include "com/sun/star/xml/dom/XElement.hpp" #include "com/sun/star/xml/dom/XNodeList.hpp" -#include "comphelper/string.hxx" #include "rtl/bootstrap.hxx" #include "rtl/string.h" #include "rtl/ustring.h" @@ -94,8 +93,8 @@ bool satisfiesMaximalVersion( rtl::OUString produceErrorText( rtl::OUString const & reason, rtl::OUString const & version) { - return comphelper::string::searchAndReplaceAsciiL( - reason, RTL_CONSTASCII_STRINGPARAM("%VERSION"), + return reason.replaceFirstAsciiL( + RTL_CONSTASCII_STRINGPARAM("%VERSION"), (version.isEmpty() ? ResId::toString( dp_misc::getResId(RID_DEPLOYMENT_DEPENDENCIES_UNKNOWN)) diff --git a/extensions/source/scanner/sanedlg.cxx b/extensions/source/scanner/sanedlg.cxx index d08a1759162f..e12e6400b736 100644 --- a/extensions/source/scanner/sanedlg.cxx +++ b/extensions/source/scanner/sanedlg.cxx @@ -38,7 +38,6 @@ #include #include #include -#include ResId SaneResId( sal_uInt32 nID ) { @@ -1212,20 +1211,18 @@ sal_Bool SaneDlg::LoadState() if( nOption == -1 ) continue; - using comphelper::string::matchL; - - if (matchL(aValue, RTL_CONSTASCII_USTRINGPARAM("BOOL="))) + if (aValue.matchL(RTL_CONSTASCII_STRINGPARAM("BOOL="))) { aValue = aValue.copy(RTL_CONSTASCII_LENGTH("BOOL=")); sal_Bool aBOOL = (sal_Bool)aValue.toInt32(); mrSane.SetOptionValue( nOption, aBOOL ); } - else if (matchL(aValue, RTL_CONSTASCII_USTRINGPARAM("STRING="))) + else if (aValue.matchL(RTL_CONSTASCII_STRINGPARAM("STRING="))) { aValue = aValue.copy(RTL_CONSTASCII_LENGTH("STRING=")); mrSane.SetOptionValue(nOption,rtl::OStringToOUString(aValue, osl_getThreadTextEncoding()) ); } - else if (matchL(aValue, RTL_CONSTASCII_USTRINGPARAM("NUMERIC="))) + else if (aValue.matchL(RTL_CONSTASCII_STRINGPARAM("NUMERIC="))) { aValue = aValue.copy(RTL_CONSTASCII_LENGTH("NUMERIC=")); diff --git a/framework/source/services/autorecovery.cxx b/framework/source/services/autorecovery.cxx index cae935b86215..6bbfc29dedc6 100644 --- a/framework/source/services/autorecovery.cxx +++ b/framework/source/services/autorecovery.cxx @@ -81,7 +81,6 @@ #include #include #include -#include #include #include #include @@ -3483,8 +3482,6 @@ sal_Bool AutoRecovery::impl_enoughDiscSpace(sal_Int32 nRequiredSpace) //----------------------------------------------- void AutoRecovery::impl_showFullDiscError() { - rtl::OUString PLACEHOLDER_PATH(RTL_CONSTASCII_USTRINGPARAM("%PATH")); - rtl::OUString sBtn(ResId::toString(FwkResId(STR_FULL_DISC_RETRY_BUTTON))); rtl::OUString sMsg(ResId::toString(FwkResId(STR_FULL_DISC_MSG))); @@ -3495,7 +3492,10 @@ void AutoRecovery::impl_showFullDiscError() if (sBackupPath.getLength() < 1) sBackupPath = sBackupURL; - ErrorBox dlgError(0, WB_OK, comphelper::string::replace(sMsg, PLACEHOLDER_PATH, sBackupPath)); + ErrorBox dlgError( + 0, WB_OK, + sMsg.replaceAllAsciiL( + RTL_CONSTASCII_STRINGPARAM("%PATH"), sBackupPath)); dlgError.SetButtonText(dlgError.GetButtonId(0), sBtn); dlgError.Execute(); } diff --git a/l10ntools/inc/export.hxx b/l10ntools/inc/export.hxx index 5e08239316c0..2355f5b23e46 100644 --- a/l10ntools/inc/export.hxx +++ b/l10ntools/inc/export.hxx @@ -54,8 +54,6 @@ #include #endif -#include "helper.hxx" - #define NO_TRANSLATE_ISO "x-no-translate" class PFormEntrys; @@ -196,8 +194,8 @@ public: pPairedList( NULL ), sPForm( rPF ) { - helper::searchAndReplaceAll(&sGId, "\r", rtl::OString()); - helper::searchAndReplaceAll(&sPForm, "\r", rtl::OString()); + sGId = sGId.replaceAll("\r", rtl::OString()); + sPForm = sPForm.replaceAll("\r", rtl::OString()); } ResData(const rtl::OString &rPF, const rtl::OString &rGId , const rtl::OString &rFilename) @@ -227,8 +225,8 @@ public: pPairedList( NULL ), sPForm( rPF ) { - helper::searchAndReplaceAll(&sGId, "\r", rtl::OString()); - helper::searchAndReplaceAll(&sPForm, "\r", rtl::OString()); + sGId = sGId.replaceAll("\r", rtl::OString()); + sPForm = sPForm.replaceAll("\r", rtl::OString()); } }; diff --git a/l10ntools/source/cfgmerge.cxx b/l10ntools/source/cfgmerge.cxx index 1d15fc78bea7..2c39fc68ee52 100644 --- a/l10ntools/source/cfgmerge.cxx +++ b/l10ntools/source/cfgmerge.cxx @@ -37,7 +37,6 @@ #include "rtl/strbuf.hxx" #include "common.hxx" -#include "helper.hxx" #include "export.hxx" #include "cfgmerge.hxx" #include "tokens.h" @@ -235,18 +234,12 @@ void CfgParser::AddText( ) /*****************************************************************************/ { - sal_Int32 nTextLen = 0; - while ( rText.getLength() != nTextLen ) { - nTextLen = rText.getLength(); - rText = rText.replace( '\n', ' ' ); - rText = rText.replace( '\r', ' ' ); - rText = rText.replace( '\t', ' ' ); - while (helper::searchAndReplace(&rText, " ", " ") != -1) {} - } - pStackData->sResTyp = rResTyp; - WorkOnText( rText, rIsoLang ); - - pStackData->sText[ rIsoLang ] = rText; + rText = rText.replaceAll(rtl::OString('\n'), rtl::OString()). + replaceAll(rtl::OString('\r'), rtl::OString()). + replaceAll(rtl::OString('\t'), rtl::OString()); + pStackData->sResTyp = rResTyp; + WorkOnText( rText, rIsoLang ); + pStackData->sText[ rIsoLang ] = rText; } /*****************************************************************************/ @@ -274,12 +267,8 @@ int CfgParser::ExecuteAnalyzedToken( int nToken, char *pToken ) case ANYTOKEN: case CFG_TEXT_START: { - sal_Int32 n = 0; - rtl::OString t(sToken.getToken(1, '<', n)); - n = 0; - t = t.getToken(0, '>', n); - n = 0; - sTokenName = t.getToken(0, ' ', n); + sTokenName = sToken.getToken(1, '<').getToken(0, '>'). + getToken(0, ' '); if ( !IsTokenClosed( sToken )) { rtl::OString sSearch; @@ -315,8 +304,7 @@ int CfgParser::ExecuteAnalyzedToken( int nToken, char *pToken ) sCurrentResTyp = sTokenName; rtl::OString sTemp = sToken.copy( sToken.indexOf( "xml:lang=" )); - n = 0; - sCurrentIsoLang = sTemp.getToken(1, '"', n); + sCurrentIsoLang = sTemp.getToken(1, '"'); if ( sCurrentIsoLang == NO_TRANSLATE_ISO ) bLocalize = sal_False; @@ -330,8 +318,7 @@ int CfgParser::ExecuteAnalyzedToken( int nToken, char *pToken ) if ( !sSearch.isEmpty()) { rtl::OString sTemp = sToken.copy( sToken.indexOf( sSearch )); - n = 0; - sTokenId = sTemp.getToken(1, '"', n); + sTokenId = sTemp.getToken(1, '"'); } pStackData = aStack.Push( sTokenName, sTokenId ); @@ -356,12 +343,8 @@ int CfgParser::ExecuteAnalyzedToken( int nToken, char *pToken ) break; case CFG_CLOSETAG: { - sal_Int32 n = 0; - rtl::OString t(sToken.getToken(1, '/', n)); - n = 0; - t = t.getToken(0, '>', n); - n = 0; - sTokenName = t.getToken(0, ' ', n); + sTokenName = sToken.getToken(1, '/').getToken(0, '>'). + getToken(0, ' '); if ( aStack.GetStackData() && ( aStack.GetStackData()->GetTagType() == sTokenName )) { if (sCurrentText.isEmpty()) @@ -660,13 +643,12 @@ void CfgMerge::WorkOnRessourceEnd() sSearch += sTemp.getToken(0, '"', n); sSearch += "\""; - n = 0; - rtl::OString sReplace = sTemp.getToken(0, '"', n); + rtl::OString sReplace = sTemp.getToken(0, '"'); sReplace += "\""; sReplace += sCur; sReplace += "\""; - helper::searchAndReplace(&sTextTag, sSearch, sReplace); + sTextTag = sTextTag.replaceFirst(sSearch, sReplace); sAdditionalLine += sTextTag; sAdditionalLine += sText; diff --git a/l10ntools/source/export.cxx b/l10ntools/source/export.cxx index c57591b3553e..6a43da8068b1 100644 --- a/l10ntools/source/export.cxx +++ b/l10ntools/source/export.cxx @@ -243,7 +243,7 @@ sal_Bool ResData::SetId( const rtl::OString& rId, sal_uInt16 nLevel ) if ( sId.getLength() > 255 ) { YYWarning( "LocalId > 255 chars, truncating..." ); - sId = helper::trimAscii(sId.copy(0, 255)); + sId = sId.copy(0, 255).trim(); } return sal_True; @@ -362,8 +362,8 @@ int Export::Execute( int nToken, const char * pToken ) if ( nToken == CONDITION ) { rtl::OString sTestToken(pToken); - helper::searchAndReplaceAll(&sTestToken, "\t", rtl::OString()); - helper::searchAndReplaceAll(&sTestToken, " ", rtl::OString()); + sTestToken = sTestToken.replaceAll("\t", rtl::OString()). + replaceAll(" ", rtl::OString()); if (( !bReadOver ) && ( sTestToken.indexOf("#ifndef__RSC_PARSER") == 0 )) bReadOver = sal_True; else if (( bReadOver ) && ( sTestToken.indexOf("#endif") == 0 )) @@ -456,9 +456,14 @@ int Export::Execute( int nToken, const char * pToken ) switch ( nToken ) { case NORMDEFINE: - while( helper::searchAndReplace(&sToken, "\r", " " ) != -1 ) {}; - while( helper::searchAndReplace(&sToken, "\t", " " ) != -1 ) {}; - while( helper::searchAndReplace(&sToken, " ", " " ) != -1 ) {}; + sToken = sToken.replace('\r', ' ').replace('\t', ' '); + for (;;) { + sal_Int32 n = 0; + sToken = sToken.replaceFirst(" ", " ", &n); + if (n == -1) { + break; + } + } if( sToken.equalsIgnoreAsciiCaseL(RTL_CONSTASCII_STRINGPARAM("#define NO_LOCALIZE_EXPORT")) ){ bSkipFile = true; return 0; @@ -487,13 +492,11 @@ int Export::Execute( int nToken, const char * pToken ) pResData = new ResData( sActPForm, FullId() , sFilename ); aResStack.push_back( pResData ); - helper::searchAndReplaceAll(&sToken, "\n", rtl::OString()); - helper::searchAndReplaceAll(&sToken, "\r", rtl::OString()); - helper::searchAndReplaceAll(&sToken, "{", rtl::OString()); - helper::searchAndReplaceAll(&sToken, "\t", " "); - sToken = helper::trimAscii(sToken); - sal_Int32 n = 0; - rtl::OString sTLower = sToken.getToken(0, ' ', n).toAsciiLowerCase(); + sToken = sToken.replaceAll("\n", rtl::OString()). + replaceAll("\r", rtl::OString()). + replaceAll("{", rtl::OString()).replace('\t', ' '); + sToken = sToken.trim(); + rtl::OString sTLower = sToken.getToken(0, ' ').toAsciiLowerCase(); pResData->sResTyp = sTLower; rtl::OString sId( sToken.copy( pResData->sResTyp.getLength() + 1 )); rtl::OString sCondition; @@ -501,14 +504,13 @@ int Export::Execute( int nToken, const char * pToken ) { // between ResTyp, Id and paranthes is a precomp. condition sCondition = "#"; - n = 0; + sal_Int32 n = 0; sId = sId.getToken(0, '#', n); sCondition += sId.getToken(0, '#', n); } - n = 0; - sId = sId.getToken(0, '/', n); + sId = sId.getToken(0, '/'); CleanValue( sId ); - helper::searchAndReplaceAll(&sId, "\t", rtl::OString()); + sId = sId.replaceAll("\t", rtl::OString()); pResData->SetId( sId, ID_LEVEL_IDENTIFIER ); if (!sCondition.isEmpty()) { @@ -529,13 +531,12 @@ int Export::Execute( int nToken, const char * pToken ) pResData = new ResData( sActPForm, FullId() , sFilename ); aResStack.push_back( pResData ); - helper::searchAndReplaceAll(&sToken, "\n", rtl::OString()); - helper::searchAndReplaceAll(&sToken, "\r", rtl::OString()); - helper::searchAndReplaceAll(&sToken, "{", rtl::OString()); - helper::searchAndReplaceAll(&sToken, "\t", rtl::OString()); - helper::searchAndReplaceAll(&sToken, " ", rtl::OString()); - helper::searchAndReplaceAll(&sToken, "\\", rtl::OString()); - sToken = sToken.toAsciiLowerCase(); + sToken = sToken.replaceAll("\n", rtl::OString()). + replaceAll("\r", rtl::OString()). + replaceAll("{", rtl::OString()). + replaceAll("\t", rtl::OString()). + replaceAll(" ", rtl::OString()). + replaceAll("\\", rtl::OString()).toAsciiLowerCase(); pResData->sResTyp = sToken; } break; @@ -595,17 +596,17 @@ int Export::Execute( int nToken, const char * pToken ) bDontWriteOutput = sal_False; // interpret different types of assignement sal_Int32 n = 0; - rtl::OString sKey = sToken.getToken(0, '=', n); - helper::searchAndReplaceAll(&sKey, " ", rtl::OString()); - helper::searchAndReplaceAll(&sKey, "\t", rtl::OString()); + rtl::OString sKey = sToken.getToken(0, '=', n). + replaceAll(" ", rtl::OString()). + replaceAll("\t", rtl::OString()); rtl::OString sValue = sToken.getToken(0, '=', n); CleanValue( sValue ); sKey = sKey.toAsciiUpperCase(); if (sKey.equalsL(RTL_CONSTASCII_STRINGPARAM("IDENTIFIER"))) { - rtl::OString sId(sValue); - helper::searchAndReplaceAll(&sId, "\t", rtl::OString()); - helper::searchAndReplaceAll(&sId, " ", rtl::OString()); + rtl::OString sId( + sValue.replaceAll("\t", rtl::OString()). + replaceAll(" ", rtl::OString())); pResData->SetId(sId, ID_LEVEL_IDENTIFIER); } else if (sKey.equalsL(RTL_CONSTASCII_STRINGPARAM("HELPID"))) @@ -648,16 +649,14 @@ int Export::Execute( int nToken, const char * pToken ) case LISTASSIGNMENT: { bDontWriteOutput = sal_False; - rtl::OString sTmpToken(sToken); - helper::searchAndReplaceAll(&sTmpToken, " ", rtl::OString()); - sTmpToken = sTmpToken.toAsciiLowerCase(); + rtl::OString sTmpToken( + sToken.replaceAll(" ", rtl::OString()).toAsciiLowerCase()); sal_Int32 nPos = sTmpToken.indexOf("[en-us]="); if (nPos != -1) { - rtl::OString sKey(sTmpToken.copy(0 , nPos)); - helper::searchAndReplaceAll(&sKey, " ", rtl::OString()); - helper::searchAndReplaceAll(&sKey, "\t", rtl::OString()); - sal_Int32 n = 0; - rtl::OString sValue = sToken.getToken(1, '=', n); + rtl::OString sKey( + sTmpToken.copy(0 , nPos).replaceAll(" ", rtl::OString()). + replaceAll("\t", rtl::OString())); + rtl::OString sValue = sToken.getToken(1, '='); CleanValue( sValue ); sKey = sKey.toAsciiUpperCase(); if (sKey.equalsL(RTL_CONSTASCII_STRINGPARAM("STRINGLIST"))) @@ -706,10 +705,9 @@ int Export::Execute( int nToken, const char * pToken ) { // new res. is a String- or FilterList sal_Int32 n = 0; - rtl::OString sKey = sToken.getToken(0, '[', n); - helper::searchAndReplaceAll(&sKey, " ", rtl::OString()); - helper::searchAndReplaceAll(&sKey, "\t", rtl::OString()); - sKey = sKey.toAsciiUpperCase(); + rtl::OString sKey( + sToken.getToken(0, '[', n).replaceAll(" ", rtl::OString()). + replaceAll("\t", rtl::OString()).toAsciiUpperCase()); if (sKey.equalsL(RTL_CONSTASCII_STRINGPARAM("STRINGLIST"))) nList = LIST_STRING; else if (sKey.equalsL(RTL_CONSTASCII_STRINGPARAM("FILTERLIST"))) @@ -758,23 +756,16 @@ int Export::Execute( int nToken, const char * pToken ) CutComment( sToken ); // this is a text line!!! - sal_Int32 n = 0; - rtl::OString t(sToken.getToken(0, '=', n)); - n = 0; - rtl::OString sKey = t.getToken(0, '[', n); - helper::searchAndReplaceAll(&sKey, " ", rtl::OString()); - helper::searchAndReplaceAll(&sKey, "\t", rtl::OString()); + rtl::OString t(sToken.getToken(0, '=')); + rtl::OString sKey( + t.getToken(0, '[').replaceAll(" ", rtl::OString()). + replaceAll("\t", rtl::OString())); rtl::OString sText( GetText( sToken, nToken )); rtl::OString sLang; - n = 0; - if ( sToken.getToken(0, '=', n).indexOf('[') != -1 ) + if ( sToken.getToken(0, '=').indexOf('[') != -1 ) { - n = 0; - t = sToken.getToken(0, '=', n); - n = 0; - t = t.getToken(1, '[', n); - n = 0; - sLang = t.getToken(0, ']', n); + sLang = sToken.getToken(0, '=').getToken(1, '['). + getToken(0, ']'); CleanValue( sLang ); } rtl::OString sLangIndex = sLang; @@ -879,25 +870,19 @@ int Export::Execute( int nToken, const char * pToken ) // this is a AppfontMapping, so look if its a definition // of field size sal_Int32 n = 0; - rtl::OString sKey = sToken.getToken(0, '=', n); - helper::searchAndReplaceAll(&sKey, " ", rtl::OString()); - helper::searchAndReplaceAll(&sKey, "\t", rtl::OString()); + rtl::OString sKey( + sToken.getToken(0, '=', n).replaceAll(" ", rtl::OString()). + replaceAll("\t", rtl::OString())); rtl::OString sMapping = sToken.getToken(0, '=', n); - n = 0; - sMapping = sMapping.getToken(1, '(', n); - n = 0; - sMapping = sMapping.getToken(0, ')', n); - helper::searchAndReplaceAll( - &sMapping, rtl::OString(' '), rtl::OString()); - helper::searchAndReplaceAll( - &sMapping, rtl::OString('\t'), rtl::OString()); - sKey = sKey.toAsciiUpperCase(); + sMapping = sMapping.getToken(1, '('); + sMapping = sMapping.getToken(0, ')'). + replaceAll(rtl::OString(' '), rtl::OString()). + replaceAll(rtl::OString('\t'), rtl::OString()). + toAsciiUpperCase(); if (sKey.equalsL(RTL_CONSTASCII_STRINGPARAM("SIZE"))) { - n = 0; - pResData->nWidth = sMapping.getToken(0, ',', n).toInt32(); + pResData->nWidth = sMapping.getToken(0, ',').toInt32(); } else if (sKey.equalsL(RTL_CONSTASCII_STRINGPARAM("POSSIZE"))) { - n = 0; - pResData->nWidth = sMapping.getToken(2, ',', n).toInt32(); + pResData->nWidth = sMapping.getToken(2, ',').toInt32(); } } break; @@ -906,9 +891,14 @@ int Export::Execute( int nToken, const char * pToken ) break; case CONDITION: { bDontWriteOutput = sal_False; - while( helper::searchAndReplace(&sToken, "\r", " " ) != -1 ) {}; - while( helper::searchAndReplace(&sToken, "\t", " " ) != -1 ) {}; - while( helper::searchAndReplace(&sToken, " ", " " ) != -1 ) {}; + sToken = sToken.replace('\r', ' ').replace('\t', ' '); + for (;;) { + sal_Int32 n = 0; + sToken = sToken.replaceFirst(" ", " ", &n); + if (n == -1) { + break; + } + } sal_Int32 n = 0; rtl::OString sCondition(sToken.getToken(0, ' ', n)); if ( sCondition == "#ifndef" ) { @@ -920,12 +910,10 @@ int Export::Execute( int nToken, const char * pToken ) sActPForm += sToken.getToken(0, ' ', n); } else if ( sCondition == "#if" ) { - sActPForm = sToken.copy( 4 ); - while ( helper::searchAndReplace(&sActPForm, "||", "\\or" ) != -1 ) {}; + sActPForm = sToken.copy( 4 ).replaceAll("||", "\\or"); } else if ( sCondition == "#elif" ) { - sActPForm = sToken.copy( 6 ); - while ( helper::searchAndReplace(&sActPForm, "||", "\\or" ) != -1 ) {}; + sActPForm = sToken.copy( 6 ).replaceAll("||", "\\or"); } else if ( sCondition == "#else" ) { sActPForm = sCondition; @@ -985,8 +973,7 @@ void Export::CutComment( rtl::OString &rText ) /*****************************************************************************/ { if (rText.indexOf("//") != -1) { - rtl::OString sWork(rText); - helper::searchAndReplaceAll(&sWork, "\\\"", "XX"); + rtl::OString sWork(rText.replaceAll("\\\"", "XX")); bool bInner = false; for (sal_Int32 i = 0; i < sWork.getLength() - 1; ++i) { if (sWork[i] == '"') { @@ -1135,20 +1122,17 @@ sal_Bool Export::WriteData( ResData *pResData, sal_Bool bCreateNew ) rtl::OString Export::GetPairedListID(const rtl::OString& rText) { // < "STRING" ; IDENTIFIER ; > ; - sal_Int32 n = 0; - return helper::trimAscii( - rText.getToken(1, ';', n).toAsciiUpperCase().replace('\t', ' ')); + return rText.getToken(1, ';').toAsciiUpperCase().replace('\t', ' ').trim(); } rtl::OString Export::GetPairedListString(const rtl::OString& rText) { // < "STRING" ; IDENTIFIER ; > ; - sal_Int32 n = 0; - rtl::OString sString(rText.getToken(0, ';', n).replace('\t', ' ')); - sString = helper::trimAscii(sString); + rtl::OString sString(rText.getToken(0, ';').replace('\t', ' ')); + sString = sString.trim(); rtl::OString s1(sString.copy(sString.indexOf('"') + 1)); sString = s1.copy(0, s1.lastIndexOf('"')); - return helper::trimAscii(sString); + return sString.trim(); } rtl::OString Export::StripList(const rtl::OString & rText) @@ -1360,20 +1344,17 @@ rtl::OString Export::GetText(const rtl::OString &rSource, int nToken) { rtl::OString sTmp(rSource.copy(rSource.indexOf("="))); CleanValue( sTmp ); - helper::searchAndReplaceAll(&sTmp, "\n", rtl::OString()); - helper::searchAndReplaceAll(&sTmp, "\r", rtl::OString()); - - helper::searchAndReplaceAll( - &sTmp, "\\\\\"", "-=<[BSlashBSlashHKom]>=-\""); - helper::searchAndReplaceAll(&sTmp, "\\\"", "-=<[Hochkomma]>=-"); - helper::searchAndReplaceAll(&sTmp, "\\", "-=<[0x7F]>=-"); - helper::searchAndReplaceAll(&sTmp, "\\0x7F", "-=<[0x7F]>=-"); + sTmp = sTmp.replaceAll("\n", rtl::OString()). + replaceAll("\r", rtl::OString()). + replaceAll("\\\\\"", "-=<[BSlashBSlashHKom]>=-\""). + replaceAll("\\\"", "-=<[Hochkomma]>=-"). + replaceAll("\\", "-=<[0x7F]>=-"). + replaceAll("\\0x7F", "-=<[0x7F]>=-"); sal_uInt16 nState = TXT_STATE_TEXT; for (sal_Int32 i = 1; i <= helper::countOccurrences(sTmp, '"'); ++i) { - sal_Int32 n = 0; - rtl::OString sToken(sTmp.getToken(i, '"', n)); + rtl::OString sToken(sTmp.getToken(i, '"')); if (!sToken.isEmpty()) { if ( nState == TXT_STATE_TEXT ) { sReturn += sToken; @@ -1381,10 +1362,14 @@ rtl::OString Export::GetText(const rtl::OString &rSource, int nToken) } else { sToken = sToken.replace('\t', ' '); - while (helper::searchAndReplace(&sToken, " ", " ") - != -1) - {} - sToken = helper::trimAscii(sToken); + for (;;) { + sal_Int32 n = 0; + sToken = sToken.replaceFirst(" ", " ", &n); + if (n == -1) { + break; + } + } + sToken = sToken.trim(); if (!sToken.isEmpty()) { sReturn += "\\\" "; sReturn += sToken; @@ -1395,13 +1380,11 @@ rtl::OString Export::GetText(const rtl::OString &rSource, int nToken) } } - helper::searchAndReplaceAll(&sReturn, "-=<[0x7F]>=-", ""); - helper::searchAndReplaceAll(&sReturn, "-=<[Hochkomma]>=-", "\""); - helper::searchAndReplaceAll( - &sReturn, "-=<[BSlashBSlashHKom]>=-", "\\\\"); - helper::searchAndReplaceAll( - &sReturn, "\\\\", "-=<[BSlashBSlash]>=-"); - helper::searchAndReplaceAll(&sReturn, "-=<[BSlashBSlash]>=-", "\\"); + sReturn = sReturn.replaceAll("-=<[0x7F]>=-", ""). + replaceAll("-=<[Hochkomma]>=-", "\""). + replaceAll("-=<[BSlashBSlashHKom]>=-", "\\\\"). + replaceAll("\\\\", "-=<[BSlashBSlash]>=-"). + replaceAll("-=<[BSlashBSlash]>=-", "\\"); } break; } @@ -1411,7 +1394,13 @@ rtl::OString Export::GetText(const rtl::OString &rSource, int nToken) void Export::WriteToMerged(const rtl::OString &rText , bool bSDFContent) { rtl::OString sText(rText); - while (helper::searchAndReplace(&sText, " \n", "\n") != -1) {} + for (;;) { + sal_Int32 n = 0; + sText = sText.replaceFirst(" \n", "\n", &n); + if (n == -1) { + break; + } + } if (pParseQueue->bNextIsM && bSDFContent && sText.getLength() > 2) { for (sal_Int32 n = 0; n < sText.getLength(); ++n) { if (sText[n] == '\n' && sText[n - 1] != '\\') { @@ -1456,7 +1445,7 @@ void Export::ConvertMergeContent( rtl::OString &rText ) /*****************************************************************************/ { sal_Bool bNoOpen = ( rText.indexOf( "\\\"" ) != 0 ); - sal_Bool bNoClose = !helper::endsWith(rText, "\\\""); + sal_Bool bNoClose = !rText.endsWithL(RTL_CONSTASCII_STRINGPARAM("\\\"")); rtl::OStringBuffer sNew; for ( sal_Int32 i = 0; i < rText.getLength(); i++ ) { @@ -1886,7 +1875,7 @@ void Export::MergeRest( ResData *pResData, sal_uInt16 nMode ) (( sLine.indexOf( '<' ) == -1 ) || ( sLine.indexOf( '<' ) >= sLine.indexOf( '"' )))) { - helper::searchAndReplace(&sLine, "\"", "< \"" ); + sLine = sLine.replaceFirst("\"", "< \"" ); } } @@ -1992,7 +1981,7 @@ void Export::MergeRest( ResData *pResData, sal_uInt16 nMode ) (( sLine.indexOf( '<' ) == -1 ) || ( sLine.indexOf( '<' ) >= sLine.indexOf( '"' )))) { - helper::searchAndReplace(&sLine, "\"", "< \"" ); + sLine = sLine.replaceFirst("\"", "< \""); } } diff --git a/l10ntools/source/export2.cxx b/l10ntools/source/export2.cxx index 1a1ae9112ece..bad5964b2f6e 100644 --- a/l10ntools/source/export2.cxx +++ b/l10ntools/source/export2.cxx @@ -29,7 +29,6 @@ #include "sal/config.h" #include "export.hxx" -#include "helper.hxx" #include #include #include @@ -302,8 +301,7 @@ void Export::InitLanguages( bool bMergeMode ){ do { rtl::OString aToken = sLanguages.getToken(0, ',', nIndex); - sal_Int32 n = 0; - sTmp = helper::trimAscii(aToken.getToken(0, '=', n)); + sTmp = aToken.getToken(0, '=').trim(); if( bMergeMode && !isAllowed( sTmp ) ){} else if( !( (sTmp[0]=='x' || sTmp[0]=='X') && sTmp[1]=='-' ) ){ aLanguages.push_back( sTmp ); @@ -326,8 +324,7 @@ void Export::InitForcedLanguages( bool bMergeMode ){ { rtl::OString aToken = sForcedLanguages.getToken(0, ',', nIndex); - sal_Int32 n = 0; - sTmp = helper::trimAscii(aToken.getToken(0, '=', n)); + sTmp = aToken.getToken(0, '=').trim(); if( bMergeMode && isAllowed( sTmp ) ){} else if( !( (sTmp[0]=='x' || sTmp[0]=='X') && sTmp[1]=='-' ) ) aForcedLanguages.push_back( sTmp ); diff --git a/l10ntools/source/gsicheck.cxx b/l10ntools/source/gsicheck.cxx index 76b7928ff4b5..d1665ff0e720 100644 --- a/l10ntools/source/gsicheck.cxx +++ b/l10ntools/source/gsicheck.cxx @@ -363,7 +363,7 @@ void GSIBlock::PrintList( ParserMessageList *pList, rtl::OString const & aPrefix aContext = pLine->GetText().copy( 0, 300 ); else aContext = pLine->data_.copy( pMsg->GetTagBegin()-150, 300 ); - aContext = helper::trimAscii(aContext); + aContext = aContext.trim(); } PrintMessage( pMsg->Prefix(), pMsg->GetErrorText(), aPrefix, aContext, pLine->GetLineNumber(), pLine->GetUniqId() ); diff --git a/l10ntools/source/helper.hxx b/l10ntools/source/helper.hxx index b2ff952a675a..59f86287fd72 100644 --- a/l10ntools/source/helper.hxx +++ b/l10ntools/source/helper.hxx @@ -40,10 +40,6 @@ namespace helper { -inline bool isAsciiWhitespace(char c) { - return (c >= 0x09 && c <= 0x0D) || c == ' '; // HT, LF, VT, FF, CR -} - // cf. comphelper::string::isdigitAsciiString: inline bool isAllAsciiDigits(rtl::OString const & text) { for (sal_Int32 i = 0; i != text.getLength(); ++i) { @@ -74,19 +70,6 @@ inline bool isAllAsciiLowerCase(rtl::OString const & text) { return true; } -inline bool endsWith(rtl::OString const & text, rtl::OString const & search) { - return text.getLength() >= search.getLength() - && text.match(search, text.getLength() - search.getLength()); -} - -inline bool endsWithAsciiL( - rtl::OUString const & text, char const * search, sal_Int32 searchLength) -{ - return text.getLength() >= searchLength - && text.matchAsciiL( - search, searchLength, text.getLength() - searchLength); -} - inline sal_Int32 countOccurrences(rtl::OString const & text, char c) { sal_Int32 n = 0; for (sal_Int32 i = 0;; ++i) { @@ -99,67 +82,6 @@ inline sal_Int32 countOccurrences(rtl::OString const & text, char c) { return n; } -inline rtl::OString trimAscii(rtl::OString const & text) { - sal_Int32 i1 = 0; - while (i1 != text.getLength() && isAsciiWhitespace(text[i1])) { - ++i1; - } - sal_Int32 i2 = text.getLength(); - while (i2 != i1 && isAsciiWhitespace(text[i2 - 1])) { - --i2; - } - return text.copy(i1, i2 - i1); -} - -inline sal_Int32 searchAndReplace( - rtl::OString * text, rtl::OString const & search, - rtl::OString const & replace) -{ - assert(text != 0); - sal_Int32 i = text->indexOf(search); - if (i != -1) { - *text = text->replaceAt(i, search.getLength(), replace); - } - return i; -} - -inline void searchAndReplaceAll( - rtl::OString * text, rtl::OString const & search, - rtl::OString const & replace) -{ - assert(text != 0); - for (sal_Int32 i = 0;;) { - i = text->indexOf(search, i); - if (i == -1) { - break; - } - *text = text->replaceAt(i, search.getLength(), replace); - i += replace.getLength(); - } -} - -inline void searchAndReplaceAll( - rtl::OUString * text, rtl::OUString const & search, - rtl::OUString const & replace) -{ - assert(text != 0); - for (sal_Int32 i = 0;;) { - i = text->indexOf(search, i); - if (i == -1) { - break; - } - *text = text->replaceAt(i, search.getLength(), replace); - i += replace.getLength(); - } -} - -inline rtl::OString getToken( - rtl::OString const & text, sal_Int32 token, char separator) -{ - sal_Int32 i = 0; - return text.getToken(token, separator, i); -} - inline sal_Int32 indexOfAnyAsciiL( rtl::OUString const & text, char const * chars, sal_Int32 charsLen, sal_Int32 index = 0) diff --git a/l10ntools/source/helpmerge.cxx b/l10ntools/source/helpmerge.cxx index d3895e66c5fe..ceb0f1e27a29 100644 --- a/l10ntools/source/helpmerge.cxx +++ b/l10ntools/source/helpmerge.cxx @@ -143,13 +143,14 @@ bool HelpParser::CreateSDF( if( pXMLElement != NULL ) { - OUString data = pXMLElement->ToOUString(); - helper::searchAndReplaceAll( - &data, rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\n")), - rtl::OUString()); // remove \n - helper::searchAndReplaceAll( - &data, rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\t")), - rtl::OUString()); // remove \t + OUString data( + pXMLElement->ToOUString(). + replaceAll( + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\n")), + rtl::OUString()). + replaceAll( + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\t")), + rtl::OUString())); sBuffer.append( sOUPrj ); sBuffer.append('\t'); if ( !rRoot_in.isEmpty()) @@ -306,13 +307,13 @@ bool HelpParser::MergeSingleFile( XMLFile* file , MergeDataFile& aMergeDataFile rtl::OString HelpParser::GetOutpath( const rtl::OString& rPathX , const rtl::OString& sCur , const rtl::OString& rPathY ) { rtl::OString testpath = rPathX; - if (!helper::endsWith(testpath, "/")) { + if (!testpath.endsWithL(RTL_CONSTASCII_STRINGPARAM("/"))) { testpath += "/"; } testpath += sCur; testpath += "/"; rtl::OString sRelativePath( rPathY ); - if (sRelativePath.getLength() != 0 && sRelativePath[0] == '/') { + if (sRelativePath.matchL(RTL_CONSTASCII_STRINGPARAM("/"))) { sRelativePath = sRelativePath.copy(1); } testpath += sRelativePath; @@ -322,14 +323,12 @@ rtl::OString HelpParser::GetOutpath( const rtl::OString& rPathX , const rtl::OSt void HelpParser::MakeDir(const rtl::OString& rPath) { - rtl::OString sTPath(rPath); - helper::searchAndReplaceAll(&sTPath, "\\", "/"); + rtl::OString sTPath(rPath.replaceAll("\\", "/")); sal_Int32 cnt = helper::countOccurrences(sTPath, '/'); rtl::OStringBuffer sCreateDir; for (sal_uInt16 i = 0; i <= cnt; ++i) { - sal_Int32 n = 0; - sCreateDir.append(sTPath.getToken(i , '/', n)); + sCreateDir.append(sTPath.getToken(i , '/')); sCreateDir.append('/'); #ifdef WNT _mkdir( sCreateDir.getStr() ); diff --git a/l10ntools/source/lngmerge.cxx b/l10ntools/source/lngmerge.cxx index 00a997aa2fad..6541bd9ab2ba 100644 --- a/l10ntools/source/lngmerge.cxx +++ b/l10ntools/source/lngmerge.cxx @@ -34,16 +34,12 @@ #include #include "common.hxx" -#include "helper.hxx" #include "lngmerge.hxx" namespace { rtl::OString getBracketedContent(rtl::OString text) { - sal_Int32 n = 0; - rtl::OString t(text.getToken(1, '[', n)); - n = 0; - return t.getToken(0, ']', n); + return text.getToken(1, '[').getToken(0, ']'); } } @@ -162,10 +158,10 @@ void LngParser::WriteSDF(std::ofstream &aSDFStream, bool LngParser::isNextGroup(rtl::OString &sGroup_out, rtl::OString &sLine_in) { - sLine_in = helper::trimAscii(sLine_in); + sLine_in = sLine_in.trim(); if ((sLine_in[0] == '[') && (sLine_in[sLine_in.getLength() - 1] == ']')) { - sGroup_out = helper::trimAscii(getBracketedContent(sLine_in)); + sGroup_out = getBracketedContent(sLine_in).trim(); return true; } return false; @@ -174,11 +170,9 @@ bool LngParser::isNextGroup(rtl::OString &sGroup_out, rtl::OString &sLine_in) void LngParser::ReadLine(const rtl::OString &rLine_in, OStringHashMap &rText_inout) { - sal_Int32 n = 0; - rtl::OString sLang(helper::trimAscii(rLine_in.getToken(0, '=', n))); + rtl::OString sLang(rLine_in.getToken(0, '=').trim()); if (!sLang.isEmpty()) { - n = 0; - rtl::OString sText(rLine_in.getToken(1, '"', n)); + rtl::OString sText(rLine_in.getToken(1, '"')); rText_inout[sLang] = sText; } } @@ -209,11 +203,11 @@ sal_Bool LngParser::Merge( while ( nPos < pLines->size() && !bGroup ) { rtl::OString sLine( *(*pLines)[ nPos ] ); - sLine = helper::trimAscii(sLine); + sLine = sLine.trim(); if (( sLine[0] == '[' ) && ( sLine[sLine.getLength() - 1] == ']' )) { - sGroup = helper::trimAscii(getBracketedContent(sLine)); + sGroup = getBracketedContent(sLine).trim(); bGroup = sal_True; } nPos ++; @@ -235,11 +229,11 @@ sal_Bool LngParser::Merge( while ( nPos < pLines->size() && !bGroup ) { rtl::OString sLine( *(*pLines)[ nPos ] ); - sLine = helper::trimAscii(sLine); + sLine = sLine.trim(); if (( sLine[0] == '[' ) && ( sLine[sLine.getLength() - 1] == ']' )) { - sGroup = helper::trimAscii(getBracketedContent(sLine)); + sGroup = getBracketedContent(sLine).trim(); bGroup = sal_True; nPos ++; sLanguagesDone = ""; @@ -254,7 +248,7 @@ sal_Bool LngParser::Merge( } else { - sLang = helper::trimAscii(sLang); + sLang = sLang.trim(); rtl::OString sSearch( ";" ); sSearch += sLang; diff --git a/l10ntools/source/localize.cxx b/l10ntools/source/localize.cxx index e259ef722dcf..6fb83e1a9bc4 100644 --- a/l10ntools/source/localize.cxx +++ b/l10ntools/source/localize.cxx @@ -50,8 +50,6 @@ #include "sal/main.h" #include "sal/types.h" -#include "helper.hxx" - using namespace std; namespace { @@ -104,7 +102,7 @@ bool matchList( rtl::OUString const & url, AsciiString const * list, std::size_t length) { for (std::size_t i = 0; i != length; ++i) { - if (helper::endsWithAsciiL(url, list[i].string, list[i].length)) { + if (url.endsWithAsciiL(list[i].string, list[i].length)) { return true; } } @@ -272,8 +270,8 @@ void handleFile( { RTL_CONSTASCII_STRINGPARAM(".xhp"), "helpex", false }, { RTL_CONSTASCII_STRINGPARAM(".properties"), "propex", false } }; for (std::size_t i = 0; i != SAL_N_ELEMENTS(commands); ++i) { - if (helper::endsWithAsciiL( - url, commands[i].extension, commands[i].extensionLength)) + if (url.endsWithAsciiL( + commands[i].extension, commands[i].extensionLength)) { handleCommand( project, projectRoot, url, diff --git a/l10ntools/source/merge.cxx b/l10ntools/source/merge.cxx index c56bdafb0e4c..b9b8d400ec9b 100644 --- a/l10ntools/source/merge.cxx +++ b/l10ntools/source/merge.cxx @@ -34,7 +34,6 @@ #include #include "export.hxx" -#include "helper.hxx" namespace { @@ -201,7 +200,7 @@ MergeDataFile::MergeDataFile( rtl::OString sPFO = sLine.getToken( 1, '\t', n ); // token 7 sPFO = sHACK; rtl::OString nLANG = sLine.getToken( 1, '\t', n ); // token 9 - nLANG = helper::trimAscii(nLANG); + nLANG = nLANG.trim(); const rtl::OString sTEXT = sLine.getToken( 0, '\t', n ); // token 10 const rtl::OString sQHTEXT = sLine.getToken( 1, '\t', n ); // token 12 const rtl::OString sTITLE = sLine.getToken( 0, '\t', n ); // token 13 diff --git a/l10ntools/source/xrmmerge.cxx b/l10ntools/source/xrmmerge.cxx index 1e25534b4d4b..0f1e3e0d2fbf 100644 --- a/l10ntools/source/xrmmerge.cxx +++ b/l10ntools/source/xrmmerge.cxx @@ -34,7 +34,6 @@ #include "common.hxx" #include "export.hxx" -#include "helper.hxx" #include "xrmmerge.hxx" #include "tokens.h" #include @@ -390,11 +389,10 @@ rtl::OString XRMResParser::GetAttribute( const rtl::OString &rToken, const rtl:: if ( nPos != -1 ) { sTmp = sTmp.copy( nPos ); - sal_Int32 n = 0; - rtl::OString sId = sTmp.getToken(1, '"', n); + rtl::OString sId = sTmp.getToken(1, '"'); return sId; } - return ""; + return rtl::OString(); } @@ -409,15 +407,14 @@ void XRMResParser::Error( const rtl::OString &rError ) void XRMResParser::ConvertStringToDBFormat( rtl::OString &rString ) /*****************************************************************************/ { - rString = helper::trimAscii(rString); - helper::searchAndReplaceAll(&rString, "\t", "\\t"); + rString = rString.trim().replaceAll("\t", "\\t"); } /*****************************************************************************/ void XRMResParser::ConvertStringToXMLFormat( rtl::OString &rString ) /*****************************************************************************/ { - helper::searchAndReplaceAll(&rString, "\\t", "\t"); + rString = rString.replaceAll("\\t", "\t"); } @@ -480,8 +477,8 @@ void XRMResExport::WorkOnDesc( ) /*****************************************************************************/ { - rtl::OString sDescFileName(sInputFileName); - helper::searchAndReplaceAll(&sDescFileName, "description.xml", ""); + rtl::OString sDescFileName( + sInputFileName.replaceAll("description.xml", rtl::OString())); sDescFileName += GetAttribute( rOpenTag, "xlink:href" ); int size; char * memblock; @@ -493,8 +490,7 @@ void XRMResExport::WorkOnDesc( file.read (memblock, size); file.close(); memblock[size] = '\0'; - rText = rtl::OString(memblock); - helper::searchAndReplaceAll(&rText, "\n", "\\n"); + rText = rtl::OString(memblock).replaceAll("\n", "\\n"); delete[] memblock; } WorkOnText( rOpenTag, rText ); @@ -536,8 +532,8 @@ void XRMResExport::EndOfText( { sCur = aLanguages[ n ]; - rtl::OString sAct = pResData->sText[ sCur ]; - helper::searchAndReplaceAll(&sAct, "\x0A", rtl::OString()); + rtl::OString sAct( + pResData->sText[sCur].replaceAll("\x0A", rtl::OString())); rtl::OString sOutput( sPrj ); sOutput += "\t"; sOutput += sPath; @@ -629,19 +625,20 @@ void XRMResMerge::WorkOnDesc( sSearch += GetAttribute( rOpenTag, sLangAttribute ); sReplace += sCur; - helper::searchAndReplace( - &sAdditionalLine, sSearch, sReplace); + sAdditionalLine = sAdditionalLine.replaceFirst( + sSearch, sReplace); sSearch = rtl::OString("xlink:href=\""); sReplace = sSearch; rtl::OString sLocDescFilename = sDescFilename; - helper::searchAndReplace(&sLocDescFilename, "en-US", sCur); + sLocDescFilename = sLocDescFilename.replaceFirst( + "en-US", sCur); sSearch += sDescFilename; sReplace += sLocDescFilename; - helper::searchAndReplace( - &sAdditionalLine, sSearch, sReplace); + sAdditionalLine = sAdditionalLine.replaceFirst( + sSearch, sReplace); Output( sAdditionalLine ); @@ -654,7 +651,7 @@ void XRMResMerge::WorkOnDesc( } rtl::OString sOutputDescFile( sOutputFile.copy(0, i + 1) + sLocDescFilename); - helper::searchAndReplaceAll(&sText, "\\n", "\n"); + sText = sText.replaceAll("\\n", "\n"); ofstream file(sOutputDescFile.getStr()); if (file.is_open()) { file << sText.getStr(); @@ -745,8 +742,8 @@ void XRMResMerge::EndOfText( sSearch += GetAttribute( rOpenTag, sLangAttribute ); sReplace += sCur; - helper::searchAndReplace( - &sAdditionalLine, sSearch, sReplace); + sAdditionalLine = sAdditionalLine.replaceFirst( + sSearch, sReplace); sAdditionalLine += sText; sAdditionalLine += rCloseTag; diff --git a/linguistic/source/dicimp.cxx b/linguistic/source/dicimp.cxx index 0e721ac29a6b..85a25afa5ddb 100644 --- a/linguistic/source/dicimp.cxx +++ b/linguistic/source/dicimp.cxx @@ -146,7 +146,7 @@ sal_Int16 ReadDicVersion( SvStreamPtr &rpStream, sal_uInt16 &nLng, sal_Bool &bNe bNeg = sal_False; } - if (comphelper::string::indexOfL(aLine, RTL_CONSTASCII_STRINGPARAM("---")) != -1) // end of header + if (aLine.indexOfL(RTL_CONSTASCII_STRINGPARAM("---")) != -1) // end of header break; } if (!bSuccess) diff --git a/oox/source/export/drawingml.cxx b/oox/source/export/drawingml.cxx index 0d4c3fae4ff9..ea35320461cd 100644 --- a/oox/source/export/drawingml.cxx +++ b/oox/source/export/drawingml.cxx @@ -64,7 +64,6 @@ #include #include #include -#include #include #include #include @@ -451,8 +450,7 @@ OUString DrawingML::WriteImage( const OUString& rURL ) rtl::OString aURLBS(rtl::OUStringToOString(rURL, RTL_TEXTENCODING_UTF8)); const char aURLBegin[] = "vnd.sun.star.GraphicObject:"; - using comphelper::string::indexOfL; - sal_Int32 index = indexOfL(aURLBS, RTL_CONSTASCII_STRINGPARAM(aURLBegin)); + sal_Int32 index = aURLBS.indexOfL(RTL_CONSTASCII_STRINGPARAM(aURLBegin)); if ( index != -1 ) { diff --git a/padmin/source/adddlg.cxx b/padmin/source/adddlg.cxx index 382924c37b7f..df2f4e2c8f93 100644 --- a/padmin/source/adddlg.cxx +++ b/padmin/source/adddlg.cxx @@ -39,7 +39,6 @@ #include #include #include -#include #include using namespace psp; @@ -508,8 +507,6 @@ APOldPrinterPage::APOldPrinterPage( AddPrinterDialog* pParent ) rtl::OString aDefCopies( aConfig.ReadKey( "Copies" ) ); rtl::OString aDefDPI( aConfig.ReadKey( "DPI" ) ); - using comphelper::string::getToken; - aConfig.SetGroup( "devices" ); int nDevices = aConfig.GetKeyCount(); for( int nKey = 0; nKey < nDevices; nKey++ ) @@ -517,9 +514,9 @@ APOldPrinterPage::APOldPrinterPage( AddPrinterDialog* pParent ) aConfig.SetGroup( "devices" ); rtl::OString aPrinter(aConfig.GetKeyName(nKey)); rtl::OString aValue(aConfig.ReadKey(aPrinter)); - rtl::OString aPort(getToken(aValue, 1, ',')); - rtl::OString aDriver(getToken(aValue, 0, ' ')); - rtl::OString aPS( getToken(getToken(aValue, 0, ','), 1, ' ') ); + rtl::OString aPort(aValue.getToken(1, ',')); + rtl::OString aDriver(aValue.getToken(0, ' ')); + rtl::OString aPS( aValue.getToken(0, ',').getToken(1, ' ') ); rtl::OString aNewDriver(aDriver); if( aDriver.equalsL(RTL_CONSTASCII_STRINGPARAM("GENERIC"))) aNewDriver = rtl::OString(RTL_CONSTASCII_STRINGPARAM("SGENPRT")); @@ -613,7 +610,7 @@ APOldPrinterPage::APOldPrinterPage( AddPrinterDialog* pParent ) // should never have been writte because they are defaults // PageRegion leads to problems in conjunction // with a not matching PageSize - if (comphelper::string::matchL(aPPDKey, RTL_CONSTASCII_STRINGPARAM("PPD_")) && + if (aPPDKey.matchL(RTL_CONSTASCII_STRINGPARAM("PPD_")) && !aPPDKey.equalsL(RTL_CONSTASCII_STRINGPARAM("PPD_PageRegion"))) { aValue = aConfig.ReadKey( nPPDKey ); diff --git a/rsc/source/rsc/rsc.cxx b/rsc/source/rsc/rsc.cxx index 229b5ce36993..d9018d4df9cd 100644 --- a/rsc/source/rsc/rsc.cxx +++ b/rsc/source/rsc/rsc.cxx @@ -75,7 +75,6 @@ using ::rtl::OStringBuffer; using ::rtl::OStringToOUString; using comphelper::string::getToken; using comphelper::string::getTokenCount; -using comphelper::string::indexOfL; /*************** F o r w a r d s *****************************************/ /*************** G l o b a l e V a r i a b l e n **********************/ @@ -1171,7 +1170,7 @@ void RscCompiler::PreprocessSrsFile( const RscCmdLine::OutputFile& rOutputFile, aOStm.WriteLine(aLine); } - else if (indexOfL(aLine, RTL_CONSTASCII_STRINGPARAM("ImageList")) != -1) + else if (aLine.indexOfL(RTL_CONSTASCII_STRINGPARAM("ImageList")) != -1) { ::std::vector< ::std::pair< rtl::OString, sal_Int32 > > aEntryVector; @@ -1186,7 +1185,7 @@ void RscCompiler::PreprocessSrsFile( const RscCmdLine::OutputFile& rOutputFile, if( !aIStm.ReadLine(aLine) ) break; } - while (indexOfL(aLine, RTL_CONSTASCII_STRINGPARAM("Prefix")) == -1); + while (aLine.indexOfL(RTL_CONSTASCII_STRINGPARAM("Prefix")) == -1); const rtl::OString aPrefix( getToken(aLine, 1, '"') ); aIStm.Seek( nImgListStartPos ); @@ -1196,7 +1195,7 @@ void RscCompiler::PreprocessSrsFile( const RscCmdLine::OutputFile& rOutputFile, if (!aIStm.ReadLine(aLine) ) break; } - while (indexOfL(aLine, RTL_CONSTASCII_STRINGPARAM("IdList")) == -1); + while (aLine.indexOfL(RTL_CONSTASCII_STRINGPARAM("IdList")) == -1); // scan all ids and collect images while (aLine.indexOf('}') == -1) @@ -1231,7 +1230,7 @@ void RscCompiler::PreprocessSrsFile( const RscCmdLine::OutputFile& rOutputFile, { aIStm.ReadLine( aLine ); - if (indexOfL(aLine, RTL_CONSTASCII_STRINGPARAM("IdList")) != -1) + if (aLine.indexOfL(RTL_CONSTASCII_STRINGPARAM("IdList")) != -1) { while (aLine.indexOf('}') == -1) aIStm.ReadLine(aLine); diff --git a/sal/CppunitTest_sal_rtl_strings.mk b/sal/CppunitTest_sal_rtl_strings.mk index fe6da666b496..f43e7fd3a73d 100644 --- a/sal/CppunitTest_sal_rtl_strings.mk +++ b/sal/CppunitTest_sal_rtl_strings.mk @@ -28,6 +28,7 @@ $(eval $(call gb_CppunitTest_CppunitTest,sal_rtl_strings)) $(eval $(call gb_CppunitTest_add_exception_objects,sal_rtl_strings,\ + sal/qa/rtl/strings/test_strings_replace \ sal/qa/rtl/strings/test_oustring_compare \ sal/qa/rtl/strings/test_oustring_convert \ sal/qa/rtl/strings/test_oustring_endswith \ diff --git a/sal/inc/rtl/string.h b/sal/inc/rtl/string.h index 671d2fdc0053..da356932979b 100644 --- a/sal/inc/rtl/string.h +++ b/sal/inc/rtl/string.h @@ -1000,6 +1000,66 @@ SAL_DLLPUBLIC void SAL_CALL rtl_string_newReplaceStrAt( SAL_DLLPUBLIC void SAL_CALL rtl_string_newReplace( rtl_String ** newStr, rtl_String * str, sal_Char oldChar, sal_Char newChar ) SAL_THROW_EXTERN_C(); +/** Create a new string by replacing the first occurrence of a given substring + with another substring. + + @param[in, out] newStr pointer to the new string; must not be null; must + point to null or a valid rtl_String + + @param str pointer to the original string; must not be null + + @param from pointer to the substring to be replaced; must not be null and + must point to memory of at least \p fromLength bytes + + @param fromLength the length of the \p from substring; must be non-negative + + @param to pointer to the replacing substring; must not be null and must + point to memory of at least \p toLength bytes + + @param toLength the length of the \p to substring; must be non-negative + + @param[in,out] index pointer to a start index, must not be null; upon entry + to the function its value is the index into the original string at which to + start searching for the \p from substring, the value must be non-negative + and not greater than the original string's length; upon exit from the + function its value is the index into the original string at which the + replacement took place or -1 if no replacement took place + + @since LibreOffice 3.6 +*/ +SAL_DLLPUBLIC void SAL_CALL rtl_string_newReplaceFirst( + rtl_String ** newStr, rtl_String * str, char const * from, + sal_Int32 fromLength, char const * to, sal_Int32 toLength, + sal_Int32 * index) SAL_THROW_EXTERN_C(); + +/** Create a new string by replacing all occurrences of a given substring with + another substring. + + Replacing subsequent occurrences picks up only after a given replacement. + That is, replacing from "xa" to "xx" in "xaa" results in "xxa", not "xxx". + + @param[in, out] newStr pointer to the new string; must not be null; must + point to null or a valid rtl_String + + @param str pointer to the original string; must not be null + + @param from pointer to the substring to be replaced; must not be null and + must point to memory of at least \p fromLength bytes + + @param fromLength the length of the \p from substring; must be non-negative + + @param to pointer to the replacing substring; must not be null and must + point to memory of at least \p toLength bytes + + @param toLength the length of the \p to substring; must be non-negative + + @since LibreOffice 3.6 +*/ +SAL_DLLPUBLIC void SAL_CALL rtl_string_newReplaceAll( + rtl_String ** newStr, rtl_String * str, char const * from, + sal_Int32 fromLength, char const * to, sal_Int32 toLength) + SAL_THROW_EXTERN_C(); + /** Create a new string by converting all ASCII uppercase letters to lowercase within another string. diff --git a/sal/inc/rtl/string.hxx b/sal/inc/rtl/string.hxx index e39e0e091cdf..68f2aa190ce4 100644 --- a/sal/inc/rtl/string.hxx +++ b/sal/inc/rtl/string.hxx @@ -470,6 +470,31 @@ public: str.pData->buffer, str.pData->length, str.pData->length ) == 0; } + /** + Match against a substring appearing in this string. + + @param str the substring to be compared; must not be null and must point + to memory of at least strLength bytes + + @param strLength the length of the substring; must be non-negative + + @param fromIndex the index into this string to start the comparison at; + must be non-negative and not greater than this string's length + + @return true if and only if the given str is contained as a substring of + this string at the given fromIndex + + @since LibreOffice 3.6 + */ + bool matchL( + char const * str, sal_Int32 strLength, sal_Int32 fromIndex = 0) + const + { + return rtl_str_shortenedCompare_WithLength( + pData->buffer + fromIndex, pData->length - fromIndex, + str, strLength, strLength) == 0; + } + /** Match against a substring appearing in this string, ignoring the case of ASCII letters. @@ -495,6 +520,39 @@ public: str.pData->length ) == 0; } + /** + Check whether this string ends with a given substring. + + @param str the substring to be compared + + @return true if and only if the given str appears as a substring at the + end of this string + + @since LibreOffice 3.6 + */ + bool endsWith(rtl::OString const & str) const { + return str.getLength() <= getLength() + && match(str, getLength() - str.getLength()); + } + + /** + Check whether this string ends with a given substring. + + @param str the substring to be compared; must not be null and must point + to memory of at least strLength bytes + + @param strLength the length of the substring; must be non-negative + + @return true if and only if the given str appears as a substring at the + end of this string + + @since LibreOffice 3.6 + */ + bool endsWithL(char const * str, sal_Int32 strLength) const { + return strLength <= getLength() + && matchL(str, strLength, getLength() - strLength); + } + friend sal_Bool operator == ( const OString& rStr1, const OString& rStr2 ) SAL_THROW(()) { return rStr1.getLength() == rStr2.getLength() && rStr1.compareTo( rStr2 ) == 0; } friend sal_Bool operator == ( const OString& rStr1, const sal_Char * pStr2 ) SAL_THROW(()) @@ -602,6 +660,32 @@ public: return (ret < 0 ? ret : ret+fromIndex); } + /** + Returns the index within this string of the first occurrence of the + specified substring, starting at the specified index. + + If str doesn't include any character, always -1 is + returned. This is also the case, if both strings are empty. + + @param str the substring to search for. + @param len the length of the substring. + @param fromIndex the index to start the search from. + @return If the string argument occurs one or more times as a substring + within this string at the starting index, then the index + of the first character of the first such substring is + returned. If it does not occur as a substring starting + at fromIndex or beyond, -1 is returned. + + @since LibreOffice 3.6 + */ + sal_Int32 indexOfL(char const * str, sal_Int32 len, sal_Int32 fromIndex = 0) + const SAL_THROW(()) + { + sal_Int32 n = rtl_str_indexOfStr_WithLength( + pData->buffer + fromIndex, pData->length - fromIndex, str, len); + return n < 0 ? n : n + fromIndex; + } + /** Returns the index within this string of the last occurrence of the specified substring, searching backward starting at the end. @@ -753,6 +837,56 @@ public: return OString( pNew, (DO_NOT_ACQUIRE*)0 ); } + /** + Returns a new string resulting from replacing the first occurrence of a + given substring with another substring. + + @param from the substring to be replaced + + @param to the replacing substring + + @param[in,out] index pointer to a start index; if the pointer is + non-null: upon entry to the function, its value is the index into the this + string at which to start searching for the \p from substring, the value + must be non-negative and not greater than this string's length; upon exit + from the function its value is the index into this string at which the + replacement took place or -1 if no replacement took place; if the pointer + is null, searching always starts at index 0 + + @since LibreOffice 3.6 + */ + OString replaceFirst( + OString const & from, OString const & to, sal_Int32 * index = 0) const + { + rtl_String * s = 0; + sal_Int32 i = 0; + rtl_string_newReplaceFirst( + &s, pData, from.pData->buffer, from.pData->length, + to.pData->buffer, to.pData->length, index == 0 ? &i : index); + return OString(s, SAL_NO_ACQUIRE); + } + + /** + Returns a new string resulting from replacing all occurrences of a given + substring with another substring. + + Replacing subsequent occurrences picks up only after a given replacement. + That is, replacing from "xa" to "xx" in "xaa" results in "xxa", not "xxx". + + @param from the substring to be replaced + + @param to the replacing substring + + @since LibreOffice 3.6 + */ + OString replaceAll(OString const & from, OString const & to) const { + rtl_String * s = 0; + rtl_string_newReplaceAll( + &s, pData, from.pData->buffer, from.pData->length, + to.pData->buffer, to.pData->length); + return OString(s, SAL_NO_ACQUIRE); + } + /** Converts from this string all ASCII uppercase characters (65-90) to ASCII lowercase characters (97-122). @@ -836,6 +970,24 @@ public: return OString( pNew, (DO_NOT_ACQUIRE *)0 ); } + /** + Returns a token from the string. + + The same as getToken(sal_Int32, sal_Char, sal_Int32 &), but always passing + in 0 as the start index in the third argument. + + @param count the number of the token to return, starting with 0 + @param separator the character which separates the tokens + + @return the given token, or an empty string + + @since LibreOffice 3.6 + */ + OString getToken(sal_Int32 count, char separator) const { + sal_Int32 n = 0; + return getToken(count, separator, n); + } + /** Returns the Boolean value from this string. diff --git a/sal/inc/rtl/ustring.h b/sal/inc/rtl/ustring.h index e75185bd00a0..03f145ba6ba4 100644 --- a/sal/inc/rtl/ustring.h +++ b/sal/inc/rtl/ustring.h @@ -1384,6 +1384,165 @@ SAL_DLLPUBLIC void SAL_CALL rtl_uString_newReplaceStrAt( SAL_DLLPUBLIC void SAL_CALL rtl_uString_newReplace( rtl_uString ** newStr, rtl_uString * str, sal_Unicode oldChar, sal_Unicode newChar ) SAL_THROW_EXTERN_C(); +/** Create a new string by replacing the first occurrence of a given substring + with another substring. + + @param[in, out] newStr pointer to the new string; must not be null; must + point to null or a valid rtl_uString + + @param str pointer to the original string; must not be null + + @param from pointer to the substring to be replaced; must not be null + + @param to pointer to the replacing substring; must not be null + + @param[in,out] index pointer to a start index, must not be null; upon entry + to the function its value is the index into the original string at which to + start searching for the \p from substring, the value must be non-negative + and not greater than the original string's length; upon exit from the + function its value is the index into the original string at which the + replacement took place or -1 if no replacement took place + + @since LibreOffice 3.6 +*/ +SAL_DLLPUBLIC void SAL_CALL rtl_uString_newReplaceFirst( + rtl_uString ** newStr, rtl_uString * str, rtl_uString const * from, + rtl_uString const * to, sal_Int32 * index) SAL_THROW_EXTERN_C(); + +/** Create a new string by replacing the first occurrence of a given substring + with another substring. + + @param[in, out] newStr pointer to the new string; must not be null; must + point to null or a valid rtl_uString + + @param str pointer to the original string; must not be null + + @param from pointer to the substring to be replaced; must not be null and + must point to memory of at least \p fromLength ASCII bytes + + @param fromLength the length of the \p from substring; must be non-negative + + @param to pointer to the replacing substring; must not be null + + @param[in,out] index pointer to a start index, must not be null; upon entry + to the function its value is the index into the original string at which to + start searching for the \p from substring, the value must be non-negative + and not greater than the original string's length; upon exit from the + function its value is the index into the original string at which the + replacement took place or -1 if no replacement took place + + @since LibreOffice 3.6 +*/ +SAL_DLLPUBLIC void SAL_CALL rtl_uString_newReplaceFirstAsciiL( + rtl_uString ** newStr, rtl_uString * str, char const * from, + sal_Int32 fromLength, rtl_uString const * to, sal_Int32 * index) + SAL_THROW_EXTERN_C(); + +/** Create a new string by replacing the first occurrence of a given substring + with another substring. + + @param[in, out] newStr pointer to the new string; must not be null; must + point to null or a valid rtl_uString + + @param str pointer to the original string; must not be null + + @param from pointer to the substring to be replaced; must not be null and + must point to memory of at least \p fromLength ASCII bytes + + @param fromLength the length of the \p from substring; must be non-negative + + @param to pointer to the substring to be replaced; must not be null and + must point to memory of at least \p toLength ASCII bytes + + @param toLength the length of the \p to substring; must be non-negative + + @param[in,out] index pointer to a start index, must not be null; upon entry + to the function its value is the index into the original string at which to + start searching for the \p from substring, the value must be non-negative + and not greater than the original string's length; upon exit from the + function its value is the index into the original string at which the + replacement took place or -1 if no replacement took place + + @since LibreOffice 3.6 +*/ +SAL_DLLPUBLIC void SAL_CALL rtl_uString_newReplaceFirstAsciiLAsciiL( + rtl_uString ** newStr, rtl_uString * str, char const * from, + sal_Int32 fromLength, char const * to, sal_Int32 toLength, + sal_Int32 * index) SAL_THROW_EXTERN_C(); + +/** Create a new string by replacing all occurrences of a given substring with + another substring. + + Replacing subsequent occurrences picks up only after a given replacement. + That is, replacing from "xa" to "xx" in "xaa" results in "xxa", not "xxx". + + @param[in, out] newStr pointer to the new string; must not be null; must + point to null or a valid rtl_uString + + @param str pointer to the original string; must not be null + + @param from pointer to the substring to be replaced; must not be null + + @param to pointer to the replacing substring; must not be null + + @since LibreOffice 3.6 +*/ +SAL_DLLPUBLIC void SAL_CALL rtl_uString_newReplaceAll( + rtl_uString ** newStr, rtl_uString * str, rtl_uString const * from, + rtl_uString const * to) SAL_THROW_EXTERN_C(); + +/** Create a new string by replacing all occurrences of a given substring with + another substring. + + Replacing subsequent occurrences picks up only after a given replacement. + That is, replacing from "xa" to "xx" in "xaa" results in "xxa", not "xxx". + + @param[in, out] newStr pointer to the new string; must not be null; must + point to null or a valid rtl_uString + + @param str pointer to the original string; must not be null + + @param from pointer to the substring to be replaced; must not be null and + must point to memory of at least \p fromLength ASCII bytes + + @param fromLength the length of the \p from substring; must be non-negative + + @param to pointer to the replacing substring; must not be null + + @since LibreOffice 3.6 +*/ +SAL_DLLPUBLIC void SAL_CALL rtl_uString_newReplaceAllAsciiL( + rtl_uString ** newStr, rtl_uString * str, char const * from, + sal_Int32 fromLength, rtl_uString const * to) SAL_THROW_EXTERN_C(); + +/** Create a new string by replacing all occurrences of a given substring with + another substring. + + Replacing subsequent occurrences picks up only after a given replacement. + That is, replacing from "xa" to "xx" in "xaa" results in "xxa", not "xxx". + + @param[in, out] newStr pointer to the new string; must not be null; must + point to null or a valid rtl_uString + + @param str pointer to the original string; must not be null + + @param from pointer to the substring to be replaced; must not be null and + must point to memory of at least \p fromLength ASCII bytes + + @param fromLength the length of the \p from substring; must be non-negative + + @param to pointer to the substring to be replaced; must not be null and + must point to memory of at least \p toLength ASCII bytes + + @param toLength the length of the \p to substring; must be non-negative + + @since LibreOffice 3.6 +*/ +SAL_DLLPUBLIC void SAL_CALL rtl_uString_newReplaceAllAsciiLAsciiL( + rtl_uString ** newStr, rtl_uString * str, char const * from, + sal_Int32 fromLength, char const * to, sal_Int32 toLength) + SAL_THROW_EXTERN_C(); + /** Create a new string by converting all ASCII uppercase letters to lowercase within another string. diff --git a/sal/inc/rtl/ustring.hxx b/sal/inc/rtl/ustring.hxx index ace4b1ae7179..cf1ec92df360 100644 --- a/sal/inc/rtl/ustring.hxx +++ b/sal/inc/rtl/ustring.hxx @@ -711,6 +711,21 @@ public: asciiStr, asciiStrLength ) == 0; } + /** + Check whether this string ends with a given substring. + + @param str the substring to be compared + + @return true if and only if the given str appears as a substring at the + end of this string + + @since LibreOffice 3.6 + */ + bool endsWith(rtl::OUString const & str) const { + return str.getLength() <= getLength() + && match(str, getLength() - str.getLength()); + } + /** Check whether this string ends with a given ASCII string. @@ -1066,6 +1081,177 @@ public: return OUString( pNew, (DO_NOT_ACQUIRE*)0 ); } + /** + Returns a new string resulting from replacing the first occurrence of a + given substring with another substring. + + @param from the substring to be replaced + + @param to the replacing substring + + @param[in,out] index pointer to a start index; if the pointer is + non-null: upon entry to the function, its value is the index into the this + string at which to start searching for the \p from substring, the value + must be non-negative and not greater than this string's length; upon exit + from the function its value is the index into this string at which the + replacement took place or -1 if no replacement took place; if the pointer + is null, searching always starts at index 0 + + @since LibreOffice 3.6 + */ + OUString replaceFirst( + OUString const & from, OUString const & to, sal_Int32 * index = 0) const + { + rtl_uString * s = 0; + sal_Int32 i = 0; + rtl_uString_newReplaceFirst( + &s, pData, from.pData, to.pData, index == 0 ? &i : index); + return OUString(s, SAL_NO_ACQUIRE); + } + + /** + Returns a new string resulting from replacing the first occurrence of a + given substring with another substring. + + @param from pointer to the substring to be replaced; must not be null and + must point to memory of at least \p fromLength ASCII bytes + + @param fromLength the length of the \p from substring; must be + non-negative + + @param to the replacing substring + + @param[in,out] index pointer to a start index; if the pointer is + non-null: upon entry to the function, its value is the index into the this + string at which to start searching for the \p from substring, the value + must be non-negative and not greater than this string's length; upon exit + from the function its value is the index into this string at which the + replacement took place or -1 if no replacement took place; if the pointer + is null, searching always starts at index 0 + + @since LibreOffice 3.6 + */ + OUString replaceFirstAsciiL( + char const * from, sal_Int32 fromLength, rtl::OUString const & to, + sal_Int32 * index = 0) const + { + rtl_uString * s = 0; + sal_Int32 i = 0; + rtl_uString_newReplaceFirstAsciiL( + &s, pData, from, fromLength, to.pData, index == 0 ? &i : index); + return OUString(s, SAL_NO_ACQUIRE); + } + + /** + Returns a new string resulting from replacing the first occurrence of a + given substring with another substring. + + @param from pointer to the substring to be replaced; must not be null and + must point to memory of at least \p fromLength ASCII bytes + + @param fromLength the length of the \p from substring; must be + non-negative + + @param to pointer to the substring to be replaced; must not be null and + must point to memory of at least \p toLength ASCII bytes + + @param toLength the length of the \p to substring; must be non-negative + + @param[in,out] index pointer to a start index; if the pointer is + non-null: upon entry to the function, its value is the index into the this + string at which to start searching for the \p from substring, the value + must be non-negative and not greater than this string's length; upon exit + from the function its value is the index into this string at which the + replacement took place or -1 if no replacement took place; if the pointer + is null, searching always starts at index 0 + + @since LibreOffice 3.6 + */ + OUString replaceFirstAsciiLAsciiL( + char const * from, sal_Int32 fromLength, char const * to, + sal_Int32 toLength, sal_Int32 * index = 0) const + { + rtl_uString * s = 0; + sal_Int32 i = 0; + rtl_uString_newReplaceFirstAsciiLAsciiL( + &s, pData, from, fromLength, to, toLength, index == 0 ? &i : index); + return OUString(s, SAL_NO_ACQUIRE); + } + + /** + Returns a new string resulting from replacing all occurrences of a given + substring with another substring. + + Replacing subsequent occurrences picks up only after a given replacement. + That is, replacing from "xa" to "xx" in "xaa" results in "xxa", not "xxx". + + @param from the substring to be replaced + + @param to the replacing substring + + @since LibreOffice 3.6 + */ + OUString replaceAll(OUString const & from, OUString const & to) const { + rtl_uString * s = 0; + rtl_uString_newReplaceAll(&s, pData, from.pData, to.pData); + return OUString(s, SAL_NO_ACQUIRE); + } + + /** + Returns a new string resulting from replacing all occurrences of a given + substring with another substring. + + Replacing subsequent occurrences picks up only after a given replacement. + That is, replacing from "xa" to "xx" in "xaa" results in "xxa", not "xxx". + + @param from pointer to the substring to be replaced; must not be null and + must point to memory of at least \p fromLength ASCII bytes + + @param fromLength the length of the \p from substring; must be + non-negative + + @param to the replacing substring + + @since LibreOffice 3.6 + */ + OUString replaceAllAsciiL( + char const * from, sal_Int32 fromLength, OUString const & to) const + { + rtl_uString * s = 0; + rtl_uString_newReplaceAllAsciiL(&s, pData, from, fromLength, to.pData); + return OUString(s, SAL_NO_ACQUIRE); + } + + /** + Returns a new string resulting from replacing all occurrences of a given + substring with another substring. + + Replacing subsequent occurrences picks up only after a given replacement. + That is, replacing from "xa" to "xx" in "xaa" results in "xxa", not "xxx". + + @param from pointer to the substring to be replaced; must not be null and + must point to memory of at least \p fromLength ASCII bytes + + @param fromLength the length of the \p from substring; must be + non-negative + + @param to pointer to the substring to be replaced; must not be null and + must point to memory of at least \p toLength ASCII bytes + + @param toLength the length of the \p to substring; must be non-negative + + @since LibreOffice 3.6 + */ + OUString replaceAllAsciiLAsciiL( + char const * from, sal_Int32 fromLength, char const * to, + sal_Int32 toLength) const + { + rtl_uString * s = 0; + rtl_uString_newReplaceAllAsciiLAsciiL( + &s, pData, from, fromLength, to, toLength); + return OUString(s, SAL_NO_ACQUIRE); + } + /** Converts from this string all ASCII uppercase characters (65-90) to ASCII lowercase characters (97-122). @@ -1149,6 +1335,24 @@ public: return OUString( pNew, (DO_NOT_ACQUIRE *)0 ); } + /** + Returns a token from the string. + + The same as getToken(sal_Int32, sal_Unicode, sal_Int32 &), but always + passing in 0 as the start index in the third argument. + + @param count the number of the token to return, starting with 0 + @param separator the character which separates the tokens + + @return the given token, or an empty string + + @since LibreOffice 3.6 + */ + OUString getToken(sal_Int32 count, sal_Unicode separator) const { + sal_Int32 n = 0; + return getToken(count, separator, n); + } + /** Returns the Boolean value from this string. diff --git a/sal/qa/rtl/strings/test_strings_replace.cxx b/sal/qa/rtl/strings/test_strings_replace.cxx new file mode 100644 index 000000000000..33638899a4ab --- /dev/null +++ b/sal/qa/rtl/strings/test_strings_replace.cxx @@ -0,0 +1,349 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * Version: MPL 1.1 / GPLv3+ / LGPLv3+ + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License or as specified alternatively below. You may obtain a copy of + * the License at http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * Major Contributor(s): + * [ Copyright (C) 2012 Red Hat, Inc., Stephan Bergmann + * (initial developer) ] + * + * All Rights Reserved. + * + * For minor contributions see the git repository. + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 3 or later (the "GPLv3+"), or + * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"), + * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable + * instead of those above. + */ + +#include "sal/config.h" +#include "sal/precppunit.hxx" + +#include + +#include "cppunit/TestAssert.h" +#include "cppunit/TestFixture.h" +#include "cppunit/extensions/HelperMacros.h" +#include "rtl/oustringostreaminserter.hxx" +#include "rtl/string.h" +#include "rtl/string.hxx" +#include "rtl/ustring.h" +#include "rtl/ustring.hxx" + +namespace rtl { + +template< typename charT, typename traits > std::basic_ostream & +operator <<( + std::basic_ostream & stream, rtl::OString const & string) +{ + return stream << string.getStr(); + // best effort; potentially loses data due to embedded null characters +} + +} + +namespace { + +class Test: public CppUnit::TestFixture { +private: + void stringReplaceFirst(); + + void stringReplaceAll(); + + void ustringReplaceFirst(); + + void ustringReplaceFirstAsciiL(); + + void ustringReplaceFirstAsciiLAsciiL(); + + void ustringReplaceAll(); + + void ustringReplaceAllAsciiL(); + + void ustringReplaceAllAsciiLAsciiL(); + + CPPUNIT_TEST_SUITE(Test); + CPPUNIT_TEST(stringReplaceFirst); + CPPUNIT_TEST(stringReplaceAll); + CPPUNIT_TEST(ustringReplaceFirst); + CPPUNIT_TEST(ustringReplaceFirstAsciiL); + CPPUNIT_TEST(ustringReplaceFirstAsciiLAsciiL); + CPPUNIT_TEST(ustringReplaceAll); + CPPUNIT_TEST(ustringReplaceAllAsciiL); + CPPUNIT_TEST(ustringReplaceAllAsciiLAsciiL); + CPPUNIT_TEST_SUITE_END(); +}; + +void Test::stringReplaceFirst() { + CPPUNIT_ASSERT_EQUAL( + rtl::OString("otherbarfoo"), + rtl::OString("foobarfoo").replaceFirst("foo", "other")); + + CPPUNIT_ASSERT_EQUAL( + rtl::OString("foobarfoo"), + rtl::OString("foobarfoo").replaceFirst("bars", "other")); + + { + sal_Int32 n = 0; + CPPUNIT_ASSERT_EQUAL( + rtl::OString("otherbarfoo"), + rtl::OString("foobarfoo").replaceFirst("foo", "other", &n)); + CPPUNIT_ASSERT_EQUAL(sal_Int32(0), n); + } + + { + sal_Int32 n = 1; + CPPUNIT_ASSERT_EQUAL( + rtl::OString("foobarother"), + rtl::OString("foobarfoo").replaceFirst("foo", "other", &n)); + CPPUNIT_ASSERT_EQUAL(sal_Int32(6), n); + } + + { + sal_Int32 n = 4; + CPPUNIT_ASSERT_EQUAL( + rtl::OString("foobarfoo"), + rtl::OString("foobarfoo").replaceFirst("bar", "other", &n)); + CPPUNIT_ASSERT_EQUAL(sal_Int32(-1), n); + } +} + +void Test::stringReplaceAll() { + CPPUNIT_ASSERT_EQUAL( + rtl::OString("otherbarother"), + rtl::OString("foobarfoo").replaceAll("foo", "other")); + + CPPUNIT_ASSERT_EQUAL( + rtl::OString("foobarfoo"), + rtl::OString("foobarfoo").replaceAll("bars", "other")); + + CPPUNIT_ASSERT_EQUAL( + rtl::OString("xxa"), rtl::OString("xaa").replaceAll("xa", "xx")); +} + +void Test::ustringReplaceFirst() { + CPPUNIT_ASSERT_EQUAL( + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("otherbarfoo")), + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("foobarfoo")).replaceFirst( + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("foo")), + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("other")))); + + CPPUNIT_ASSERT_EQUAL( + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("foobarfoo")), + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("foobarfoo")).replaceFirst( + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("bars")), + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("other")))); + + { + sal_Int32 n = 0; + CPPUNIT_ASSERT_EQUAL( + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("otherbarfoo")), + (rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("foobarfoo")). + replaceFirst( + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("foo")), + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("other")), &n))); + CPPUNIT_ASSERT_EQUAL(sal_Int32(0), n); + } + + { + sal_Int32 n = 1; + CPPUNIT_ASSERT_EQUAL( + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("foobarother")), + (rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("foobarfoo")). + replaceFirst( + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("foo")), + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("other")), &n))); + CPPUNIT_ASSERT_EQUAL(sal_Int32(6), n); + } + + { + sal_Int32 n = 4; + CPPUNIT_ASSERT_EQUAL( + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("foobarfoo")), + (rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("foobarfoo")). + replaceFirst( + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("bar")), + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("other")), &n))); + CPPUNIT_ASSERT_EQUAL(sal_Int32(-1), n); + } +} + +void Test::ustringReplaceFirstAsciiL() { + CPPUNIT_ASSERT_EQUAL( + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("otherbarfoo")), + (rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("foobarfoo")). + replaceFirstAsciiL( + RTL_CONSTASCII_STRINGPARAM("foo"), + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("other"))))); + + CPPUNIT_ASSERT_EQUAL( + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("foobarfoo")), + (rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("foobarfoo")). + replaceFirstAsciiL( + RTL_CONSTASCII_STRINGPARAM("bars"), + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("other"))))); + + { + sal_Int32 n = 0; + CPPUNIT_ASSERT_EQUAL( + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("otherbarfoo")), + (rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("foobarfoo")). + replaceFirstAsciiL( + RTL_CONSTASCII_STRINGPARAM("foo"), + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("other")), &n))); + CPPUNIT_ASSERT_EQUAL(sal_Int32(0), n); + } + + { + sal_Int32 n = 1; + CPPUNIT_ASSERT_EQUAL( + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("foobarother")), + (rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("foobarfoo")). + replaceFirstAsciiL( + RTL_CONSTASCII_STRINGPARAM("foo"), + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("other")), &n))); + CPPUNIT_ASSERT_EQUAL(sal_Int32(6), n); + } + + { + sal_Int32 n = 4; + CPPUNIT_ASSERT_EQUAL( + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("foobarfoo")), + (rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("foobarfoo")). + replaceFirstAsciiL( + RTL_CONSTASCII_STRINGPARAM("bar"), + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("other")), &n))); + CPPUNIT_ASSERT_EQUAL(sal_Int32(-1), n); + } +} + +void Test::ustringReplaceFirstAsciiLAsciiL() { + CPPUNIT_ASSERT_EQUAL( + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("otherbarfoo")), + (rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("foobarfoo")). + replaceFirstAsciiLAsciiL( + RTL_CONSTASCII_STRINGPARAM("foo"), + RTL_CONSTASCII_STRINGPARAM("other")))); + + CPPUNIT_ASSERT_EQUAL( + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("foobarfoo")), + (rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("foobarfoo")). + replaceFirstAsciiLAsciiL( + RTL_CONSTASCII_STRINGPARAM("bars"), + RTL_CONSTASCII_STRINGPARAM("other")))); + + { + sal_Int32 n = 0; + CPPUNIT_ASSERT_EQUAL( + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("otherbarfoo")), + (rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("foobarfoo")). + replaceFirstAsciiLAsciiL( + RTL_CONSTASCII_STRINGPARAM("foo"), + RTL_CONSTASCII_STRINGPARAM("other"), &n))); + CPPUNIT_ASSERT_EQUAL(sal_Int32(0), n); + } + + { + sal_Int32 n = 1; + CPPUNIT_ASSERT_EQUAL( + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("foobarother")), + (rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("foobarfoo")). + replaceFirstAsciiLAsciiL( + RTL_CONSTASCII_STRINGPARAM("foo"), + RTL_CONSTASCII_STRINGPARAM("other"), &n))); + CPPUNIT_ASSERT_EQUAL(sal_Int32(6), n); + } + + { + sal_Int32 n = 4; + CPPUNIT_ASSERT_EQUAL( + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("foobarfoo")), + (rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("foobarfoo")). + replaceFirstAsciiLAsciiL( + RTL_CONSTASCII_STRINGPARAM("bar"), + RTL_CONSTASCII_STRINGPARAM("other"), &n))); + CPPUNIT_ASSERT_EQUAL(sal_Int32(-1), n); + } +} + +void Test::ustringReplaceAll() { + CPPUNIT_ASSERT_EQUAL( + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("otherbarother")), + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("foobarfoo")).replaceAll( + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("foo")), + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("other")))); + + CPPUNIT_ASSERT_EQUAL( + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("foobarfoo")), + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("foobarfoo")).replaceAll( + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("bars")), + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("other")))); + + CPPUNIT_ASSERT_EQUAL( + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("xxa")), + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("xaa")).replaceAll( + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("xa")), + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("xx")))); +} + +void Test::ustringReplaceAllAsciiL() { + CPPUNIT_ASSERT_EQUAL( + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("otherbarother")), + (rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("foobarfoo")). + replaceAllAsciiL( + RTL_CONSTASCII_STRINGPARAM("foo"), + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("other"))))); + + CPPUNIT_ASSERT_EQUAL( + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("foobarfoo")), + (rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("foobarfoo")). + replaceAllAsciiL( + RTL_CONSTASCII_STRINGPARAM("bars"), + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("other"))))); + + CPPUNIT_ASSERT_EQUAL( + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("xxa")), + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("xaa")).replaceAllAsciiL( + RTL_CONSTASCII_STRINGPARAM("xa"), + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("xx")))); +} + +void Test::ustringReplaceAllAsciiLAsciiL() { + CPPUNIT_ASSERT_EQUAL( + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("otherbarother")), + (rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("foobarfoo")). + replaceAllAsciiLAsciiL( + RTL_CONSTASCII_STRINGPARAM("foo"), + RTL_CONSTASCII_STRINGPARAM("other")))); + + CPPUNIT_ASSERT_EQUAL( + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("foobarfoo")), + (rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("foobarfoo")). + replaceAllAsciiLAsciiL( + RTL_CONSTASCII_STRINGPARAM("bars"), + RTL_CONSTASCII_STRINGPARAM("other")))); + + CPPUNIT_ASSERT_EQUAL( + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("xxa")), + (rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("xaa")). + replaceAllAsciiLAsciiL( + RTL_CONSTASCII_STRINGPARAM("xa"), + RTL_CONSTASCII_STRINGPARAM("xx")))); +} + +} + +CPPUNIT_TEST_SUITE_REGISTRATION(Test); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sal/rtl/source/string.cxx b/sal/rtl/source/string.cxx index c43b564a2099..9c5393f32779 100644 --- a/sal/rtl/source/string.cxx +++ b/sal/rtl/source/string.cxx @@ -25,10 +25,16 @@ * for a copy of the LGPLv3 License. * ************************************************************************/ + +#include "sal/config.h" + #if defined(_MSC_VER) && (_MSC_VER >= 1400) #pragma warning(disable:4738) // storing 32-bit float result in memory, possible loss of performance #endif +#include +#include + #include #include #include @@ -324,4 +330,57 @@ sal_Bool SAL_CALL rtl_convertUStringToString(rtl_String ** pTarget, nFlags, sal_True); } +void rtl_string_newReplaceFirst( + rtl_String ** newStr, rtl_String * str, char const * from, + sal_Int32 fromLength, char const * to, sal_Int32 toLength, + sal_Int32 * index) SAL_THROW_EXTERN_C() +{ + assert(str != 0); + assert(index != 0); + assert(*index >= 0 && *index <= str->length); + assert(fromLength >= 0); + assert(toLength >= 0); + sal_Int32 i = rtl_str_indexOfStr_WithLength( + str->buffer + *index, str->length - *index, from, fromLength); + if (i == -1) { + rtl_string_assign(newStr, str); + } else { + assert(i <= str->length - *index); + i += *index; + assert(fromLength <= str->length); + if (str->length - fromLength > SAL_MAX_INT32 - toLength) { + std::abort(); + } + sal_Int32 n = str->length - fromLength + toLength; + rtl_string_acquire(str); // in case *newStr == str + rtl_string_new_WithLength(newStr, n); + if (n != 0) { + (*newStr)->length = n; + assert(i >= 0 && i < str->length); + rtl_copyMemory((*newStr)->buffer, str->buffer, i); + rtl_copyMemory((*newStr)->buffer + i, to, toLength); + rtl_copyMemory( + (*newStr)->buffer + i + toLength, str->buffer + i + fromLength, + str->length - i - fromLength); + } + rtl_string_release(str); + } + *index = i; +} + +void rtl_string_newReplaceAll( + rtl_String ** newStr, rtl_String * str, char const * from, + sal_Int32 fromLength, char const * to, sal_Int32 toLength) + SAL_THROW_EXTERN_C() +{ + rtl_string_assign(newStr, str); + for (sal_Int32 i = 0;; i += toLength) { + rtl_string_newReplaceFirst( + newStr, *newStr, from, fromLength, to, toLength, &i); + if (i == -1) { + break; + } + } +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sal/rtl/source/ustring.cxx b/sal/rtl/source/ustring.cxx index a37353c99161..0156ceae9a08 100644 --- a/sal/rtl/source/ustring.cxx +++ b/sal/rtl/source/ustring.cxx @@ -25,10 +25,16 @@ * for a copy of the LGPLv3 License. * ************************************************************************/ + +#include "sal/config.h" + #if defined(_MSC_VER) && (_MSC_VER >= 1400) #pragma warning(disable:4738) // storing 32-bit float result in memory, possible loss of performance #endif +#include +#include + #include #include #include @@ -994,4 +1000,176 @@ sal_Bool rtl_convertStringToUString( return (sal_Bool) ((info & RTL_TEXTTOUNICODE_INFO_ERROR) == 0); } +void rtl_uString_newReplaceFirst( + rtl_uString ** newStr, rtl_uString * str, rtl_uString const * from, + rtl_uString const * to, sal_Int32 * index) SAL_THROW_EXTERN_C() +{ + assert(str != 0); + assert(index != 0); + assert(*index >= 0 && *index <= str->length); + assert(from != 0); + assert(to != 0); + sal_Int32 i = rtl_ustr_indexOfStr_WithLength( + str->buffer + *index, str->length - *index, from->buffer, from->length); + if (i == -1) { + rtl_uString_assign(newStr, str); + } else { + assert(i <= str->length - *index); + i += *index; + assert(from->length <= str->length); + if (str->length - from->length > SAL_MAX_INT32 - to->length) { + std::abort(); + } + sal_Int32 n = str->length - from->length + to->length; + rtl_uString_acquire(str); // in case *newStr == str + rtl_uString_new_WithLength(newStr, n); + if (n != 0) { + (*newStr)->length = n; + assert(i >= 0 && i < str->length); + rtl_copyMemory( + (*newStr)->buffer, str->buffer, i * sizeof (sal_Unicode)); + rtl_copyMemory( + (*newStr)->buffer + i, to->buffer, + to->length * sizeof (sal_Unicode)); + rtl_copyMemory( + (*newStr)->buffer + i + to->length, + str->buffer + i + from->length, + (str->length - i - from->length) * sizeof (sal_Unicode)); + } + rtl_uString_release(str); + } + *index = i; +} + +void rtl_uString_newReplaceFirstAsciiL( + rtl_uString ** newStr, rtl_uString * str, char const * from, + sal_Int32 fromLength, rtl_uString const * to, sal_Int32 * index) + SAL_THROW_EXTERN_C() +{ + assert(str != 0); + assert(index != 0); + assert(*index >= 0 && *index <= str->length); + assert(fromLength >= 0); + assert(to != 0); + sal_Int32 i = rtl_ustr_indexOfAscii_WithLength( + str->buffer + *index, str->length - *index, from, fromLength); + if (i == -1) { + rtl_uString_assign(newStr, str); + } else { + assert(i <= str->length - *index); + i += *index; + assert(fromLength <= str->length); + if (str->length - fromLength > SAL_MAX_INT32 - to->length) { + std::abort(); + } + sal_Int32 n = str->length - fromLength + to->length; + rtl_uString_acquire(str); // in case *newStr == str + if (n != 0) { + rtl_uString_new_WithLength(newStr, n); + (*newStr)->length = n; + assert(i >= 0 && i < str->length); + rtl_copyMemory( + (*newStr)->buffer, str->buffer, i * sizeof (sal_Unicode)); + rtl_copyMemory( + (*newStr)->buffer + i, to->buffer, + to->length * sizeof (sal_Unicode)); + rtl_copyMemory( + (*newStr)->buffer + i + to->length, + str->buffer + i + fromLength, + (str->length - i - fromLength) * sizeof (sal_Unicode)); + } + rtl_uString_release(str); + } + *index = i; +} + +void rtl_uString_newReplaceFirstAsciiLAsciiL( + rtl_uString ** newStr, rtl_uString * str, char const * from, + sal_Int32 fromLength, char const * to, sal_Int32 toLength, + sal_Int32 * index) SAL_THROW_EXTERN_C() +{ + assert(str != 0); + assert(index != 0); + assert(*index >= 0 && *index <= str->length); + assert(fromLength >= 0); + assert(to != 0); + assert(toLength >= 0); + sal_Int32 i = rtl_ustr_indexOfAscii_WithLength( + str->buffer + *index, str->length - *index, from, fromLength); + if (i == -1) { + rtl_uString_assign(newStr, str); + } else { + assert(i <= str->length - *index); + i += *index; + assert(fromLength <= str->length); + if (str->length - fromLength > SAL_MAX_INT32 - toLength) { + std::abort(); + } + sal_Int32 n = str->length - fromLength + toLength; + rtl_uString_acquire(str); // in case *newStr == str + if (n != 0) { + rtl_uString_new_WithLength(newStr, n); + (*newStr)->length = n; + assert(i >= 0 && i < str->length); + rtl_copyMemory( + (*newStr)->buffer, str->buffer, i * sizeof (sal_Unicode)); + for (sal_Int32 j = 0; j != toLength; ++j) { + assert(static_cast< unsigned char >(to[j]) <= 0x7F); + (*newStr)->buffer[i + j] = to[j]; + } + rtl_copyMemory( + (*newStr)->buffer + i + toLength, + str->buffer + i + fromLength, + (str->length - i - fromLength) * sizeof (sal_Unicode)); + } + rtl_uString_release(str); + } + *index = i; +} + +void rtl_uString_newReplaceAll( + rtl_uString ** newStr, rtl_uString * str, rtl_uString const * from, + rtl_uString const * to) SAL_THROW_EXTERN_C() +{ + assert(to != 0); + rtl_uString_assign(newStr, str); + for (sal_Int32 i = 0;; i += to->length) { + rtl_uString_newReplaceFirst(newStr, *newStr, from, to, &i); + if (i == -1) { + break; + } + } +} + +void rtl_uString_newReplaceAllAsciiL( + rtl_uString ** newStr, rtl_uString * str, char const * from, + sal_Int32 fromLength, rtl_uString const * to) SAL_THROW_EXTERN_C() +{ + assert(to != 0); + rtl_uString_assign(newStr, str); + for (sal_Int32 i = 0;; i += to->length) { + rtl_uString_newReplaceFirstAsciiL( + newStr, *newStr, from, fromLength, to, &i); + if (i == -1) { + break; + } + } +} + +void rtl_uString_newReplaceAllAsciiLAsciiL( + rtl_uString ** newStr, rtl_uString * str, char const * from, + sal_Int32 fromLength, char const * to, sal_Int32 toLength) + SAL_THROW_EXTERN_C() +{ + assert(toLength >= 0); + rtl_uString_assign(newStr, str); + for (sal_Int32 i = 0;; i += toLength) { + rtl_uString_newReplaceFirstAsciiLAsciiL( + newStr, *newStr, from, fromLength, to, toLength, &i); + if (i == -1) { + break; + } + } +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sal/util/sal.map b/sal/util/sal.map index 338854dabf3b..d6c3ab1fa842 100644 --- a/sal/util/sal.map +++ b/sal/util/sal.map @@ -612,6 +612,14 @@ LIBO_UDK_3.6 { # symbols available in >= LibO 3.6 global: osl_unmapMappedFile; osl_identicalDirectoryItem; + rtl_string_newReplaceAll; + rtl_string_newReplaceFirst; + rtl_uString_newReplaceAll; + rtl_uString_newReplaceAllAsciiL; + rtl_uString_newReplaceAllAsciiLAsciiL; + rtl_uString_newReplaceFirst; + rtl_uString_newReplaceFirstAsciiL; + rtl_uString_newReplaceFirstAsciiLAsciiL; } UDK_3.10; PRIVATE_1.0 { diff --git a/sc/source/ui/app/inputhdl.cxx b/sc/source/ui/app/inputhdl.cxx index baefc8a33b4f..2fa6ae399b46 100644 --- a/sc/source/ui/app/inputhdl.cxx +++ b/sc/source/ui/app/inputhdl.cxx @@ -2754,25 +2754,33 @@ void ScInputHandler::EnterHandler( sal_uInt8 nBlockMode ) if (aReplace.isEmpty()) aReplace = ScGlobal::pLocaleData->getDoubleQuotationMarkStart(); if (!aReplace.equalsAsciiL("\"", 1)) - aString = comphelper::string::replace(aString, aReplace, rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\""))); + aString = aString.replaceAll( + aReplace, + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\""))); aReplace = rtl::OUString(pAuto->GetEndDoubleQuote()); if (aReplace.isEmpty()) aReplace = ScGlobal::pLocaleData->getDoubleQuotationMarkEnd(); if (!aReplace.equalsAsciiL("\"", 1)) - aString = comphelper::string::replace(aString, aReplace, rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\""))); + aString = aString.replaceAll( + aReplace, + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\""))); aReplace = rtl::OUString(pAuto->GetStartSingleQuote()); if (aReplace.isEmpty()) aReplace = ScGlobal::pLocaleData->getQuotationMarkStart(); if (!aReplace.equalsAsciiL("'", 1)) - aString = comphelper::string::replace(aString, aReplace, rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("'"))); + aString = aString.replaceAll( + aReplace, + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("'"))); aReplace = rtl::OUString(pAuto->GetEndSingleQuote()); if (aReplace.isEmpty()) aReplace = ScGlobal::pLocaleData->getQuotationMarkEnd(); if (!aReplace.equalsAsciiL("'", 1)) - aString = comphelper::string::replace(aString, aReplace, rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("'"))); + aString = aString.replaceAll( + aReplace, + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("'"))); } } diff --git a/sot/source/sdstor/ucbstorage.cxx b/sot/source/sdstor/ucbstorage.cxx index 215c42b76f34..e82d7b3dff32 100644 --- a/sot/source/sdstor/ucbstorage.cxx +++ b/sot/source/sdstor/ucbstorage.cxx @@ -52,8 +52,6 @@ #include #include -#include - #include #include #include @@ -3294,7 +3292,7 @@ String UCBStorage::GetLinkedFile( SvStream &rStream ) if( nBytes == 0x04034b50 ) { rtl::OString aTmp = read_lenPrefixed_uInt8s_ToOString(rStream); - if (comphelper::string::matchL(aTmp, RTL_CONSTASCII_STRINGPARAM("ContentURL="))) + if (aTmp.matchL(RTL_CONSTASCII_STRINGPARAM("ContentURL="))) { aString = rtl::OStringToOUString(aTmp.copy(11), RTL_TEXTENCODING_UTF8); } diff --git a/starmath/source/ooxmlimport.cxx b/starmath/source/ooxmlimport.cxx index a092462a0a85..141a114bc952 100644 --- a/starmath/source/ooxmlimport.cxx +++ b/starmath/source/ooxmlimport.cxx @@ -29,7 +29,6 @@ #include "ooxmlimport.hxx" -#include #include #include #include @@ -85,10 +84,12 @@ OUString SmOoxmlImport::handleStream() stream.ensureClosingTag( M_TOKEN( oMath )); // Placeholders are written out as nothing (i.e. nothing inside e.g. the element), // which will result in "{}" in the formula text. Fix this up. - ret = comphelper::string::searchAndReplaceAllAsciiWithAscii( ret, "{}", "" ); + ret = ret.replaceAllAsciiLAsciiL( + RTL_CONSTASCII_STRINGPARAM("{}"), RTL_CONSTASCII_STRINGPARAM("")); // And as a result, empty parts of the formula that are not placeholders are written out // as a single space, so fix that up too. - ret = comphelper::string::searchAndReplaceAllAsciiWithAscii( ret, "{ }", "{}" ); + ret = ret.replaceAllAsciiLAsciiL( + RTL_CONSTASCII_STRINGPARAM("{ }"), RTL_CONSTASCII_STRINGPARAM("{}")); SAL_INFO( "starmath.ooxml", "Formula: " << ret ); return ret; } diff --git a/svtools/bmpmaker/bmpcore.cxx b/svtools/bmpmaker/bmpcore.cxx index 2a7c709fdb34..c2c954ab7dae 100644 --- a/svtools/bmpmaker/bmpcore.cxx +++ b/svtools/bmpmaker/bmpcore.cxx @@ -364,8 +364,6 @@ void BmpCreator::Create( const String& rSRSName, rtl::OString aByteText; sal_Bool bLangDep = sal_False; - using comphelper::string::indexOfL; - do { do @@ -373,14 +371,14 @@ void BmpCreator::Create( const String& rSRSName, if (!pSRS->ReadLine(aByteText)) break; } - while ( indexOfL(aByteText, RTL_CONSTASCII_STRINGPARAM("ImageList")) == -1 ); + while ( aByteText.indexOfL(RTL_CONSTASCII_STRINGPARAM("ImageList")) == -1 ); do { if (!pSRS->ReadLine( aByteText ) ) break; } - while ( indexOfL(aByteText, RTL_CONSTASCII_STRINGPARAM("File")) == -1 ); + while ( aByteText.indexOfL(RTL_CONSTASCII_STRINGPARAM("File")) == -1 ); aText = rtl::OStringToOUString(aByteText, RTL_TEXTENCODING_ASCII_US); const String aName( aText.GetToken( 1, '"' ) ); @@ -388,7 +386,7 @@ void BmpCreator::Create( const String& rSRSName, do { if( !bLangDep && - indexOfL(aByteText, RTL_CONSTASCII_STRINGPARAM("File")) != -1 && + aByteText.indexOfL(RTL_CONSTASCII_STRINGPARAM("File")) != -1 && aByteText.indexOf('[') != -1 && aByteText.indexOf(']') != -1 ) { @@ -398,7 +396,7 @@ void BmpCreator::Create( const String& rSRSName, if (!pSRS->ReadLine(aByteText)) break; } - while (indexOfL(aByteText, RTL_CONSTASCII_STRINGPARAM("IdList")) == -1); + while (aByteText.indexOfL(RTL_CONSTASCII_STRINGPARAM("IdList")) == -1); aText = rtl::OStringToOUString(aByteText, RTL_TEXTENCODING_ASCII_US); // if image list is not language dependent, don't do anything for languages except german diff --git a/svtools/bmpmaker/bmpsum.cxx b/svtools/bmpmaker/bmpsum.cxx index c57273708503..4fdf1e515275 100644 --- a/svtools/bmpmaker/bmpsum.cxx +++ b/svtools/bmpmaker/bmpsum.cxx @@ -305,7 +305,7 @@ void BmpSum::ProcessFileList( const String& rInFileList, if( !aReadLine.isEmpty() ) aFileNameSet.insert( aReadLine ); - if( comphelper::string::indexOfL(aReadLine, RTL_CONSTASCII_STRINGPARAM("enus") ) != -1 ) + if( aReadLine.indexOfL(RTL_CONSTASCII_STRINGPARAM("enus") ) != -1 ) { static const char* aLanguages[] = { @@ -328,10 +328,10 @@ void BmpSum::ProcessFileList( const String& rInFileList, for( sal_uInt32 n = 0; n < 14; ++n ) { - rtl::OString aLangPath = comphelper::string::replace( - aReadLine, - rtl::OString(RTL_CONSTASCII_STRINGPARAM("enus")), - rtl::OString(aLanguages[n])); + rtl::OString aLangPath( + aReadLine.replaceAll( + rtl::OString(RTL_CONSTASCII_STRINGPARAM("enus")), + rtl::OString(aLanguages[n]))); DirEntry aTestFile( aLangPath ); diff --git a/svtools/source/filter/ixbm/xbmread.cxx b/svtools/source/filter/ixbm/xbmread.cxx index aae46dcc4cfe..e6fc446816c1 100644 --- a/svtools/source/filter/ixbm/xbmread.cxx +++ b/svtools/source/filter/ixbm/xbmread.cxx @@ -317,10 +317,9 @@ ReadState XBMReader::ReadXBM( Graphic& rGraphic ) { XBMFormat eFormat = XBM10; - using comphelper::string::indexOfL; - if (indexOfL(aLine, RTL_CONSTASCII_STRINGPARAM("short")) != -1) + if (aLine.indexOfL(RTL_CONSTASCII_STRINGPARAM("short")) != -1) eFormat = XBM10; - else if (indexOfL(aLine, RTL_CONSTASCII_STRINGPARAM("char")) != -1) + else if (aLine.indexOfL(RTL_CONSTASCII_STRINGPARAM("char")) != -1) eFormat = XBM11; else bStatus = sal_False; diff --git a/svtools/source/filter/sgvtext.cxx b/svtools/source/filter/sgvtext.cxx index 7a79edd472c9..1060c482ebe1 100644 --- a/svtools/source/filter/sgvtext.cxx +++ b/svtools/source/filter/sgvtext.cxx @@ -1185,26 +1185,25 @@ void SgfFontOne::ReadOne( const rtl::OString& rID, rtl::OString& Dsc ) sal_Int32 nTokenCount = comphelper::string::getTokenCount(Dsc, ' '); for (sal_Int32 nIdx = 0; nIdx < nTokenCount; ++nIdx) { - rtl::OString s = comphelper::string::getToken(Dsc, nIdx, ' '); + rtl::OString s(Dsc.getToken(nIdx, ' ')); if (!s.isEmpty()) { s = s.toAsciiUpperCase(); - using comphelper::string::matchL; - if (matchL(s, RTL_CONSTASCII_USTRINGPARAM("BOLD"))) Bold=sal_True; - else if (matchL(s, RTL_CONSTASCII_USTRINGPARAM("ITAL"))) Ital=sal_True; - else if (matchL(s, RTL_CONSTASCII_USTRINGPARAM("SERF"))) Serf=sal_True; - else if (matchL(s, RTL_CONSTASCII_USTRINGPARAM("SANS"))) Sans=sal_True; - else if (matchL(s, RTL_CONSTASCII_USTRINGPARAM("FIXD"))) Fixd=sal_True; - else if (matchL(s, RTL_CONSTASCII_USTRINGPARAM("ROMAN"))) SVFamil=FAMILY_ROMAN; - else if (matchL(s, RTL_CONSTASCII_USTRINGPARAM("SWISS"))) SVFamil=FAMILY_SWISS; - else if (matchL(s, RTL_CONSTASCII_USTRINGPARAM("MODERN"))) SVFamil=FAMILY_MODERN; - else if (matchL(s, RTL_CONSTASCII_USTRINGPARAM("SCRIPT"))) SVFamil=FAMILY_SCRIPT; - else if (matchL(s, RTL_CONSTASCII_USTRINGPARAM("DECORA"))) SVFamil=FAMILY_DECORATIVE; - else if (matchL(s, RTL_CONSTASCII_USTRINGPARAM("ANSI"))) SVChSet=RTL_TEXTENCODING_MS_1252; - else if (matchL(s, RTL_CONSTASCII_USTRINGPARAM("IBMPC"))) SVChSet=RTL_TEXTENCODING_IBM_850; - else if (matchL(s, RTL_CONSTASCII_USTRINGPARAM("MAC"))) SVChSet=RTL_TEXTENCODING_APPLE_ROMAN; - else if (matchL(s, RTL_CONSTASCII_USTRINGPARAM("SYMBOL"))) SVChSet=RTL_TEXTENCODING_SYMBOL; - else if (matchL(s, RTL_CONSTASCII_USTRINGPARAM("SYSTEM"))) SVChSet = osl_getThreadTextEncoding(); + if (s.matchL(RTL_CONSTASCII_STRINGPARAM("BOLD"))) Bold=sal_True; + else if (s.matchL(RTL_CONSTASCII_STRINGPARAM("ITAL"))) Ital=sal_True; + else if (s.matchL(RTL_CONSTASCII_STRINGPARAM("SERF"))) Serf=sal_True; + else if (s.matchL(RTL_CONSTASCII_STRINGPARAM("SANS"))) Sans=sal_True; + else if (s.matchL(RTL_CONSTASCII_STRINGPARAM("FIXD"))) Fixd=sal_True; + else if (s.matchL(RTL_CONSTASCII_STRINGPARAM("ROMAN"))) SVFamil=FAMILY_ROMAN; + else if (s.matchL(RTL_CONSTASCII_STRINGPARAM("SWISS"))) SVFamil=FAMILY_SWISS; + else if (s.matchL(RTL_CONSTASCII_STRINGPARAM("MODERN"))) SVFamil=FAMILY_MODERN; + else if (s.matchL(RTL_CONSTASCII_STRINGPARAM("SCRIPT"))) SVFamil=FAMILY_SCRIPT; + else if (s.matchL(RTL_CONSTASCII_STRINGPARAM("DECORA"))) SVFamil=FAMILY_DECORATIVE; + else if (s.matchL(RTL_CONSTASCII_STRINGPARAM("ANSI"))) SVChSet=RTL_TEXTENCODING_MS_1252; + else if (s.matchL(RTL_CONSTASCII_STRINGPARAM("IBMPC"))) SVChSet=RTL_TEXTENCODING_IBM_850; + else if (s.matchL(RTL_CONSTASCII_STRINGPARAM("MAC"))) SVChSet=RTL_TEXTENCODING_APPLE_ROMAN; + else if (s.matchL(RTL_CONSTASCII_STRINGPARAM("SYMBOL"))) SVChSet=RTL_TEXTENCODING_SYMBOL; + else if (s.matchL(RTL_CONSTASCII_STRINGPARAM("SYSTEM"))) SVChSet = osl_getThreadTextEncoding(); else if (comphelper::string::isdigitAsciiString(s) ) SVWidth=sal::static_int_cast< sal_uInt16 >(s.toInt32()); } } diff --git a/svtools/source/misc/imap2.cxx b/svtools/source/misc/imap2.cxx index 252346b48c95..60225a86d9f9 100644 --- a/svtools/source/misc/imap2.cxx +++ b/svtools/source/misc/imap2.cxx @@ -535,11 +535,9 @@ sal_uLong ImageMap::ImpDetectFormat( SvStream& rIStm ) { aStr = aStr.toAsciiLowerCase(); - using comphelper::string::indexOfL; - - if ( (indexOfL(aStr, RTL_CONSTASCII_STRINGPARAM("rect")) != -1) || - (indexOfL(aStr, RTL_CONSTASCII_USTRINGPARAM("circ")) != -1) || - (indexOfL(aStr, RTL_CONSTASCII_USTRINGPARAM("poly")) != -1) ) + if ( (aStr.indexOfL(RTL_CONSTASCII_STRINGPARAM("rect")) != -1) || + (aStr.indexOfL(RTL_CONSTASCII_USTRINGPARAM("circ")) != -1) || + (aStr.indexOfL(RTL_CONSTASCII_USTRINGPARAM("poly")) != -1) ) { if ( ( aStr.indexOf('(') != -1 ) && ( aStr.indexOf(')') != -1 ) ) diff --git a/svtools/source/svhtml/parhtml.cxx b/svtools/source/svhtml/parhtml.cxx index 3df6ab9f3f16..781b48abee56 100644 --- a/svtools/source/svhtml/parhtml.cxx +++ b/svtools/source/svhtml/parhtml.cxx @@ -39,7 +39,6 @@ #include #include #include -#include #include #include @@ -1967,7 +1966,7 @@ bool HTMLParser::IsHTMLFormat( const sal_Char* pHeader, return true; // somewhere in the first 80 characters of the document - nStart = comphelper::string::indexOfL(sCmp, RTL_CONSTASCII_STRINGPARAM(OOO_STRING_SVTOOLS_HTML_html)); + nStart = sCmp.indexOfL(RTL_CONSTASCII_STRINGPARAM(OOO_STRING_SVTOOLS_HTML_html)); if( nStart != -1 && nStart>0 && '<'==sCmp[nStart-1] && nStart+4 < sCmp.getLength() && '>'==sCmp[nStart+4] ) diff --git a/tools/bootstrp/cppdep.cxx b/tools/bootstrp/cppdep.cxx index 979201b3d02a..50165d136798 100644 --- a/tools/bootstrp/cppdep.cxx +++ b/tools/bootstrp/cppdep.cxx @@ -34,7 +34,6 @@ #include #include #include -#include #include "cppdep.hxx" CppDep::CppDep() @@ -82,8 +81,7 @@ sal_Bool CppDep::Search(const rtl::OString &rFileName) aFile.Open( suFileName, STREAM_READ ); while ( aFile.ReadLine( aReadLine )) { - using comphelper::string::indexOfL; - sal_Int32 nPos = indexOfL(aReadLine, + sal_Int32 nPos = aReadLine.indexOfL( RTL_CONSTASCII_STRINGPARAM("include")); if ( nPos != -1 ) { @@ -186,9 +184,8 @@ rtl::OString CppDep::IsIncludeStatement(rtl::OString aLine) #endif } // WhiteSpacesfressen - using comphelper::string::replace; - aLine = replace(aLine, rtl::OString(' '), rtl::OString()); - aLine = replace(aLine, rtl::OString('\t'), rtl::OString()); + aLine = aLine.replaceAll(rtl::OString(' '), rtl::OString()). + replaceAll(rtl::OString('\t'), rtl::OString()); #ifdef DEBUG_VERBOSE fprintf( stderr, "now : %s\n", aLine.getStr() ); #endif diff --git a/tools/source/fsys/dirent.cxx b/tools/source/fsys/dirent.cxx index 20251dfeee40..3fa68692eb6c 100644 --- a/tools/source/fsys/dirent.cxx +++ b/tools/source/fsys/dirent.cxx @@ -732,7 +732,7 @@ DirEntry::DirEntry( const String& rInitName, FSysPathStyle eStyle ) } rtl::OString aTmpName(rtl::OUStringToOString(rInitName, osl_getThreadTextEncoding())); - if (comphelper::string::matchIgnoreAsciiCaseL(aTmpName, RTL_CONSTASCII_STRINGPARAM("file:"))) + if (aTmpName.matchIgnoreAsciiCase(rtl::OString(RTL_CONSTASCII_STRINGPARAM("file:")))) { DBG_WARNING( "File URLs are not permitted but accepted" ); aTmpName = rtl::OUStringToOString(INetURLObject( rInitName ).PathToFileName(), osl_getThreadTextEncoding()); @@ -784,7 +784,7 @@ DirEntry::DirEntry( const rtl::OString& rInitName, FSysPathStyle eStyle ) } rtl::OString aTmpName( rInitName ); - if (comphelper::string::matchIgnoreAsciiCaseL(aTmpName, RTL_CONSTASCII_STRINGPARAM("file:"))) + if (aTmpName.matchIgnoreAsciiCase(rtl::OString(RTL_CONSTASCII_STRINGPARAM("file:")))) { DBG_WARNING( "File URLs are not permitted but accepted" ); aTmpName = rtl::OUStringToOString(INetURLObject( rInitName ).PathToFileName(), osl_getThreadTextEncoding()); diff --git a/tools/source/inet/inetstrm.cxx b/tools/source/inet/inetstrm.cxx index d787baaa7166..7ad19e640fc6 100644 --- a/tools/source/inet/inetstrm.cxx +++ b/tools/source/inet/inetstrm.cxx @@ -1614,7 +1614,7 @@ int INetMIMEMessageStream::PutMsgLine (const sal_Char *pData, sal_uIntPtr nSize) pMsg->GetContentType(), RTL_TEXTENCODING_ASCII_US)); rtl::OString aLowerType(aType.toAsciiLowerCase()); - sal_Int32 nPos = comphelper::string::indexOfL(aLowerType, + sal_Int32 nPos = aLowerType.indexOfL( RTL_CONSTASCII_STRINGPARAM("boundary=")); rtl::OString aBoundary(aType.copy(nPos + 9)); diff --git a/vcl/generic/print/common_gfx.cxx b/vcl/generic/print/common_gfx.cxx index 8de0134283f3..941a5ccc51c9 100644 --- a/vcl/generic/print/common_gfx.cxx +++ b/vcl/generic/print/common_gfx.cxx @@ -30,7 +30,6 @@ #include "psputil.hxx" #include "glyphset.hxx" -#include #include "generic/printergfx.hxx" #include "generic/printerjob.hxx" #include "vcl/fontmanager.hxx" @@ -1204,9 +1203,9 @@ PrinterGfx::DrawEPS( const Rectangle& rBoundingBox, void* pPtr, sal_uInt32 nSize char cChar = aLine[1]; if( cChar == '%' ) { - if( comphelper::string::matchIgnoreAsciiCaseL( aLine, RTL_CONSTASCII_STRINGPARAM("%%BoundingBox:") ) ) + if( aLine.matchIgnoreAsciiCase( rtl::OString( RTL_CONSTASCII_STRINGPARAM("%%BoundingBox:") ) ) ) { - aLine = WhitespaceToSpace( comphelper::string::getToken(aLine, 1, ':') ); + aLine = WhitespaceToSpace( aLine.getToken(1, ':') ); if( !aLine.isEmpty() && aLine.indexOf( "atend" ) == -1 ) { fLeft = StringToDouble( GetCommandLineToken( 0, aLine ) ); @@ -1215,9 +1214,9 @@ PrinterGfx::DrawEPS( const Rectangle& rBoundingBox, void* pPtr, sal_uInt32 nSize fTop = StringToDouble( GetCommandLineToken( 3, aLine ) ); } } - else if( comphelper::string::matchIgnoreAsciiCaseL( aLine, RTL_CONSTASCII_STRINGPARAM("%%Title:") ) ) + else if( aLine.matchIgnoreAsciiCase( rtl::OString( RTL_CONSTASCII_STRINGPARAM("%%Title:") ) ) ) aDocTitle = WhitespaceToSpace( aLine.copy( 8 ) ); - else if( comphelper::string::matchIgnoreAsciiCaseL( aLine, RTL_CONSTASCII_STRINGPARAM("%%EndComments") ) ) + else if( aLine.matchIgnoreAsciiCase( rtl::OString( RTL_CONSTASCII_STRINGPARAM("%%EndComments") ) ) ) bEndComments = true; } else if( cChar == ' ' || cChar == '\t' || cChar == '\r' || cChar == '\n' ) diff --git a/vcl/generic/print/genprnpsp.cxx b/vcl/generic/print/genprnpsp.cxx index 18980a421e28..9bc8731016c3 100644 --- a/vcl/generic/print/genprnpsp.cxx +++ b/vcl/generic/print/genprnpsp.cxx @@ -47,7 +47,6 @@ #endif #include "rtl/ustring.hxx" -#include "comphelper/string.hxx" #include "osl/module.h" @@ -243,7 +242,7 @@ static bool passFileToCommandLine( const OUString& rFilename, const OUString& rC // setup command line for exec if( ! bPipe ) - aCmdLine = comphelper::string::replace( aCmdLine, rtl::OString("(TMP)"), aFilename ); + aCmdLine = aCmdLine.replaceAll(rtl::OString("(TMP)"), aFilename); #if OSL_DEBUG_LEVEL > 1 fprintf( stderr, "%s commandline: \"%s\"\n", @@ -359,7 +358,9 @@ static bool sendAFax( const OUString& rFaxNumber, const OUString& rFileName, con { OUString aFaxNumber( aFaxNumbers.front() ); aFaxNumbers.pop_front(); - OUString aCmdLine = comphelper::string::replace( rCommand, OUString( RTL_CONSTASCII_USTRINGPARAM( "(PHONE)" ) ), aFaxNumber ); + OUString aCmdLine( + rCommand.replaceAllAsciiL( + RTL_CONSTASCII_STRINGPARAM("(PHONE)"), aFaxNumber)); #if OSL_DEBUG_LEVEL > 1 fprintf( stderr, "sending fax to \"%s\"\n", OUStringToOString( aFaxNumber, osl_getThreadTextEncoding() ).getStr() ); #endif @@ -382,7 +383,9 @@ static bool sendAFax( const OUString& rFaxNumber, const OUString& rFileName, con static bool createPdf( const OUString& rToFile, const OUString& rFromFile, const OUString& rCommandLine ) { #if defined( UNX ) - OUString aCommandLine = comphelper::string::replace( rCommandLine, OUString( RTL_CONSTASCII_USTRINGPARAM( "(OUTFILE)" ) ), rToFile ); + OUString aCommandLine( + rCommandLine.replaceAllAsciiL( + RTL_CONSTASCII_STRINGPARAM("(OUTFILE)"), rToFile)); return passFileToCommandLine( rFromFile, aCommandLine ); #else diff --git a/vcl/unx/generic/printer/jobdata.cxx b/vcl/unx/generic/printer/jobdata.cxx index 9bd1d57b54af..5644a6720402 100644 --- a/vcl/unx/generic/printer/jobdata.cxx +++ b/vcl/unx/generic/printer/jobdata.cxx @@ -34,7 +34,6 @@ #include #include -#include using namespace psp; @@ -207,54 +206,51 @@ bool JobData::constructFromStreamBuffer( void* pData, int bytes, JobData& rJobDa const char pslevelEquals[] = "pslevel="; const char pdfdeviceEquals[] = "pdfdevice="; - using comphelper::string::matchL; - while( ! aStream.IsEof() ) { aStream.ReadLine( aLine ); - if (matchL(aLine, RTL_CONSTASCII_STRINGPARAM("JobData"))) + if (aLine.matchL(RTL_CONSTASCII_STRINGPARAM("JobData"))) bVersion = true; - else if (matchL(aLine, RTL_CONSTASCII_STRINGPARAM(printerEquals))) + else if (aLine.matchL(RTL_CONSTASCII_STRINGPARAM(printerEquals))) { bPrinter = true; rJobData.m_aPrinterName = rtl::OStringToOUString(aLine.copy(RTL_CONSTASCII_LENGTH(printerEquals)), RTL_TEXTENCODING_UTF8); } - else if (matchL(aLine, RTL_CONSTASCII_STRINGPARAM(orientatationEquals))) + else if (aLine.matchL(RTL_CONSTASCII_STRINGPARAM(orientatationEquals))) { bOrientation = true; rJobData.m_eOrientation = aLine.copy(RTL_CONSTASCII_LENGTH(orientatationEquals)).equalsIgnoreAsciiCase("landscape") ? orientation::Landscape : orientation::Portrait; } - else if (matchL(aLine, RTL_CONSTASCII_STRINGPARAM(copiesEquals))) + else if (aLine.matchL(RTL_CONSTASCII_STRINGPARAM(copiesEquals))) { bCopies = true; rJobData.m_nCopies = aLine.copy(RTL_CONSTASCII_LENGTH(copiesEquals)).toInt32(); } - else if (matchL(aLine, RTL_CONSTASCII_STRINGPARAM(margindajustmentEquals))) + else if (aLine.matchL(RTL_CONSTASCII_STRINGPARAM(margindajustmentEquals))) { bMargin = true; rtl::OString aValues(aLine.copy(RTL_CONSTASCII_LENGTH(margindajustmentEquals))); - using comphelper::string::getToken; - rJobData.m_nLeftMarginAdjust = getToken(aValues, 0, ',').toInt32(); - rJobData.m_nRightMarginAdjust = getToken(aValues, 1, ',').toInt32(); - rJobData.m_nTopMarginAdjust = getToken(aValues, 2, ',').toInt32(); - rJobData.m_nBottomMarginAdjust = getToken(aValues, 3, ',').toInt32(); + rJobData.m_nLeftMarginAdjust = aValues.getToken(0, ',').toInt32(); + rJobData.m_nRightMarginAdjust = aValues.getToken(1, ',').toInt32(); + rJobData.m_nTopMarginAdjust = aValues.getToken(2, ',').toInt32(); + rJobData.m_nBottomMarginAdjust = aValues.getToken(3, ',').toInt32(); } - else if (matchL(aLine, RTL_CONSTASCII_STRINGPARAM(colordepthEquals))) + else if (aLine.matchL(RTL_CONSTASCII_STRINGPARAM(colordepthEquals))) { bColorDepth = true; rJobData.m_nColorDepth = aLine.copy(RTL_CONSTASCII_LENGTH(colordepthEquals)).toInt32(); } - else if (matchL(aLine, RTL_CONSTASCII_STRINGPARAM(colordeviceEquals))) + else if (aLine.matchL(RTL_CONSTASCII_STRINGPARAM(colordeviceEquals))) { bColorDevice = true; rJobData.m_nColorDevice = aLine.copy(RTL_CONSTASCII_LENGTH(colordeviceEquals)).toInt32(); } - else if (matchL(aLine, RTL_CONSTASCII_STRINGPARAM(pslevelEquals))) + else if (aLine.matchL(RTL_CONSTASCII_STRINGPARAM(pslevelEquals))) { bPSLevel = true; rJobData.m_nPSLevel = aLine.copy(RTL_CONSTASCII_LENGTH(pslevelEquals)).toInt32(); } - else if (matchL(aLine, RTL_CONSTASCII_STRINGPARAM(pdfdeviceEquals))) + else if (aLine.matchL(RTL_CONSTASCII_STRINGPARAM(pdfdeviceEquals))) { bPDFDevice = true; rJobData.m_nPDFDevice = aLine.copy(RTL_CONSTASCII_LENGTH(pdfdeviceEquals)).toInt32(); diff --git a/vcl/unx/gtk/app/gtksys.cxx b/vcl/unx/gtk/app/gtksys.cxx index 6690d5f0b70e..7c3b3f0e0cc1 100644 --- a/vcl/unx/gtk/app/gtksys.cxx +++ b/vcl/unx/gtk/app/gtksys.cxx @@ -30,7 +30,6 @@ #include #include #include -#include #include #include @@ -243,8 +242,8 @@ static rtl::OString MapToGtkAccelerator(const rtl::OUString &rStr) { const rtl::OUString aRep(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "_" ))); return rtl::OUStringToOString( - comphelper::string::searchAndReplaceAsciiL( - rStr, RTL_CONSTASCII_STRINGPARAM( "~" ), aRep), RTL_TEXTENCODING_UTF8); + rStr.replaceFirstAsciiL(RTL_CONSTASCII_STRINGPARAM( "~" ), aRep), + RTL_TEXTENCODING_UTF8); } int GtkSalSystem::ShowNativeDialog (const rtl::OUString& rTitle, const rtl::OUString& rMessage, -- cgit