diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2012-02-15 15:26:43 +0100 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2012-02-15 15:41:09 +0100 |
commit | 9ab0b38e95133dab720408cc2c80093b8a201c10 (patch) | |
tree | 416dde227ed5c4ded99292feb94f36a64c327999 /comphelper/inc | |
parent | 42422f2599220b678aa41c4aadeec28df113c3ec (diff) |
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.
Diffstat (limited to 'comphelper/inc')
-rw-r--r-- | comphelper/inc/comphelper/string.hxx | 192 |
1 files changed, 20 insertions, 172 deletions
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<rtl_String, sal_Char>(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 <code>source</code> -*/ -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<typename B> B& truncateToLength(B& rBuffer, sal_Int32 nLen) |