[opengtl-commits] [481] add a endWith function ( and fix startWith when use with a too big string)

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


Revision: 481
Author:   cyrille
Date:     2008-11-16 23:36:39 +0100 (Sun, 16 Nov 2008)

Log Message:
-----------
add a endWith function (and fix startWith when use with a too big 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-11-16 21:47:54 UTC (rev 480)
+++ trunk/OpenGTL/OpenGTL/GTLCore/String.cpp	2008-11-16 22:36:39 UTC (rev 481)
@@ -184,5 +184,12 @@
 
 bool String::startWith(const GTLCore::String& _sw) const
 {
+  if(_sw.length() > length() ) return false;
   return substr(0, _sw.size()) == _sw;
 }
+
+bool String::endWith(const GTLCore::String& _sw) const
+{
+  if(_sw.length() > length() ) return false;
+  return substr( length() - _sw.length(), _sw.length() ) == _sw;
+}

Modified: trunk/OpenGTL/OpenGTL/GTLCore/String.h
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/String.h	2008-11-16 21:47:54 UTC (rev 480)
+++ trunk/OpenGTL/OpenGTL/GTLCore/String.h	2008-11-16 22:36:39 UTC (rev 481)
@@ -107,6 +107,7 @@
        * @return true if this \ref String starts with \a _sw .
        */
       bool startWith(const GTLCore::String& _sw) const;
+      bool endWith(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-11-16 21:47:54 UTC (rev 480)
+++ trunk/OpenGTL/OpenGTL/GTLCore/tests/TestString.h	2008-11-16 22:36:39 UTC (rev 481)
@@ -108,6 +108,10 @@
       GTLCore::String hello("Hello World");
       GTLTEST_CHECK( hello.startWith("Hello") );
       GTLTEST_CHECK( not hello.startWith("World") );
+      GTLTEST_CHECK( not hello.startWith("Hellow World !") );
+      GTLTEST_CHECK( not hello.endWith("Hello") );
+      GTLTEST_CHECK( hello.endWith("World") );
+      GTLTEST_CHECK( not hello.endWith("Hellow World !") );
     }
 };
 class TestString : public GTLTest::Suite {


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