// ############################################################################################# // Internals // ############################################################################################# /** **************************************************************************************** * Internal, recursive helper of #Find. * * @param domainPath Path to search. * @param sensitivity Denotes if domain name search is treated case sensitive or not. * @param maxCreate The maximum number of sub domains that are created if not * found at the end of the path. * @param[out] wasCreated Output parameter that is set \c true if domain was not found * and hence created. * @return The domain found or created. ******************************************************************************************/ protected Domain findRecursive( Substring domainPath, Case sensitivity, int maxCreate, ref bool wasCreated ) { //--- get act sub-name and rest of path domainPath.Consume( Separator ); int endSubName= domainPath.IndexOf( Separator ); ALIB.ASSERT_ERROR( endSubName != 0, "Internal Error" ); // find end of actual domain name and save rest Substring restOfDomainPath= tSubstring2; restOfDomainPath.SetNull(); if ( endSubName > 0 ) domainPath.Split( endSubName, restOfDomainPath, 1 ); // search sub-domain Domain subDomain= null; // "." if( domainPath.Equals( "." ) ) subDomain= this; // ".." else if( domainPath.Equals( ".." ) ) subDomain= Parent != null ? Parent : this; // search in sub-domain else { int i; bool fixedOnce= false; for(;;) { for( i= 0; i< SubDomains.Count; i++ ) { int comparison= SubDomains[i].Name.CompareTo( domainPath, sensitivity ); if( comparison >= 0 ) { if ( comparison == 0 ) subDomain= SubDomains[i]; break; } } // domain found? if ( subDomain != null ) break; // try and fix name if( !fixedOnce ) { fixedOnce= true; bool illegalCharacterFound= false; for( int cp= 0; cp< domainPath.Length() ; ++cp ) { char c= domainPath.CharAt(cp); if ( c < '-' || c > 'z' || c == '<' || c == '>' || c == '[' || c == ']' || c == '=' || c == '?' || c == ';' || c == ':' || c == '\\'|| c == '\''|| c == '.' || c == ',' ) { illegalCharacterFound= true; domainPath.Buf[domainPath.Start + cp]= '#'; } } if ( illegalCharacterFound ) continue; } // create if ( maxCreate == 0 ) return null; wasCreated= true; SubDomains.Insert( i, subDomain= new Domain( this, new AString( domainPath ) ) ); maxCreate--; if ( maxCreate == 0 ) return subDomain; break; } } // recursion? if ( restOfDomainPath.IsNotEmpty() ) { domainPath.Set( restOfDomainPath ); return subDomain.findRecursive( domainPath, sensitivity, maxCreate, ref wasCreated ); } // that's it return subDomain; }
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 ) ); } }
public void CompareTo() { Substring tss= new Substring(); // null string comparison String nullString= null; UT_TRUE( tss.CompareTo( nullString) == 0 ); UT_TRUE( tss.Equals( nullString) ); tss.Set( "" ); UT_TRUE( tss.CompareTo( nullString) != 0 ); UT_TRUE( !tss.Equals( nullString) ); tss.SetNull(); UT_TRUE( tss.CompareTo( nullString) == 0 ); UT_TRUE( tss.Equals( nullString) ); String t= "abcde"; tss= new Substring("01"+t+"234", 2, t.Length ); int result, resSys; result= tss.CompareTo( t ); UT_EQ( t.CompareTo( t ), result ); result= tss.CompareTo( t + "x" ); UT_EQ( t.CompareTo( t + "x" ), result ); result= tss.CompareTo( t.Substring (0, t.Length -1 ) ); UT_EQ( t.CompareTo( t.Substring (0, t.Length -1 ) ), result ); result= tss.CompareTo( "pad" + t, Case.Sensitive, 3 ); UT_EQ( 0, result ); result= tss.CompareTo( "pad" + t, Case.Sensitive, 3, 2 ); UT_EQ( 1, result ); // greater/smaller strings { String greater= "x"; String greater2= "abcdef"; String smaller= "aaa"; String smaller2= "abcd"; result= tss.CompareTo( greater ); resSys= t.CompareTo( greater ); UT_TRUE( result==resSys || (result < 0 && resSys < 0) || (result > 0 && resSys > 0) ); result= tss.CompareTo( greater2 ); resSys= t.CompareTo( greater2 ); UT_TRUE( result==resSys || (result < 0 && resSys < 0) || (result > 0 && resSys > 0) ); result= tss.CompareTo( smaller ); resSys= t.CompareTo( smaller ); UT_TRUE( result==resSys || (result < 0 && resSys < 0) || (result > 0 && resSys > 0) ); result= tss.CompareTo( smaller2 ); resSys= t.CompareTo( smaller2 ); UT_TRUE( result==resSys || (result < 0 && resSys < 0) || (result > 0 && resSys > 0) ); String ut= t.ToUpper(); UT_FALSE( 0 == tss.CompareTo( ut ) ); UT_FALSE( 0 == tss.CompareTo( ut, Case.Sensitive )); UT_TRUE ( 0 == tss.CompareTo( ut, Case.Ignore )); } { AString greater= new AString( "x" ); AString greater2= new AString( "abcdef" ); AString smaller= new AString( "aaa" ); AString smaller2= new AString( "abcd" ); result= tss.CompareTo( greater ); resSys= t.CompareTo( greater .ToString() ); UT_TRUE( result==resSys || (result < 0 && resSys < 0) || (result > 0 && resSys > 0) ); result= tss.CompareTo( greater2 ); resSys= t.CompareTo( greater2 .ToString() ); UT_TRUE( result==resSys || (result < 0 && resSys < 0) || (result > 0 && resSys > 0) ); result= tss.CompareTo( smaller ); resSys= t.CompareTo( smaller .ToString() ); UT_TRUE( result==resSys || (result < 0 && resSys < 0) || (result > 0 && resSys > 0) ); result= tss.CompareTo( smaller2 ); resSys= t.CompareTo( smaller2 .ToString() ); UT_TRUE( result==resSys || (result < 0 && resSys < 0) || (result > 0 && resSys > 0) ); AString ut= new AString (t.ToUpper()); UT_FALSE( 0 == tss.CompareTo( ut ) ); UT_FALSE( 0 == tss.CompareTo( ut, Case.Sensitive )); UT_TRUE ( 0 == tss.CompareTo( ut, Case.Ignore )); } { Substring greater= new Substring( "123x" , 3 ); Substring greater2= new Substring( "123abcdef" , 3 ); Substring smaller= new Substring( "123aaa" , 3 ); Substring smaller2= new Substring( "123abcd" , 3 ); result= tss.CompareTo( greater ); resSys= t.CompareTo( greater .ToString() ); UT_TRUE( result==resSys || (result < 0 && resSys < 0) || (result > 0 && resSys > 0) ); result= tss.CompareTo( greater2 ); resSys= t.CompareTo( greater2 .ToString() ); UT_TRUE( result==resSys || (result < 0 && resSys < 0) || (result > 0 && resSys > 0) ); result= tss.CompareTo( smaller ); resSys= t.CompareTo( smaller .ToString() ); UT_TRUE( result==resSys || (result < 0 && resSys < 0) || (result > 0 && resSys > 0) ); result= tss.CompareTo( smaller2 ); resSys= t.CompareTo( smaller2 .ToString() ); UT_TRUE( result==resSys || (result < 0 && resSys < 0) || (result > 0 && resSys > 0) ); Substring ut= new Substring( t.ToUpper() ); UT_FALSE( 0 == tss.CompareTo( ut ) ); UT_FALSE( 0 == tss.CompareTo( ut, Case.Sensitive )); UT_TRUE ( 0 == tss.CompareTo( ut, Case.Ignore )); } }
/** **************************************************************************************** * Implements functionality for configuration variable \c LOXNAME_DUMP_STATE_ON_EXIT. * Is called when a logger is removed. ******************************************************************************************/ protected void dumpStateOnLoggerRemoval() { if( !loggerAddedSinceLastDebugState ) return; loggerAddedSinceLastDebugState= false; Variable variable= new Variable( ALox.DUMP_STATE_ON_EXIT, GetName() ); variable.Load(); String domain= null; Verbosity verbosity= Verbosity.Info; Substring tok= new Substring(); int flags= 0; for( int tokNo= 0; tokNo< variable.Size(); tokNo++ ) { tok.Set( variable.GetString( tokNo ) ); if( tok.IsEmpty() ) continue; // state flags if( tok.Equals( "NONE" , Case.Ignore ) ) { flags= 0; break; } else if( tok.Equals( "Basic" , Case.Ignore ) ) flags|= (int) Lox.StateInfo.Basic ; else if( tok.Equals( "Version" , Case.Ignore ) ) flags|= (int) Lox.StateInfo.Version ; else if( tok.Equals( "Loggers" , Case.Ignore ) ) flags|= (int) Lox.StateInfo.Loggers ; else if( tok.Equals( "Domains" , Case.Ignore ) ) flags|= (int) Lox.StateInfo.Domains ; else if( tok.Equals( "InternalDomains" , Case.Ignore ) ) flags|= (int) Lox.StateInfo.InternalDomains ; else if( tok.Equals( "ScopeDomains" , Case.Ignore ) ) flags|= (int) Lox.StateInfo.ScopeDomains ; else if( tok.Equals( "DSR" , Case.Ignore ) ) flags|= (int) Lox.StateInfo.DSR ; else if( tok.Equals( "PrefixLogables" , Case.Ignore ) ) flags|= (int) Lox.StateInfo.PrefixLogables ; else if( tok.Equals( "Once" , Case.Ignore ) ) flags|= (int) Lox.StateInfo.Once ; else if( tok.Equals( "LogData" , Case.Ignore ) ) flags|= (int) Lox.StateInfo.LogData ; else if( tok.Equals( "ThreadMappings" , Case.Ignore ) ) flags|= (int) Lox.StateInfo.ThreadMappings ; else if( tok.Equals( "SPTR" , Case.Ignore ) ) flags|= (int) Lox.StateInfo.SPTR ; else if( tok.Equals( "All" , Case.Ignore ) ) flags|= (int) Lox.StateInfo.All ; // domain and verbosity else if( tok.Consume( "domain", Case.Ignore, Whitespaces.Trim ) ) { if( tok.Consume( '=', Case.Sensitive, Whitespaces.Trim ) ) domain= tok.Trim().ToString(); } else if( tok.Consume( "verbosity", Case.Ignore, Whitespaces.Trim ) ) { if( tok.Consume( '=', Case.Sensitive, Whitespaces.Trim ) ) verbosity= ALox.ReadVerbosity( tok.Trim() ); } // unknown argument else { logInternal( Verbosity.Error, "VAR", intMsg._() ._( "Unknown argument '" )._(tok) ._( "' in variable " )._(variable.Fullname)._( " = \"")._(variable.GetString())._('\"') ); } } if ( flags != 0 ) { State( domain, verbosity, "Auto dump state on exit requested: ", (Lox.StateInfo) flags ); } }