[opengtl-commits] [328] add a startWith function to GTLCore::String

[ Thread Index | Date Index | More lists.tuxfamily.org/opengtl-commits Archives ]


Revision: 328
Author:   cyrille
Date:     2008-08-31 10:02:30 +0200 (Sun, 31 Aug 2008)

Log Message:
-----------
add a startWith function to GTLCore::String

Modified Paths:
--------------
    trunk/OpenGTL/OpenGTL/GTLCore/String.cpp
    trunk/OpenGTL/OpenGTL/GTLCore/String.h
    trunk/OpenGTL/OpenGTL/GTLCore/tests/TestString.h


Modified: trunk/OpenGTL/OpenGTL/GTLCore/String.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/String.cpp	2008-08-30 22:57:55 UTC (rev 327)
+++ trunk/OpenGTL/OpenGTL/GTLCore/String.cpp	2008-08-31 08:02:30 UTC (rev 328)
@@ -161,3 +161,8 @@
   result.push_back( substr( lastPos, length() - lastPos ) );
   return result;
 }
+
+bool String::startWith(const GTLCore::String& _sw) const
+{
+  return substr(0, _sw.size()) == _sw;
+}

Modified: trunk/OpenGTL/OpenGTL/GTLCore/String.h
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/String.h	2008-08-30 22:57:55 UTC (rev 327)
+++ trunk/OpenGTL/OpenGTL/GTLCore/String.h	2008-08-31 08:02:30 UTC (rev 328)
@@ -103,6 +103,10 @@
        * @return a list of \ref String
        */
       std::list<String> split( const std::list<String>& _separators, bool _allowEmpty = false) const;
+      /**
+       * @return true if this \ref String starts with \a _sw .
+       */
+      bool startWith(const GTLCore::String& _sw) const;
     public:
       String& operator=(char c);
     public:

Modified: trunk/OpenGTL/OpenGTL/GTLCore/tests/TestString.h
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/tests/TestString.h	2008-08-30 22:57:55 UTC (rev 327)
+++ trunk/OpenGTL/OpenGTL/GTLCore/tests/TestString.h	2008-08-31 08:02:30 UTC (rev 328)
@@ -98,6 +98,18 @@
     }
 };
 
+class TestStringSubstr : public GTLTest::Case {
+  public:
+    TestStringSubstr() : GTLTest::Case("Substr")
+    {
+    }
+    virtual void runTest()
+    {
+      GTLCore::String hello("Hello World");
+      GTLTEST_CHECK( hello.startWith("Hello") );
+      GTLTEST_CHECK( not hello.startWith("World") );
+    }
+};
 class TestString : public GTLTest::Suite {
   public:
     TestString() : GTLTest::Suite("String")
@@ -107,5 +119,6 @@
       addCase( new TestStringLowerUpper );
       addCase( new TestStringHeadTail );
       addCase( new TestStringSplit );
+      addCase( new TestStringSubstr );
     }
 };


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/