aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/fstring.h18
-rw-r--r--src/unit/fstring.cpp21
2 files changed, 39 insertions, 0 deletions
diff --git a/src/fstring.h b/src/fstring.h
index b4cae3a..620b312 100644
--- a/src/fstring.h
+++ b/src/fstring.h
@@ -390,6 +390,24 @@ namespace Bu
390 return pFirst->pData; 390 return pFirst->pData;
391 } 391 }
392 392
393 MyType getSubStr( long iStart, long iSize=-1 ) const
394 {
395 if( iStart < 0 )
396 iStart = 0;
397 if( iStart >= nLength )
398 return "";
399 if( iSize < 0 )
400 iSize = nLength;
401 if( iStart+iSize > nLength )
402 iSize = nLength-iStart;
403 if( iSize == 0 )
404 return "";
405
406 flatten();
407 MyType ret( pFirst->pData+iStart, iSize );
408 return ret;
409 }
410
393 /** 411 /**
394 * (std::string compatability) Get a pointer to the string array. 412 * (std::string compatability) Get a pointer to the string array.
395 *@returns (chr *) The string data. 413 *@returns (chr *) The string data.
diff --git a/src/unit/fstring.cpp b/src/unit/fstring.cpp
index ea3342a..7be03a7 100644
--- a/src/unit/fstring.cpp
+++ b/src/unit/fstring.cpp
@@ -24,6 +24,8 @@ public:
24 addTest( Unit::add2 ); 24 addTest( Unit::add2 );
25 addTest( Unit::add3 ); 25 addTest( Unit::add3 );
26 addTest( Unit::add4 ); 26 addTest( Unit::add4 );
27 addTest( Unit::add5 );
28 addTest( Unit::subStr1 );
27 } 29 }
28 30
29 virtual ~Unit() 31 virtual ~Unit()
@@ -128,6 +130,25 @@ public:
128 130
129 unitTest( c == "hi there, yeah!" ); 131 unitTest( c == "hi there, yeah!" );
130 } 132 }
133
134 void add5()
135 {
136 Bu::FString b;
137 Bu::FString c = "sup?";
138 b += "hey, " + c;
139
140 unitTest( b == "hey, sup?" );
141 }
142
143 void subStr1()
144 {
145 Bu::FString a("abcdefghijklmnop");
146 unitTest( a.getSubStr( 5, 3 ) == "fgh" );
147 unitTest( a.getSubStr( 10 ) == "klmnop" );
148 unitTest( a.getSubStr( 40 ) == "" );
149 unitTest( a.getSubStr( -10 ) == "abcdefghijklmnop" );
150 unitTest( a.getSubStr( -15, 4 ) == "abcd" );
151 }
131}; 152};
132 153
133int main( int argc, char *argv[] ) 154int main( int argc, char *argv[] )