예제 #1
0
            /**
             * 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 );
            }
        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 );
            }


        }