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 /sal/rtl/source/ustring.cxx | |
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 'sal/rtl/source/ustring.cxx')
-rw-r--r-- | sal/rtl/source/ustring.cxx | 178 |
1 files changed, 178 insertions, 0 deletions
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 <cassert> +#include <cstdlib> + #include <rtl/memory.h> #include <osl/diagnose.h> #include <osl/interlck.h> @@ -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: */ |