[Libreoffice-commits] .: sal/inc

Stephan Bergmann sbergmann at kemper.freedesktop.org
Wed Oct 5 00:22:37 PDT 2011


 sal/inc/rtl/strbuf.hxx  |   14 ++++++++++----
 sal/inc/rtl/string.hxx  |   24 +++++++++++-------------
 sal/inc/rtl/ustrbuf.hxx |   14 ++++++++++----
 sal/inc/rtl/ustring.hxx |   12 +++++++-----
 4 files changed, 38 insertions(+), 26 deletions(-)

New commits:
commit 112bdf84d684590e042725c7173e059b4afa2f83
Author: Stephan Bergmann <sbergman at redhat.com>
Date:   Wed Oct 5 09:20:59 2011 +0200

    Removed dangerous rtl::O[U]String[Buffer]::operator sal_{char,Unicode} const *.
    
    As a replacement, added appropriate operator [] functions.  All other uses can
    use getStr().

diff --git a/sal/inc/rtl/strbuf.hxx b/sal/inc/rtl/strbuf.hxx
index 63ae448..962d3df 100644
--- a/sal/inc/rtl/strbuf.hxx
+++ b/sal/inc/rtl/strbuf.hxx
@@ -287,12 +287,18 @@ public:
     /**
         Return a null terminated character array.
      */
-    operator        const sal_Char *() const { return pData->buffer; }
+    const sal_Char* getStr() const { return pData->buffer; }
 
     /**
-        Return a null terminated character array.
-     */
-    const sal_Char* getStr() const { return pData->buffer; }
+      Access to individual characters.
+
+      @param index must be non-negative and less than length.
+
+      @return a reference to the character at the given index.
+
+      @since LibreOffice 3.5
+    */
+    sal_Char & operator [](sal_Int32 index) { return pData->buffer[index]; }
 
     /**
         Return a OString instance reflecting the current content
diff --git a/sal/inc/rtl/string.hxx b/sal/inc/rtl/string.hxx
index 96ca406..22de6dd 100644
--- a/sal/inc/rtl/string.hxx
+++ b/sal/inc/rtl/string.hxx
@@ -251,19 +251,6 @@ public:
     /**
       Returns a pointer to the characters of this string.
 
-      <p>The returned pointer is not guaranteed to point to a null-terminated
-      byte string.  Note that this string object may contain embedded null
-      characters, which will thus also be embedded in the returned byte
-      string.</p>
-
-      @return a pointer to a (not necessarily null-terminated) byte string
-      representing the characters of this string object.
-    */
-    operator const sal_Char *() const SAL_THROW(()) { return pData->buffer; }
-
-    /**
-      Returns a pointer to the characters of this string.
-
       <p>The returned pointer is guaranteed to point to a null-terminated byte
       string.  But note that this string object may contain embedded null
       characters, which will thus also be embedded in the returned
@@ -275,6 +262,17 @@ public:
     const sal_Char * getStr() const SAL_THROW(()) { return pData->buffer; }
 
     /**
+      Access to individual characters.
+
+      @param index must be non-negative and less than length.
+
+      @return the character at the given index.
+
+      @since LibreOffice 3.5
+    */
+    sal_Char operator [](sal_Int32 index) const { return getStr()[index]; }
+
+    /**
       Compares two strings.
 
       The comparison is based on the numeric value of each character in
diff --git a/sal/inc/rtl/ustrbuf.hxx b/sal/inc/rtl/ustrbuf.hxx
index a356309..47569e5 100644
--- a/sal/inc/rtl/ustrbuf.hxx
+++ b/sal/inc/rtl/ustrbuf.hxx
@@ -267,12 +267,18 @@ public:
     /**
         Return a null terminated unicode character array.
      */
-    operator        const sal_Unicode *() const { return pData->buffer; }
+    const sal_Unicode*  getStr() const { return pData->buffer; }
 
     /**
-        Return a null terminated unicode character array.
-     */
-    const sal_Unicode*  getStr() const { return pData->buffer; }
+      Access to individual characters.
+
+      @param index must be non-negative and less than length.
+
+      @return a reference to the character at the given index.
+
+      @since LibreOffice 3.5
+    */
+    sal_Unicode & operator [](sal_Int32 index) { return pData->buffer[index]; }
 
     /**
         Return a OUString instance reflecting the current content
diff --git a/sal/inc/rtl/ustring.hxx b/sal/inc/rtl/ustring.hxx
index ed268d9..e104f0d 100644
--- a/sal/inc/rtl/ustring.hxx
+++ b/sal/inc/rtl/ustring.hxx
@@ -300,16 +300,18 @@ public:
 
       @return   a pointer to the Unicode characters buffer from this object.
     */
-    operator const sal_Unicode *() const SAL_THROW(()) { return pData->buffer; }
+    const sal_Unicode * getStr() const SAL_THROW(()) { return pData->buffer; }
 
     /**
-      Returns a pointer to the Unicode character buffer from this string.
+      Access to individual characters.
 
-      It isn't necessarily NULL terminated.
+      @param index must be non-negative and less than length.
 
-      @return   a pointer to the Unicode characters buffer from this object.
+      @return the character at the given index.
+
+      @since LibreOffice 3.5
     */
-    const sal_Unicode * getStr() const SAL_THROW(()) { return pData->buffer; }
+    sal_Unicode operator [](sal_Int32 index) const { return getStr()[index]; }
 
     /**
       Compares two strings.


More information about the Libreoffice-commits mailing list