summaryrefslogtreecommitdiff
path: root/include/rtl
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2015-06-23 14:53:56 +0200
committerStephan Bergmann <sbergman@redhat.com>2015-06-23 14:53:56 +0200
commitfd7889a9cfb601df65670dcdce8c4c2c2450f47c (patch)
tree771d97562d4023e975effbe3cae30a1ca204ef73 /include/rtl
parent0f03d20011c31e36823ca5260e1840593d6949a1 (diff)
Implement full set of OUString::replaceFirst/All literal overloads
Change-Id: I5f525d91ce24d1d2653a6855f1c4fffc039ae398
Diffstat (limited to 'include/rtl')
-rw-r--r--include/rtl/ustring.h53
-rw-r--r--include/rtl/ustring.hxx52
2 files changed, 105 insertions, 0 deletions
diff --git a/include/rtl/ustring.h b/include/rtl/ustring.h
index 8dd70cb4911f..700393694b60 100644
--- a/include/rtl/ustring.h
+++ b/include/rtl/ustring.h
@@ -1555,6 +1555,35 @@ SAL_DLLPUBLIC void SAL_CALL rtl_uString_newReplaceFirstAsciiL(
@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 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 5.1
+*/
+SAL_DLLPUBLIC void SAL_CALL rtl_uString_newReplaceFirstToAsciiL(
+ rtl_uString ** newStr, rtl_uString * str, rtl_uString const * from,
+ char const * to, sal_Int32 toLength, 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
@@ -1658,6 +1687,30 @@ SAL_DLLPUBLIC void SAL_CALL rtl_uString_newReplaceAllAsciiL(
@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 and must
+ point to memory of at least \p toLength ASCII bytes
+
+ @param fromLength the length of the \p to substring; must be non-negative
+
+ @since LibreOffice 5.1
+*/
+SAL_DLLPUBLIC void SAL_CALL rtl_uString_newReplaceAllToAsciiL(
+ rtl_uString ** newStr, rtl_uString * str, rtl_uString const * from,
+ char const * to, sal_Int32 toLength) 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
diff --git a/include/rtl/ustring.hxx b/include/rtl/ustring.hxx
index 662e215c0370..1e9bfa8fbd5e 100644
--- a/include/rtl/ustring.hxx
+++ b/include/rtl/ustring.hxx
@@ -1780,6 +1780,36 @@ public:
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 ASCII string literal, 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 exiting
+ 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 5.1
+ */
+ template< typename T >
+ SAL_WARN_UNUSED_RESULT typename libreoffice_internal::ConstCharArrayDetector< T, OUString >::Type replaceFirst( OUString const & from, T& to,
+ sal_Int32 * index = 0) const
+ {
+ rtl_uString * s = 0;
+ sal_Int32 i = 0;
+ assert( strlen( to ) == libreoffice_internal::ConstCharArrayDetector< T >::size - 1 );
+ rtl_uString_newReplaceFirstToAsciiL(
+ &s, pData, from.pData, to, libreoffice_internal::ConstCharArrayDetector< T, void >::size - 1, 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 ASCII string literal, the substring to be replaced
@param to ASCII string literal, the substring to be replaced
@@ -1860,6 +1890,28 @@ public:
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 ASCII string literal, the replacing substring
+
+ @since LibreOffice 5.1
+ */
+ template< typename T >
+ SAL_WARN_UNUSED_RESULT typename libreoffice_internal::ConstCharArrayDetector< T, OUString >::Type replaceAll( OUString const & from, T& to) const
+ {
+ rtl_uString * s = 0;
+ assert( strlen( to ) == libreoffice_internal::ConstCharArrayDetector< T >::size - 1 );
+ rtl_uString_newReplaceAllToAsciiL(&s, pData, from.pData, to, libreoffice_internal::ConstCharArrayDetector< T, void >::size - 1);
+ 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 ASCII string literal, the substring to be replaced
@param to ASCII string literal, the substring to be replaced