Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- struct ConfigReader
- {
- ConfigReader( const StringView& _it ) : it( _it.after_all( SPACE_CHARS ) ){}
- bool Read( StringView& key, StringView& value )
- {
- while( it.size() )
- {
- key = it.until_any( SPACE_CHARS );
- if( key.ch() == '#' )
- {
- it = it.after( "\n" ).after_all( SPACE_CHARS );
- continue;
- }
- it.skip( key.size() );
- it.after_all( HSPACE_CHARS );
- value = it.until( "\n" );
- it.skip( value.size() );
- value.trim( SPACE_CHARS );
- it = it.after_all( SPACE_CHARS );
- return key.size() != 0;
- }
- return false;
- }
- StringView it;
- };
- // usage code
- ConfigReader cr( text );
- StringView key, value;
- while( cr.Read( key, value ) )
- {
- if( key == "game" )
- {
- if( value.size() )
- {
- g_GameLibName = value;
- LOG << "CONFIG: Game library: " << value;
- }
- }
- else if( key == "dir" )
- {
- if( value.size() )
- {
- g_GameDir = value;
- LOG << "CONFIG: Game directory: " << value;
- }
- }
- else if( key == "dir2" )
- {
- if( value.size() )
- {
- g_GameDir2 = value;
- LOG << "CONFIG: Game directory #2: " << value;
- }
- }
- else if( key == "renderer" )
- {
- if( value.size() )
- {
- g_RendererName = value;
- LOG << "CONFIG: Renderer: " << value;
- }
- }
- else
- {
- LOG_WARNING << "Unknown key (" << key << " = " << value << ")";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement