示例#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 );
            }