public void IsNull() { AString ms = new AString(); UT_TRUE( ms.Capacity() == 0 ); UT_TRUE( ms.IsNull() ); UT_TRUE( !ms.IsNotNull() ); UT_TRUE( ms.IsEmpty() ); UT_TRUE( !ms.IsNotEmpty() ); ms._(""); UT_TRUE( ms.Capacity() != 0 ); UT_TRUE( !ms.IsNull() ); UT_TRUE( ms.IsNotNull() ); UT_TRUE( ms.IsEmpty() ); UT_TRUE( !ms.IsNotEmpty() ); ms._("x"); UT_TRUE( ms.Capacity() != 0 ); UT_TRUE( !ms.IsNull() ); UT_TRUE( ms.IsNotNull() ); UT_TRUE( !ms.IsEmpty() ); UT_TRUE( ms.IsNotEmpty() ); ms.SetNull(); UT_TRUE( ms.Capacity() == 0 ); UT_TRUE( ms.IsNull() ); UT_TRUE( !ms.IsNotNull() ); UT_TRUE( ms.IsEmpty() ); UT_TRUE( !ms.IsNotEmpty() ); ms._(""); UT_TRUE( ms.Capacity() != 0 ); UT_TRUE( !ms.IsNull() ); UT_TRUE( ms.IsNotNull() ); UT_TRUE( ms.IsEmpty() ); UT_TRUE( !ms.IsNotEmpty() ); ms._("x"); UT_TRUE( ms.Capacity() != 0 ); UT_TRUE( !ms.IsNull() ); UT_TRUE( ms.IsNotNull() ); UT_TRUE( !ms.IsEmpty() ); UT_TRUE( ms.IsNotEmpty() ); ms.SetNull(); UT_TRUE( ms.Capacity() == 0 ); UT_TRUE( ms.IsNull() ); UT_TRUE( !ms.IsNotNull() ); UT_TRUE( ms.IsEmpty() ); UT_TRUE( !ms.IsNotEmpty() ); ms.SetBuffer(5); UT_TRUE( ms.Capacity() != 0 ); UT_TRUE( !ms.IsNull() ); UT_TRUE( ms.IsNotNull() ); UT_TRUE( ms.IsEmpty() ); UT_TRUE( !ms.IsNotEmpty() ); ms._("x"); UT_TRUE( ms.Capacity() != 0 ); UT_TRUE( !ms.IsNull() ); UT_TRUE( ms.IsNotNull() ); UT_TRUE( !ms.IsEmpty() ); UT_TRUE( ms.IsNotEmpty() ); }
public void _() { // append char[] { AString ms= new AString(); char[] csNull= null; char[] csEmpty= "".ToCharArray(); ms._( csNull ); UT_EQ ( ms.Length(), 0 ); UT_TRUE( ms.IsNull() ); ms._( csEmpty); UT_EQ ( ms.Length(), 0 ); UT_TRUE( ms.IsNotNull() ); ms.SetNull(); UT_EQ ( ms.Length(), 0 ); UT_TRUE( ms.IsNull() ); ms._("1234567".ToCharArray()); UT_EQ ( ms.Capacity(), 16 ); UT_EQ( "1234567", ms ); ms._("89" .ToCharArray()); UT_TRUE( ms.Length()> 7 ); UT_EQ( "123456789", ms ); char[] t= "0123456789".ToCharArray(); ms.Clear()._ ( t, 5); UT_EQ( ms, "56789" ); ms.Clear()._ ( t, 5, 100); UT_EQ( ms, "56789" ); ms.Clear()._ ( t, -5); UT_EQ( ms, "0123456789" ); ms.Clear()._ ( t, -5, 3); UT_EQ( ms, "" ); ms.Clear()._ ( t, 50, 3); UT_EQ( ms, "" ); ms.Clear()._ ( t, 10, 3); UT_EQ( ms, "" ); ms.Clear()._ ( t, -5, 10); UT_EQ( ms, "01234" ); ms.Clear()._ ( t, -5, 100); UT_EQ( ms, "0123456789" ); // _NC ms.SetNull(); UT_EQ ( ms.Length(), 0 ); UT_TRUE( ms.IsNull() ); ms._NC( csEmpty,0,0); UT_EQ ( ms.Length(), 0 ); UT_TRUE( ms.IsNull() ); ms.Clear()._NC( t, 5,3); UT_EQ( ms, "567" ); } // append AString { AString ms= new AString(); AString asNull= null; AString asEmpty= new AString(""); AString t= new AString( "012" ); ms._( asNull ); UT_EQ ( ms.Length(), 0 ); UT_TRUE( ms.IsNull() ); ms._( asEmpty); UT_EQ ( ms.Length(), 0 ); UT_TRUE( ms.IsNotNull() ); ms.SetNull(); UT_EQ ( ms.Length(), 0 ); UT_TRUE( ms.IsNull() ); ms._( t ); UT_EQ ( ms.Capacity(), 16 ); UT_EQ( "012" , ms ); ms._( t ); UT_TRUE( ms.Length()> 3 ); UT_EQ( "012012", ms ); t.Clear()._( "0123456789" ); ms.Clear()._ ( t, 5); UT_EQ( ms, "56789" ); ms.Clear()._ ( t, 5, 100); UT_EQ( ms, "56789" ); ms.Clear()._ ( t, -5); UT_EQ( ms, "0123456789" ); ms.Clear()._ ( t, -5, 3); UT_EQ( ms, "" ); ms.Clear()._ ( t, 50, 3); UT_EQ( ms, "" ); ms.Clear()._ ( t, 10, 3); UT_EQ( ms, "" ); ms.Clear()._ ( t, -5, 10); UT_EQ( ms, "01234" ); ms.Clear()._ ( t, -5, 100); UT_EQ( ms, "0123456789" ); ms.Clear()._NC( t ); UT_EQ( ms, "0123456789" ); ms.Clear()._NC( t, 1, 9 ); UT_EQ( ms, "123456789" ); ms.Clear()._NC( t, 1, 2 ); UT_EQ( ms, "12" ); ms.Clear()._NC( t, 1, 8 ); UT_EQ( ms, "12345678" ); ms.Clear()._NC( t, 1, 9 ); UT_EQ( ms, "123456789" ); ms.Clear()._NC( t, 5, 5 ); UT_EQ( ms, "56789" ); // _NC ms.SetNull(); UT_EQ ( ms.Length(), 0 ); UT_TRUE( ms.IsNull() ); ms._NC( asEmpty); UT_EQ ( ms.Length(), 0 ); UT_TRUE( ms.IsNull() ); ms.Clear()._NC( t, 5, 3); UT_EQ( ms, "567" ); } // append Substring { AString ms= new AString(); Substring ssNull= null; Substring ssEmpty= new Substring( "" ); Substring t= new Substring( "01234" ); ms._( ssNull ); UT_EQ ( ms.Length(), 0 ); UT_TRUE( ms.IsNull() ); ms._( ssEmpty); UT_EQ ( ms.Length(), 0 ); UT_TRUE( ms.IsNotNull() ); ms.SetNull(); UT_EQ ( ms.Length(), 0 ); UT_TRUE( ms.IsNull() ); ms._( t ); UT_EQ ( ms.Capacity(), 16 ); UT_EQ( "01234" , ms ); ms._( t ); UT_TRUE( ms.Length()> 5 ); UT_EQ( "0123401234", ms ); t.Consume(); ms.Clear()._( t ); UT_EQ( ms, "1234" ); t.Consume(); ms.Clear()._( t ); UT_EQ( ms, "234" ); t.ConsumeFromEnd(); ms.Clear()._( t ); UT_EQ( ms, "23" ); // _NC ms.SetNull(); UT_EQ ( ms.Length(), 0 ); UT_TRUE( ms.IsNull() ); ms._NC( ssEmpty ); UT_EQ ( ms.Length(), 0 ); UT_TRUE( ms.IsNull() ); ms.Clear()._NC( t); UT_EQ( ms, "23" ); } // append String { AString ms= new AString(); String sEmpty= ""; String t= "012"; ms._( sEmpty); UT_EQ ( ms.Length(), 0 ); UT_TRUE( ms.IsNotNull() ); ms.SetNull(); UT_EQ ( ms.Length(), 0 ); UT_TRUE( ms.IsNull() ); ms._( t ); UT_EQ ( ms.Capacity(), 16 ); UT_EQ( "012" , ms ); ms._( t ); UT_TRUE( ms.Length()> 3 ); UT_EQ( "012012", ms ); t= "0123456789"; ms.Clear()._( t, 5); UT_EQ( ms, "56789" ); ms.Clear()._( t, 5, 100); UT_EQ( ms, "56789" ); ms.Clear()._( t, -5); UT_EQ( ms, "0123456789" ); ms.Clear()._( t, -5, 3); UT_EQ( ms, "" ); ms.Clear()._( t, 50, 3); UT_EQ( ms, "" ); ms.Clear()._( t, 10, 3); UT_EQ( ms, "" ); ms.Clear()._( t, -5, 10); UT_EQ( ms, "01234" ); ms.Clear()._( t, -5, 100); UT_EQ( ms, "0123456789" ); // _NC ms.SetNull(); UT_EQ ( ms.Length(), 0 ); UT_TRUE( ms.IsNull() ); ms._NC( sEmpty ); UT_EQ ( ms.Length(), 0 ); UT_TRUE( ms.IsNull() ); ms.Clear()._NC( t); UT_EQ( ms, "0123456789" ); ms.Clear()._NC( t ,2,3); UT_EQ( ms, "234" ); } // append String Builders { AString ms= new AString(); StringBuilder t= new StringBuilder( "012"); ms._( t ); UT_EQ ( ms.Capacity(), 16 ); UT_EQ( "012" , ms ); ms._( t ); UT_TRUE( ms.Length()> 3 ); UT_EQ( "012012", ms ); t.Clear().Append("0123456789"); ms.Clear()._( t, 5); UT_EQ( ms, "56789" ); ms.Clear()._( t, 5, 100); UT_EQ( ms, "56789" ); ms.Clear()._( t, -5); UT_EQ( ms, "0123456789" ); ms.Clear()._( t, -5, 3); UT_EQ( ms, "" ); ms.Clear()._( t, 50, 3); UT_EQ( ms, "" ); ms.Clear()._( t, 10, 3); UT_EQ( ms, "" ); ms.Clear()._( t, -5, 10); UT_EQ( ms, "01234" ); ms.Clear()._( t, -5, 100); UT_EQ( ms, "0123456789" ); } }
/** **************************************************************************************** * Tests and returns true, if the given AString equals to what this object * represents. True is returned if both are zero length or \c null. * * @param compareString The %AString that is compared to this %AString. * @param sensitivity Case sensitivity of the comparison. * Optional and defaults to Case.Sensitive. * * @return true, if contents of this and the given %AString are equal ******************************************************************************************/ public bool Equals( AString compareString, Case sensitivity= Case.Sensitive ) { // null? if ( compareString == null || compareString.IsNull() ) return IsNull(); // same length? if ( compareString.Length() != Length() ) return false; return ContainsAt( compareString, 0, sensitivity ); }