[PATCH] New method: isEmpty() - Checks if a string is empty.

Thomas Arnhold thomas at arnhold.org
Fri Jan 21 04:43:52 PST 2011


This could simplify logics in the source. Now this test is done
like 'if (aStr.getLength() != 0) {...}' or 'if (!aStr.getLength()) {...}'.

With isEmpty() this looks like:
if (aStr.isEmpty()) {...}
if (!aStr.isEmpty()) {...}

I think this would make the code more readable.
---
 sal/inc/rtl/ustring.hxx |   14 ++++++++++++++
 1 files changed, 14 insertions(+), 0 deletions(-)

diff --git a/sal/inc/rtl/ustring.hxx b/sal/inc/rtl/ustring.hxx
index a481be7..5fdbcc6 100644
--- a/sal/inc/rtl/ustring.hxx
+++ b/sal/inc/rtl/ustring.hxx
@@ -278,6 +278,20 @@ public:
     sal_Int32 getLength() const SAL_THROW(()) { return pData->length; }
 
     /**
+      Checks if a string is empty.
+
+      @return   sal_True if the string is empty;
+                sal_False, otherwise.
+    */
+    sal_Bool isEmpty() const SAL_THROW(())
+    {
+        if ( pData->length )
+            return sal_False;
+        else
+            return sal_True;
+    }
+
+    /**
       Returns a pointer to the Unicode character buffer from this string.
 
       It isn't necessarily NULL terminated.
-- 
1.7.3.5


--------------060305080405000201000102--


More information about the LibreOffice mailing list