[Libreoffice-commits] .: sal/inc sal/rtl sal/util

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Tue Oct 9 13:49:08 PDT 2012


 sal/inc/rtl/ustring.h      |   23 +++++++++++++++++++++++
 sal/inc/rtl/ustring.hxx    |    8 +++++---
 sal/rtl/source/ustring.cxx |   10 +++++++++-
 sal/util/sal.map           |    1 +
 4 files changed, 38 insertions(+), 4 deletions(-)

New commits:
commit 7ef1190c3e9422998d89df2cf8fcf30bddfc1a03
Author: Noel Grandin <noel at peralex.com>
Date:   Thu Oct 4 15:06:27 2012 +0200

    Add a 'fromIndex' parameter to OUString::replaceAll
    
    This method will be needed for forthcoming String->OUStringBuffer
    conversions.
    
    Change-Id: I001099baaca5cd402aebcd15c031d9060286a8f9

diff --git a/sal/inc/rtl/ustring.h b/sal/inc/rtl/ustring.h
index 231dcdc..e056bad 100644
--- a/sal/inc/rtl/ustring.h
+++ b/sal/inc/rtl/ustring.h
@@ -1530,6 +1530,29 @@ SAL_DLLPUBLIC void SAL_CALL rtl_uString_newReplaceAll(
 
     @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 fromIndex  the position in the string where we will begin searching
+
+    @since LibreOffice 3.7
+*/
+SAL_DLLPUBLIC void SAL_CALL rtl_uString_newReplaceAllFromIndex(
+    rtl_uString ** newStr, rtl_uString * str, rtl_uString const * from,
+    rtl_uString const * to, sal_Int32 fromIndex) 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/sal/inc/rtl/ustring.hxx b/sal/inc/rtl/ustring.hxx
index 9756801..bbd6e96 100644
--- a/sal/inc/rtl/ustring.hxx
+++ b/sal/inc/rtl/ustring.hxx
@@ -1531,11 +1531,13 @@ public:
 
       @param to  the replacing substring
 
-      @since LibreOffice 3.6
+      @param fromIndex  the position in the string where we will begin searching
+
+      @since LibreOffice 3.7
     */
-    OUString replaceAll(OUString const & from, OUString const & to) const {
+    OUString replaceAll(OUString const & from, OUString const & to, int fromIndex = 0) const {
         rtl_uString * s = 0;
-        rtl_uString_newReplaceAll(&s, pData, from.pData, to.pData);
+        rtl_uString_newReplaceAllFromIndex(&s, pData, from.pData, to.pData, fromIndex);
         return OUString(s, SAL_NO_ACQUIRE);
     }
 
diff --git a/sal/rtl/source/ustring.cxx b/sal/rtl/source/ustring.cxx
index b219949..ac2d7d9 100644
--- a/sal/rtl/source/ustring.cxx
+++ b/sal/rtl/source/ustring.cxx
@@ -1159,9 +1159,17 @@ void rtl_uString_newReplaceAll(
     rtl_uString ** newStr, rtl_uString * str, rtl_uString const * from,
     rtl_uString const * to) SAL_THROW_EXTERN_C()
 {
+    rtl_uString_newReplaceAllFromIndex( newStr, str, from, to, 0 );
+}
+
+void rtl_uString_newReplaceAllFromIndex(
+    rtl_uString ** newStr, rtl_uString * str, rtl_uString const * from,
+    rtl_uString const * to, sal_Int32 fromIndex) SAL_THROW_EXTERN_C()
+{
     assert(to != 0);
+    assert(fromIndex >= 0 && fromIndex <= str->length);
     rtl_uString_assign(newStr, str);
-    for (sal_Int32 i = 0;; i += to->length) {
+    for (sal_Int32 i = fromIndex;; i += to->length) {
         rtl_uString_newReplaceFirst(newStr, *newStr, from, to, &i);
         if (i == -1) {
             break;
diff --git a/sal/util/sal.map b/sal/util/sal.map
index 978a66e..bf518d3 100644
--- a/sal/util/sal.map
+++ b/sal/util/sal.map
@@ -631,6 +631,7 @@ LIBO_UDK_3.7 { # symbols available in >= LibO 3.7
     global:
         rtl_string_newFromSubString;
         rtl_uString_newFromSubString;
+        rtl_uString_newReplaceAllFromIndex;
 } LIBO_UDK_3.6;
 
 PRIVATE_1.0 {


More information about the Libreoffice-commits mailing list