Date: prev next · Thread: first prev next last
2011 Archives by date, by thread · List index


On Thursday 30 of June 2011, Caolán McNamara wrote:
On Thu, 2011-06-30 at 13:46 +0200, Lubos Lunak wrote:
O[U]StringBuffer don't have any other range
function, but O[U]String uses start+len for such cases (copy, replaceAt),
so this seems inconsistent.

hmm, yeah, that's true. java doesn't have a replaceAt sort of thing, nor
a "copy" method, though its ctors have a startindex +  length option
while it has a "substring" which does take [startindex, endindex)

Do we have a preference ?, I'm easy either way.

 Since nobody seems to have a preference, I'd like to point out that also 
std::string uses start+len (even though there one could expect start,end to 
match the iterator variants) and Qt uses start+len. IMO we should not try to 
be consistent with Java just because the idea for the class comes from Java.

 Ok to push the attached patch? Also, am I correct that you haven't used these 
anywhere yet?

-- 
 Lubos Lunak
 l.lunak@suse.cz
diff --git a/sal/inc/rtl/strbuf.h b/sal/inc/rtl/strbuf.h
index 1c076cf..9543b9a 100644
--- a/sal/inc/rtl/strbuf.h
+++ b/sal/inc/rtl/strbuf.h
@@ -116,19 +116,16 @@ void SAL_CALL rtl_stringbuffer_insert( /*inout*/rtl_String ** This,
     Removes the characters in a substring of this sequence.
 
     The substring begins at the specified <code>start</code> and
-    extends to the character at index <code>end - 1</code> or to
-    the end of the sequence if no such character exists. If
-    <code>start</code> is equal to <code>end</code>, no changes
-    are made.
+    is <code>len</code> characters long.
 
-    start must be >= 0 && <= This->length && <= end
+    start must be >= 0 && <= This->length
 
     @param     start           The beginning index, inclusive
-    @param     end             The ending index, exclusive
+    @param     len             The substring length
  */
 void SAL_CALL rtl_stringbuffer_remove( /*inout*/rtl_String ** This,
                                        sal_Int32 start,
-                                       sal_Int32 end );
+                                       sal_Int32 len );
 
 #ifdef __cplusplus
 }
diff --git a/sal/inc/rtl/strbuf.hxx b/sal/inc/rtl/strbuf.hxx
index 7e52b21..3a26c1b 100644
--- a/sal/inc/rtl/strbuf.hxx
+++ b/sal/inc/rtl/strbuf.hxx
@@ -675,25 +675,17 @@ public:
         Removes the characters in a substring of this sequence.
 
         The substring begins at the specified <code>start</code> and
-        extends to the character at index <code>end - 1</code> or to
-        the end of the sequence if no such character exists. If
-        <code>start</code> is equal to <code>end</code>, no changes
-        are made.
+        is <code>len</code> characters long.
 
         start must be >= 0 && <= getLength() && <= end
 
-        As is usual for the rtl string classes, this is based
-        on an analogous Java StringBuffer member. In this
-        case <code>delete</code>, but because that's a reserved
-        keyword in C++, this is named <code>remove</code>.
-
-        @param  start          The beginning index, inclusive
-        @param  end                    The ending index, exclusive
+        @param         start           The beginning index, inclusive
+        @param len             The substring length
         @return this string buffer.
      */
-    OStringBuffer & remove( sal_Int32 start, sal_Int32 end )
+    OStringBuffer & remove( sal_Int32 start, sal_Int32 len )
     {
-        rtl_stringbuffer_remove( &pData, start, end );
+        rtl_stringbuffer_remove( &pData, start, len );
         return *this;
     }
 
diff --git a/sal/inc/rtl/ustrbuf.h b/sal/inc/rtl/ustrbuf.h
index d2d2ed4..260db4f 100644
--- a/sal/inc/rtl/ustrbuf.h
+++ b/sal/inc/rtl/ustrbuf.h
@@ -163,19 +163,16 @@ void SAL_CALL rtl_uStringbuffer_insert_ascii(   /*inout*/rtl_uString ** This,
     Removes the characters in a substring of this sequence.
 
     The substring begins at the specified <code>start</code> and
-    extends to the character at index <code>end - 1</code> or to
-    the end of the sequence if no such character exists. If
-    <code>start</code> is equal to <code>end</code>, no changes
-    are made.
+    is <code>len</code> characters long.
 
-    start must be >= 0 && <= This->length && <= end
+    start must be >= 0 && <= This->length
 
     @param     start           The beginning index, inclusive
-    @param     end             The ending index, exclusive
+    @param     len             The substring length
  */
 void SAL_CALL rtl_uStringbuffer_remove( /*inout*/rtl_uString ** This,
                                        sal_Int32 start,
-                                       sal_Int32 end );
+                                       sal_Int32 len );
 
 #ifdef __cplusplus
 }
diff --git a/sal/inc/rtl/ustrbuf.hxx b/sal/inc/rtl/ustrbuf.hxx
index d48c5c7..7569597 100644
--- a/sal/inc/rtl/ustrbuf.hxx
+++ b/sal/inc/rtl/ustrbuf.hxx
@@ -742,25 +742,17 @@ public:
         Removes the characters in a substring of this sequence.
 
         The substring begins at the specified <code>start</code> and
-        extends to the character at index <code>end - 1</code> or to
-        the end of the sequence if no such character exists. If
-        <code>start</code> is equal to <code>end</code>, no changes
-        are made.
+        is <code>len</code> characters long.
 
-        start must be >= 0 && <= getLength() && <= end
+        start must be >= 0 && <= This->length
 
-        As is usual for the rtl string classes, this is based
-        on an analogous Java StringBuffer member. In this
-        case <code>delete</code>, but because that's a reserved
-        keyword in C++, this is named <code>remove</code>.
-
-        @param  start          The beginning index, inclusive
-        @param  end                    The ending index, exclusive
+        @param         start           The beginning index, inclusive
+        @param len             The substring length
         @return this string buffer.
      */
-    OUStringBuffer & remove( sal_Int32 start, sal_Int32 end )
+    OUStringBuffer & remove( sal_Int32 start, sal_Int32 len )
     {
-        rtl_uStringbuffer_remove( &pData, start, end );
+        rtl_uStringbuffer_remove( &pData, start, len );
         return *this;
     }
 
diff --git a/sal/qa/OStringBuffer/rtl_OStringBuffer.cxx b/sal/qa/OStringBuffer/rtl_OStringBuffer.cxx
index 2307dab..036a2c3 100644
--- a/sal/qa/OStringBuffer/rtl_OStringBuffer.cxx
+++ b/sal/qa/OStringBuffer/rtl_OStringBuffer.cxx
@@ -340,7 +340,7 @@ namespace rtl_OStringBuffer
             CPPUNIT_ASSERT(sb.toString().equalsL(
                 RTL_CONSTASCII_STRINGPARAM("Hat, Inc.")));
 
-            sb.remove(3, 9);
+            sb.remove(3, 6);
             CPPUNIT_ASSERT(sb.toString().equalsL(
                 RTL_CONSTASCII_STRINGPARAM("Hat")));
 
diff --git a/sal/rtl/source/strbuf.c b/sal/rtl/source/strbuf.c
index 8d0f276..c0e9694 100644
--- a/sal/rtl/source/strbuf.c
+++ b/sal/rtl/source/strbuf.c
@@ -151,31 +151,28 @@ void SAL_CALL rtl_stringbuffer_insert( rtl_String ** This,
  */
 void SAL_CALL rtl_stringbuffer_remove( rtl_String ** This,
                                        sal_Int32 start,
-                                       sal_Int32 end )
+                                       sal_Int32 len )
 {
     sal_Int32 nTailLen;
     sal_Char * pBuf;
-    sal_Int32 n;
-
-    if (end > (*This)->length)
-        end = (*This)->length;
 
-    n = end - start;
+    if (len > (*This)->length - start)
+        len = (*This)->length - start;
 
     //remove nothing
-    if (!n)
+    if (!len)
         return;
 
     pBuf = (*This)->buffer;
-    nTailLen = (*This)->length - end;
+    nTailLen = (*This)->length - ( start + len );
 
     if (nTailLen)
     {
         /* move the tail */
-        rtl_moveMemory(pBuf + start, pBuf + end, nTailLen * sizeof(sal_Char));
+        rtl_moveMemory(pBuf + start, pBuf + start + len, nTailLen * sizeof(sal_Char));
     }
 
-    (*This)->length-=n;
+    (*This)->length-=len;
     pBuf[ (*This)->length ] = 0;
 }      
 
diff --git a/sal/rtl/source/ustrbuf.c b/sal/rtl/source/ustrbuf.c
index 18ca27f..638b27e 100644
--- a/sal/rtl/source/ustrbuf.c
+++ b/sal/rtl/source/ustrbuf.c
@@ -211,31 +211,28 @@ void SAL_CALL rtl_uStringbuffer_insert_ascii(   /*inout*/rtl_uString ** This,
  */
 void SAL_CALL rtl_uStringbuffer_remove( rtl_uString ** This,
                                        sal_Int32 start,
-                                       sal_Int32 end )
+                                       sal_Int32 len )
 {
     sal_Int32 nTailLen;
     sal_Unicode * pBuf;
-    sal_Int32 n;
-
-    if (end > (*This)->length)
-        end = (*This)->length;
 
-    n = end - start;
+    if (len > (*This)->length - start)
+        len = (*This)->length - start;
 
     //remove nothing
-    if (!n)
+    if (!len)
         return;
 
     pBuf = (*This)->buffer;
-    nTailLen = (*This)->length - end;
+    nTailLen = (*This)->length - ( start + len );
 
     if (nTailLen)
     {
         /* move the tail */
-        rtl_moveMemory(pBuf + start, pBuf + end, nTailLen * sizeof(sal_Unicode));
+        rtl_moveMemory(pBuf + start, pBuf + start + len, nTailLen * sizeof(sal_Unicode));
     }
 
-    (*This)->length-=n;
+    (*This)->length-=len;
     pBuf[ (*This)->length ] = 0;
 }
 

Context


Privacy Policy | Impressum (Legal Info) | Copyright information: Unless otherwise specified, all text and images on this website are licensed under the Creative Commons Attribution-Share Alike 3.0 License. This does not include the source code of LibreOffice, which is licensed under the Mozilla Public License (MPLv2). "LibreOffice" and "The Document Foundation" are registered trademarks of their corresponding registered owners or are in actual use as trademarks in one or more countries. Their respective logos and icons are also subject to international copyright laws. Use thereof is explained in our trademark policy.