/** * Overrides default method. If we have not parsed the INI file text value, yet, * we do this now. * * @param parent The plug-in we belong to. * @param variable The variable to fill with our values. */ public override void ToVariable( InMemoryPlugin parent, Variable variable ) { // if we are still raw, then parse the INI file content if ( Values.Count == 0 ) { ALIB.ASSERT( Delim == '\0' ); Delim= variable.Delim; variable.Comments._()._( Comments ); //----- remove INI-File specific from raw value ----- AString raw= new AString(); raw._( RawValue ); // remove '=' raw.TrimStart(); if ( raw.CharAtStart() != '=' ) { ALIB.WARNING( "No equal sign in variable \"" + variable.Fullname + "\" of INI file." ); } else raw.DeleteStart(1).TrimStart(); // remove "\\n" int startIdx= 0; while ( (startIdx= raw.IndexOf( '\n', startIdx )) >= 0 ) { // find \\n and trim around this location int delLen= 2; if ( raw.CharAt( --startIdx) == '\r' ) { delLen= 3; --startIdx; } ALIB.ASSERT( raw.CharAt(startIdx) == '\\' ); raw.Delete( startIdx, delLen ); startIdx= raw.TrimAt( startIdx ); // if now the next value is starting with a comment symbol, we remove to the next \n for(;;) { char c= raw.CharAt( startIdx ); if ( c != '#' && c != ';' && ( c != '/' || raw.CharAt( startIdx + 1 ) != '/' ) ) break; int idx= raw.IndexOf( '\n' ); if (idx < 0 ) idx= raw.Length(); raw.Delete( startIdx, idx - startIdx + 1 ); if( startIdx >= raw.Length() ) break; startIdx= raw.TrimAt( startIdx ); } } // now convert parent.StringConverter.LoadFromString( variable, raw ); // copy the parsed values back to our entry and store the delimiter for( int i= 0; i < variable.Size() ; i++ ) Values.Add( new AString( variable.GetString( i ) ) ); } // otherwise, use base method else base.ToVariable( parent, variable ); }
/** **************************************************************************************** * Reads a prefix string from the ALib configuration system. * This internal method is used when a new domain is created, * * @param dom The domain to set the verbosity for. ******************************************************************************************/ protected void getDomainPrefixFromConfig( Domain dom ) { Variable variable= new Variable( ALox.PREFIXES, GetName() ); if( 0 == variable.Load() ) return; Tokenizer prefixTok= new Tokenizer(); Tokenizer prefixTokInner= new Tokenizer(); Substring domainStr= new Substring(); AString domainStrBuf= new AString(); Substring prefixStr= new Substring(); for( int varNo= 0; varNo< variable.Size(); varNo++ ) { prefixTok.Set( variable.GetString( varNo ), '=' ); domainStr.Set( prefixTok.Next() ); if ( domainStr.StartsWith( "INTERNAL_DOMAINS", DomainSensitivity ) ) { domainStrBuf._()._( domainStr.Buf, domainStr.Start + 16, domainStr.Length() -16 ); while ( domainStrBuf.CharAtStart() == '/' ) domainStrBuf.DeleteStart( 1 ); domainStrBuf.InsertAt( ALox.InternalDomains, 0 ); domainStr.Set( domainStrBuf ); } prefixTokInner.Set( prefixTok.Next(), ',' ); prefixStr.Set( prefixTokInner.Next() ); if ( prefixStr.IsEmpty() ) continue; if ( prefixStr.Consume( '\"' ) ) prefixStr.ConsumeFromEnd( '\"' ); Inclusion otherPLs= Inclusion.Include; prefixTokInner.Next(); if ( prefixTokInner.Actual.IsNotEmpty() ) otherPLs= ALIB.ReadInclusion( prefixTokInner.Actual ); int searchMode= 0; if ( domainStr.Consume ( '*' ) ) searchMode+= 2; if ( domainStr.ConsumeFromEnd( '*' ) ) searchMode+= 1; if( ( searchMode == 0 && dom.FullPath.Equals ( domainStr, DomainSensitivity ) ) || ( searchMode == 1 && dom.FullPath.StartsWith ( domainStr, DomainSensitivity ) ) || ( searchMode == 2 && dom.FullPath.EndsWith ( domainStr, DomainSensitivity ) ) || ( searchMode == 3 && dom.FullPath.IndexOf ( domainStr, 0, DomainSensitivity ) >=0 ) ) { dom.PrefixLogables.Add( new Domain.PL( new AString( prefixStr ), otherPLs ) ); // log info on this intMsg._()._NC( "String \"" )._NC( prefixStr )._NC ( "\" added as prefix logable for domain \'" ) ._NC( dom.FullPath ) ._NC( "\'. (Retrieved from variable" ) ._NC( variable.Fullname )._( ".)" ); logInternal( Verbosity.Info, "PFX", intMsg ); } } }
public void DeleteInsertSet() { AString ms= new AString(); // delete { ms.Clear()._("0123456789"); ms.Delete ( 5 ); UT_EQ( "01234", ms ); ms.Clear()._("0123456789"); ms.Delete ( 5, 0 ); UT_EQ( "0123456789", ms ); ms.Clear()._("0123456789"); ms.Delete ( 5, -1 ); UT_EQ( "0123456789", ms ); ms.Clear()._("0123456789"); ms.Delete ( 5, 1 ); UT_EQ( "012346789", ms ); ms.Clear()._("0123456789"); ms.Delete ( 5, 100 ); UT_EQ( "01234", ms ); ms.Clear()._("0123456789"); ms.Delete ( -5, 10 ); UT_EQ( "56789", ms ); ms.Clear()._("0123456789"); ms.Delete_NC ( 5, 5 ); UT_EQ( "01234", ms ); ms.Clear()._("0123456789"); ms.Delete_NC ( 0, 5 ); UT_EQ( "56789", ms ); ms.Clear()._("0123456789"); ms.Delete_NC ( 0, 1 ); UT_EQ( "123456789", ms ); ms.Clear()._("0123456789"); ms.Delete_NC ( 9, 1 ); UT_EQ( "012345678", ms ); ms.Clear()._("0123456789"); ms.DeleteStart ( -2 ); UT_EQ( "0123456789", ms ); ms.Clear()._("0123456789"); ms.DeleteStart ( -1 ); UT_EQ( "0123456789", ms ); ms.Clear()._("0123456789"); ms.DeleteStart ( 0 ); UT_EQ( "0123456789", ms ); ms.Clear()._("0123456789"); ms.DeleteStart ( 1 ); UT_EQ( "123456789", ms ); ms.Clear()._("0123456789"); ms.DeleteStart ( 2 ); UT_EQ( "23456789", ms ); ms.Clear()._("0123456789"); ms.DeleteStart ( 9 ); UT_EQ( "9", ms ); ms.Clear()._("0123456789"); ms.DeleteStart ( 10 ); UT_EQ( "", ms ); ms.Clear()._("0123456789"); ms.DeleteStart ( 11 ); UT_EQ( "", ms ); ms.Clear()._("0123456789"); ms.DeleteStart_NC ( 0 ); UT_EQ( "0123456789", ms ); ms.Clear()._("0123456789"); ms.DeleteStart_NC ( 1 ); UT_EQ( "123456789", ms ); ms.Clear()._("0123456789"); ms.DeleteStart_NC ( 2 ); UT_EQ( "23456789", ms ); ms.Clear()._("0123456789"); ms.DeleteStart_NC ( 9 ); UT_EQ( "9", ms ); ms.Clear()._("0123456789"); ms.DeleteStart_NC ( 10 ); UT_EQ( "", ms ); ms.Clear()._("0123456789"); ms.DeleteEnd ( -2 ); UT_EQ( "0123456789", ms ); ms.Clear()._("0123456789"); ms.DeleteEnd ( -1 ); UT_EQ( "0123456789", ms ); ms.Clear()._("0123456789"); ms.DeleteEnd ( 0 ); UT_EQ( "0123456789", ms ); ms.Clear()._("0123456789"); ms.DeleteEnd ( 1 ); UT_EQ( "012345678" , ms ); ms.Clear()._("0123456789"); ms.DeleteEnd ( 2 ); UT_EQ( "01234567" , ms ); ms.Clear()._("0123456789"); ms.DeleteEnd ( 9 ); UT_EQ( "0" , ms ); ms.Clear()._("0123456789"); ms.DeleteEnd ( 10 ); UT_EQ( "" , ms ); ms.Clear()._("0123456789"); ms.DeleteEnd ( 11 ); UT_EQ( "" , ms ); ms.Clear()._("0123456789"); ms.DeleteEnd_NC ( 0 ); UT_EQ( "0123456789", ms ); ms.Clear()._("0123456789"); ms.DeleteEnd_NC ( 1 ); UT_EQ( "012345678" , ms ); ms.Clear()._("0123456789"); ms.DeleteEnd_NC ( 2 ); UT_EQ( "01234567" , ms ); ms.Clear()._("0123456789"); ms.DeleteEnd_NC ( 9 ); UT_EQ( "0" , ms ); ms.Clear()._("0123456789"); ms.DeleteEnd_NC ( 10 ); UT_EQ( "" , ms ); } // insertChars { ms.Clear()._("0123456789"); ms.InsertChars ( ' ', 1, -1 ); UT_EQ( "0123456789", ms ); ms.Clear()._("0123456789"); ms.InsertChars ( ' ', 1, 20 ); UT_EQ( "0123456789", ms ); ms.Clear()._("0123456789"); ms.InsertChars ( ' ', 0, 0 ); UT_EQ( "0123456789", ms ); ms.Clear()._("0123456789"); ms.InsertChars ( ' ', 1, 0 ); UT_EQ( " 0123456789", ms ); ms.Clear()._("0123456789"); ms.InsertChars ( ' ', 1, 1 ); UT_EQ( "0 123456789", ms ); ms.Clear()._("0123456789"); ms.InsertChars ( ' ', 2, 0 ); UT_EQ( " 0123456789", ms ); ms.Clear()._("0123456789"); ms.InsertChars ( ' ', 2, 1 ); UT_EQ( "0 123456789", ms ); ms.Clear()._("0123456789"); ms.InsertChars ( ' ', 1, 11 ); UT_EQ( "0123456789", ms ); ms.Clear()._("0123456789"); ms.InsertChars ( ' ', 1, 10 ); UT_EQ( "0123456789 ", ms ); ms.Clear()._("0123456789"); ms.InsertChars ( '@', 3, 5 ); UT_EQ( "01234@@@56789",ms ); } // InsertAt { ms.Clear()._("0123456789"); ms.InsertAt ( "TST", -2 ); UT_EQ( "0123456789", ms ); ms.Clear()._("0123456789"); ms.InsertAt ( "TST", -1 ); UT_EQ( "0123456789", ms ); ms.Clear()._("0123456789"); ms.InsertAt ( "TST", 0 ); UT_EQ( "TST0123456789", ms ); ms.Clear()._("0123456789"); ms.InsertAt ( "TST", 1 ); UT_EQ( "0TST123456789", ms ); ms.Clear()._("0123456789"); ms.InsertAt ( "TST", 8 ); UT_EQ( "01234567TST89", ms ); ms.Clear()._("0123456789"); ms.InsertAt ( "TST", 9 ); UT_EQ( "012345678TST9", ms ); ms.Clear()._("0123456789"); ms.InsertAt ( "TST", 10 ); UT_EQ( "0123456789TST", ms ); ms.Clear()._("0123456789"); ms.InsertAt ( "TST", 11 ); UT_EQ( "0123456789", ms ); ms.Clear()._("0123456789"); ms.InsertAt ( "TST", 12 ); UT_EQ( "0123456789", ms ); AString astr= new AString( "TST" ); ms.Clear()._("0123456789"); ms.InsertAt ( astr , -2 ); UT_EQ( "0123456789", ms ); ms.Clear()._("0123456789"); ms.InsertAt ( astr , -1 ); UT_EQ( "0123456789", ms ); ms.Clear()._("0123456789"); ms.InsertAt ( astr , 0 ); UT_EQ( "TST0123456789", ms ); ms.Clear()._("0123456789"); ms.InsertAt ( astr , 1 ); UT_EQ( "0TST123456789", ms ); ms.Clear()._("0123456789"); ms.InsertAt ( astr , 8 ); UT_EQ( "01234567TST89", ms ); ms.Clear()._("0123456789"); ms.InsertAt ( astr , 9 ); UT_EQ( "012345678TST9", ms ); ms.Clear()._("0123456789"); ms.InsertAt ( astr , 10 ); UT_EQ( "0123456789TST", ms ); ms.Clear()._("0123456789"); ms.InsertAt ( astr , 11 ); UT_EQ( "0123456789", ms ); ms.Clear()._("0123456789"); ms.InsertAt ( astr , 12 ); UT_EQ( "0123456789", ms ); Substring subs= new Substring( "0123TSTxyz".ToCharArray(), 4, 3 ); ms.Clear()._("0123456789"); ms.InsertAt ( subs , -2 ); UT_EQ( "0123456789", ms ); ms.Clear()._("0123456789"); ms.InsertAt ( subs , -1 ); UT_EQ( "0123456789", ms ); ms.Clear()._("0123456789"); ms.InsertAt ( subs , 0 ); UT_EQ( "TST0123456789", ms ); ms.Clear()._("0123456789"); ms.InsertAt ( subs , 1 ); UT_EQ( "0TST123456789", ms ); ms.Clear()._("0123456789"); ms.InsertAt ( subs , 8 ); UT_EQ( "01234567TST89", ms ); ms.Clear()._("0123456789"); ms.InsertAt ( subs , 9 ); UT_EQ( "012345678TST9", ms ); ms.Clear()._("0123456789"); ms.InsertAt ( subs , 10 ); UT_EQ( "0123456789TST", ms ); ms.Clear()._("0123456789"); ms.InsertAt ( subs , 11 ); UT_EQ( "0123456789", ms ); ms.Clear()._("0123456789"); ms.InsertAt ( subs , 12 ); UT_EQ( "0123456789", ms ); } // ReplaceSubstring { String r= "ABC"; ms.Clear()._("0123456789"); ms.ReplaceSubstring( r, 0, 10) ; UT_EQ( "ABC", ms ); ms.Clear()._("0123456789"); ms.ReplaceSubstring( r, -10, 100) ; UT_EQ( "0123456789", ms ); ms.Clear()._("0123456789"); ms.ReplaceSubstring( r, -10, 5 ) ; UT_EQ( "0123456789", ms ); ms.Clear()._("0123456789"); ms.ReplaceSubstring( r, -10, 10 ) ; UT_EQ( "0123456789", ms ); ms.Clear()._("0123456789"); ms.ReplaceSubstring( r, -10, 11 ) ; UT_EQ( "0123456789", ms ); ms.Clear()._("0123456789"); ms.ReplaceSubstring( r, 0, 1 ) ; UT_EQ( "ABC123456789", ms ); ms.Clear()._("0123456789"); ms.ReplaceSubstring( r, 0, 2 ) ; UT_EQ( "ABC23456789", ms ); ms.Clear()._("0123456789"); ms.ReplaceSubstring( r, 1, 1 ) ; UT_EQ( "0ABC23456789", ms ); ms.Clear()._("0123456789"); ms.ReplaceSubstring( r, 1, 2 ) ; UT_EQ( "0ABC3456789", ms ); ms.Clear()._("0123456789"); ms.ReplaceSubstring( r, 8, 1 ) ; UT_EQ( "01234567ABC9", ms ); ms.Clear()._("0123456789"); ms.ReplaceSubstring( r, 8, 2 ) ; UT_EQ( "01234567ABC", ms ); ms.Clear()._("0123456789"); ms.ReplaceSubstring( r, 8, 3 ) ; UT_EQ( "0123456789", ms ); Substring s= new Substring( "0123ABCxyz".ToCharArray(), 4, 3 ); ms.Clear()._("0123456789"); ms.ReplaceSubstring( s, 0, 10) ; UT_EQ( "ABC", ms ); ms.Clear()._("0123456789"); ms.ReplaceSubstring( s, -10, 100) ; UT_EQ( "0123456789", ms ); ms.Clear()._("0123456789"); ms.ReplaceSubstring( s, -10, 5 ) ; UT_EQ( "0123456789", ms ); ms.Clear()._("0123456789"); ms.ReplaceSubstring( s, -10, 10 ) ; UT_EQ( "0123456789", ms ); ms.Clear()._("0123456789"); ms.ReplaceSubstring( s, -10, 11 ) ; UT_EQ( "0123456789", ms ); ms.Clear()._("0123456789"); ms.ReplaceSubstring( s, 0, 1 ) ; UT_EQ( "ABC123456789", ms ); ms.Clear()._("0123456789"); ms.ReplaceSubstring( s, 0, 2 ) ; UT_EQ( "ABC23456789", ms ); ms.Clear()._("0123456789"); ms.ReplaceSubstring( s, 1, 1 ) ; UT_EQ( "0ABC23456789", ms ); ms.Clear()._("0123456789"); ms.ReplaceSubstring( s, 1, 2 ) ; UT_EQ( "0ABC3456789", ms ); ms.Clear()._("0123456789"); ms.ReplaceSubstring( s, 8, 1 ) ; UT_EQ( "01234567ABC9", ms ); ms.Clear()._("0123456789"); ms.ReplaceSubstring( s, 8, 2 ) ; UT_EQ( "01234567ABC", ms ); ms.Clear()._("0123456789"); ms.ReplaceSubstring( s, 8, 3 ) ; UT_EQ( "0123456789", ms ); } // ReplaceRegion { ms.Clear()._("0123456789"); ms.ReplaceRegion ( '@', 0, 10 ); UT_EQ( "@@@@@@@@@@", ms ); ms.Clear()._("0123456789"); ms.ReplaceRegion ( '@', -10, 100 ); UT_EQ( "@@@@@@@@@@", ms ); ms.Clear()._("0123456789"); ms.ReplaceRegion ( '@', -10, 5 ); UT_EQ( "0123456789", ms ); ms.Clear()._("0123456789"); ms.ReplaceRegion ( '@', -10, 10 ); UT_EQ( "0123456789", ms ); ms.Clear()._("0123456789"); ms.ReplaceRegion ( '@', -10, 11 ); UT_EQ( "@123456789", ms ); ms.Clear()._("0123456789"); ms.ReplaceRegion ( '@', 0, 1 ); UT_EQ( "@123456789", ms ); ms.Clear()._("0123456789"); ms.ReplaceRegion ( '@', 0, 2 ); UT_EQ( "@@23456789", ms ); ms.Clear()._("0123456789"); ms.ReplaceRegion ( '@', 1, 1 ); UT_EQ( "0@23456789", ms ); ms.Clear()._("0123456789"); ms.ReplaceRegion ( '@', 1, 2 ); UT_EQ( "0@@3456789", ms ); ms.Clear()._("0123456789"); ms.ReplaceRegion ( '@', 8, 1 ); UT_EQ( "01234567@9", ms ); ms.Clear()._("0123456789"); ms.ReplaceRegion ( '@', 8, 2 ); UT_EQ( "01234567@@", ms ); ms.Clear()._("0123456789"); ms.ReplaceRegion ( '@', 8, 3 ); UT_EQ( "01234567@@", ms ); } }
/** **************************************************************************************** * Reads the verbosity for the given logger and domain from the ALib configuration system. * This internal method is used in two occasions: * - when a new logger is added: recursively for all existing domains (\p configStr is * given) * - when a new domain is created on the fly(\p configStr is not given) * * @param logger The logger to set the verbosity for. * @param dom The domain to set the verbosity for. * @param variable The (already read) variable to set verbosities from. ******************************************************************************************/ protected void getVerbosityFromConfig( Logger logger, Domain dom, Variable variable ) { // get logger number. It may happen that the logger is not existent in this domain tree. int loggerNo= dom.GetLoggerNo( logger ) ; if ( loggerNo < 0 ) return; Tokenizer verbosityTknzr= new Tokenizer(); Substring domainStr= new Substring(); AString domainStrBuf= new AString(); for( int varNo= 0; varNo< variable.Size(); varNo++ ) { verbosityTknzr.Set( variable.GetString( varNo ), '=' ); domainStr.Set( verbosityTknzr.Next() ); if ( domainStr.StartsWith( "INTERNAL_DOMAINS", DomainSensitivity ) ) { domainStrBuf._()._( domainStr.Buf, domainStr.Start + 16, domainStr.Length() -16 ); while ( domainStrBuf.CharAtStart() == '/' ) domainStrBuf.DeleteStart( 1 ); domainStrBuf.InsertAt( ALox.InternalDomains, 0 ); domainStr.Set( domainStrBuf ); } Substring verbosityStr= verbosityTknzr.Next(); if ( verbosityStr.IsEmpty() ) continue; int searchMode= 0; if ( domainStr.Consume ( '*' ) ) searchMode+= 2; if ( domainStr.ConsumeFromEnd( '*' ) ) searchMode+= 1; if( ( searchMode == 0 && dom.FullPath.Equals ( domainStr, DomainSensitivity ) ) || ( searchMode == 1 && dom.FullPath.StartsWith ( domainStr, DomainSensitivity ) ) || ( searchMode == 2 && dom.FullPath.EndsWith ( domainStr, DomainSensitivity ) ) || ( searchMode == 3 && dom.FullPath.IndexOf ( domainStr, 0, DomainSensitivity ) >=0 ) ) { Verbosity verbosity= ALox.ReadVerbosity( verbosityStr); dom.SetVerbosity( loggerNo, verbosity, variable.Priority ); // log info on this intMsg._()._NC( "Logger \"" )._NC( logger.GetName() ) ._NC( "\":" ).Tab(11 + maxLoggerNameLength) ._( '\'' )._NC( dom.FullPath ) ._( '\'' ).InsertChars(' ', maxDomainPathLength - dom.FullPath.Length() + 1 ) ._("= Verbosity." ); ALox.ToString( verbosity, dom.GetPriority(loggerNo), intMsg ).TrimEnd() ._('.'); logInternal( Verbosity.Info, "LGR", intMsg ); } } }