public void Consume() { // null substring { Substring s= new Substring(); Substring r= new Substring("oldval"); UT_EQ( '\0', s.Consume ( ) ); UT_EQ( 0, s.Consume ( 0 , r) ); UT_TRUE(r.IsNull()); UT_EQ( 0, s.Consume ( 5 , r) ); UT_TRUE(r.IsNull()); UT_EQ( false, s.Consume ( 'a' ) ); UT_EQ( false, s.Consume ( "word" ) ); UT_EQ( '\0', s.ConsumeFromEnd( ) ); UT_EQ( 0, s.ConsumeFromEnd( 0 ) ); UT_EQ( 0, s.ConsumeFromEnd( 5 ) ); UT_EQ( false, s.ConsumeFromEnd( 'a' ) ); UT_EQ( false, s.ConsumeFromEnd( "word" ) ); } // empty substring { Substring s= new Substring("aaaaaaaaaaaa"); Substring r= new Substring("oldval"); s.Start= 5; s.End= 4; UT_EQ( '\0', s.Consume ( ) ); UT_EQ( 0, s.Consume ( 0 ,r ) ); UT_TRUE( r.IsNotNull()); UT_TRUE(r.IsEmpty()); UT_EQ( 0, s.Consume ( 5 ,r ) ); UT_TRUE( r.IsNotNull()); UT_TRUE(r.IsEmpty()); UT_EQ( false, s.Consume ( 'a' ) ); UT_EQ( false, s.Consume ( "word" ) ); UT_EQ( '\0', s.ConsumeFromEnd( ) ); UT_EQ( 0, s.ConsumeFromEnd( 0 ) ); UT_EQ( 0, s.ConsumeFromEnd( 5 ) ); UT_EQ( false, s.ConsumeFromEnd( 'a' ) ); UT_EQ( false, s.ConsumeFromEnd( "word" ) ); } // substring of length 1 { Substring s= new Substring("aaaaaaaaaaaa"); Substring r= new Substring("oldval"); s.Start= s.End= 5; UT_EQ( 'a', s.Consume ( ) ); UT_EQ( 0, s.Length() ); s.Start= s.End= 5; UT_EQ( 1, s.Consume ( 0 ) ); UT_EQ( 1, s.Length() ); s.Start= s.End= 5; UT_EQ( 0, s.Consume ( 1 , r ) ); UT_EQ( 0, s.Length() ); UT_TRUE(r.Equals("a")); s.Start= s.End= 5; UT_EQ( 0, s.Consume ( 5 , r ) ); UT_EQ( 0, s.Length() ); UT_TRUE(r.Equals("a")); s.Start= s.End= 5; UT_EQ( true, s.Consume ( 'a' ) ); UT_EQ( 0, s.Length() ); s.Start= s.End= 5; UT_EQ( false, s.Consume ( 'b' ) ); UT_EQ( 1, s.Length() ); s.Start= s.End= 5; UT_EQ( false, s.Consume ( "word" ) ); UT_EQ( 1, s.Length() ); s.Start= s.End= 5; UT_EQ( 'a', s.ConsumeFromEnd( ) ); UT_EQ( 0, s.Length() ); s.Start= s.End= 5; UT_EQ( 1, s.ConsumeFromEnd( 0 ) ); UT_EQ( 1, s.Length() ); s.Start= s.End= 5; UT_EQ( 0, s.ConsumeFromEnd( 1 ) ); UT_EQ( 0, s.Length() ); s.Start= s.End= 5; UT_EQ( 0, s.ConsumeFromEnd( 5 ) ); UT_EQ( 0, s.Length() ); s.Start= s.End= 5; UT_EQ( true, s.ConsumeFromEnd( 'a' ) ); UT_EQ( 0, s.Length() ); s.Start= s.End= 5; UT_EQ( false, s.ConsumeFromEnd( 'b' ) ); UT_EQ( 1, s.Length() ); s.Start= s.End= 5; UT_EQ( false, s.ConsumeFromEnd( "word" ) ); UT_EQ( 1, s.Length() ); } // substring of length 2 { Substring s= new Substring("12ab3456"); Substring r= new Substring("oldval"); s.Start= 2; s.End= 3; UT_EQ( 'a', s.Consume ( ) ); UT_EQ( 1, s.Length() ); UT_EQ( 'b', s.Consume ( ) ); UT_EQ( 0, s.Length() ); s.Start= 2; s.End= 3; UT_EQ( 'b', s.ConsumeFromEnd( ) ); UT_EQ( 1, s.Length() ); UT_EQ( 'a', s.ConsumeFromEnd( ) ); UT_EQ( 0, s.Length() ); s.Start= 2; s.End= 3; UT_EQ( 2, s.Consume ( 0 , r ) ); UT_EQ( 2, s.Length() ); UT_TRUE(r.IsNotNull()); UT_TRUE(r.IsEmpty()); s.Start= 2; s.End= 3; UT_EQ( 1, s.Consume ( 1 , r ) ); UT_EQ( 1, s.Length() ); UT_TRUE(r.Equals("a")); s.Start= 2; s.End= 3; UT_EQ( 0, s.Consume ( 2 , r ) ); UT_EQ( 0, s.Length() ); UT_TRUE(r.Equals("ab")); s.Start= 2; s.End= 3; UT_EQ( 0, s.Consume ( 3 , r ) ); UT_EQ( 0, s.Length() ); UT_TRUE(r.Equals("ab")); s.Start= 2; s.End= 3; UT_EQ( 2, s.ConsumeFromEnd( 0 , r ) ); UT_EQ( 2, s.Length() ); UT_TRUE(r.IsNotNull()); UT_TRUE(r.IsEmpty()); s.Start= 2; s.End= 3; UT_EQ( 1, s.ConsumeFromEnd( 1 , r ) ); UT_EQ( 1, s.Length() ); UT_TRUE(r.Equals("b")); s.Start= 2; s.End= 3; UT_EQ( 0, s.ConsumeFromEnd( 2 , r ) ); UT_EQ( 0, s.Length() ); UT_TRUE(r.Equals("ab")); s.Start= 2; s.End= 3; UT_EQ( 0, s.ConsumeFromEnd( 3 , r ) ); UT_EQ( 0, s.Length() ); UT_TRUE(r.Equals("ab")); s.Start= 2; s.End= 3; UT_EQ( false, s.Consume ( 'b' ) ); UT_EQ( 2, s.Length() ); UT_EQ( true, s.Consume ( 'a' ) ); UT_EQ( 1, s.Length() ); UT_EQ( true, s.Consume ( 'b' ) ); UT_EQ( 0, s.Length() ); UT_EQ( false, s.Consume ( 'a' ) ); UT_EQ( 0, s.Length() ); UT_EQ( false, s.Consume ( 'b' ) ); UT_EQ( 0, s.Length() ); s.Start= 2; s.End= 3; UT_EQ( false, s.ConsumeFromEnd( 'a' ) ); UT_EQ( 2, s.Length() ); UT_EQ( true, s.ConsumeFromEnd( 'b' ) ); UT_EQ( 1, s.Length() ); UT_EQ( true, s.ConsumeFromEnd( 'a' ) ); UT_EQ( 0, s.Length() ); UT_EQ( false, s.ConsumeFromEnd( 'b' ) ); UT_EQ( 0, s.Length() ); UT_EQ( false, s.ConsumeFromEnd( 'a' ) ); UT_EQ( 0, s.Length() ); s.Start= 2; s.End= 3; UT_EQ( false, s.Consume ( "word" ) ); UT_EQ( 2, s.Length() ); s.Start= 2; s.End= 3; UT_EQ( false, s.Consume ( "AB" ) ); UT_EQ( 2, s.Length() ); s.Start= 2; s.End= 3; UT_EQ( true, s.Consume ( "ab" ) ); UT_EQ( 0, s.Length() ); s.Start= 2; s.End= 3; UT_EQ( false, s.ConsumeFromEnd( "word" ) ); UT_EQ( 2, s.Length() ); s.Start= 2; s.End= 3; UT_EQ( false, s.ConsumeFromEnd( "AB" ) ); UT_EQ( 2, s.Length() ); s.Start= 2; s.End= 3; UT_EQ( true, s.ConsumeFromEnd( "ab" ) ); UT_EQ( 0, s.Length() ); } // 3 words { Substring s= new Substring("word1 word2 word3"); UT_EQ( 'w', s.Consume ( ) ); UT_EQ( 'o', s.Consume ( ) ); UT_EQ( 'r', s.Consume ( ) ); UT_EQ( 'd', s.Consume ( ) ); UT_EQ( '1', s.Consume ( ) ); UT_EQ( false , s.Consume ('w' ) ); UT_EQ( true , s.Consume ('w' , Case.Sensitive, Whitespaces.Trim ) ); UT_EQ( true , s.Consume ('o' , Case.Sensitive, Whitespaces.Trim ) ); UT_EQ( false , s.Consume ('o' , Case.Sensitive, Whitespaces.Trim ) ); UT_EQ( true , s.Consume ('r' , Case.Sensitive, Whitespaces.Trim ) ); UT_EQ( false , s.Consume ("D2" , Case.Sensitive, Whitespaces.Trim ) ); UT_EQ( false , s.Consume ("D2" ) ); UT_EQ( true , s.Consume ("d2" ) ); UT_EQ( 2 , s.Consume ( 4 ) ); UT_EQ( "d3" , s.ToString() ); s= new Substring("word1 word2 word3"); UT_EQ( '3', s.ConsumeFromEnd( ) ); UT_EQ( 'd', s.ConsumeFromEnd( ) ); UT_EQ( 'r', s.ConsumeFromEnd( ) ); UT_EQ( 'o', s.ConsumeFromEnd( ) ); UT_EQ( 'w', s.ConsumeFromEnd( ) ); UT_EQ( false , s.ConsumeFromEnd('2' ) ); UT_EQ( true , s.ConsumeFromEnd('2' , Case.Sensitive, Whitespaces.Trim ) ); UT_EQ( true , s.ConsumeFromEnd('d' , Case.Sensitive, Whitespaces.Trim ) ); UT_EQ( false , s.ConsumeFromEnd('d' , Case.Sensitive, Whitespaces.Trim ) ); UT_EQ( true , s.ConsumeFromEnd('r' , Case.Sensitive, Whitespaces.Trim ) ); UT_EQ( false , s.ConsumeFromEnd("WO" , Case.Sensitive, Whitespaces.Trim ) ); UT_EQ( false , s.ConsumeFromEnd("WO" ) ); UT_EQ( true , s.ConsumeFromEnd("wo" ) ); UT_EQ( 2 , s.ConsumeFromEnd( 4 ) ); UT_EQ( "wo" , s.ToString() ); } // consume AString, Substring { Substring s= new Substring("word1 word2 word3 word4"); Substring sConsume= new Substring( "1234word12", 4, 4 ); AString aConsume= new AString ( "word" ); UT_EQ( true, s.Consume ( sConsume ) ); UT_EQ( false, s.Consume ( sConsume ) ); UT_EQ( '1', s.Consume ( ) ); UT_EQ( false, s.Consume ( sConsume ) ); UT_EQ( true, s.Consume ( sConsume, Case.Sensitive, Whitespaces.Trim ) ); UT_EQ( '2', s.Consume ( ) ); UT_EQ( ' ', s.Consume ( ) ); UT_EQ( true, s.Consume ( aConsume ) ); UT_EQ( false, s.Consume ( aConsume ) ); UT_EQ( '3', s.Consume ( ) ); UT_EQ( false, s.Consume ( aConsume ) ); UT_EQ( true, s.Consume ( aConsume, Case.Sensitive, Whitespaces.Trim ) ); s.Set("1word 2word 3word 4word"); UT_EQ( true, s.ConsumeFromEnd( sConsume ) ); UT_EQ( false, s.ConsumeFromEnd( sConsume ) ); UT_EQ( '4', s.ConsumeFromEnd( ) ); UT_EQ( false, s.ConsumeFromEnd( sConsume ) ); UT_EQ( true, s.ConsumeFromEnd( sConsume, Case.Sensitive, Whitespaces.Trim ) ); UT_EQ( '3', s.ConsumeFromEnd( ) ); UT_EQ( ' ', s.ConsumeFromEnd( ) ); UT_EQ( true, s.ConsumeFromEnd( aConsume ) ); UT_EQ( false, s.ConsumeFromEnd( aConsume ) ); UT_EQ( '2', s.ConsumeFromEnd( ) ); UT_EQ( false, s.ConsumeFromEnd( aConsume ) ); UT_EQ( true, s.ConsumeFromEnd( aConsume, Case.Sensitive, Whitespaces.Trim ) ); } }