Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- json parseJsonFileWithComments( const std::string& path )
- {
- std::string str = util::getFileContents( path, true );
- std::string noComments = "";
- bool quote = false;
- bool escape = false;
- for ( int i = 0; i < str.length(); ++i )
- {
- char c = str[ i ];
- char n = i < str.length() - 1 ? str[ i + 1 ] : '\0';
- if ( escape )
- {
- noComments += c;
- escape = false;
- continue;
- }
- if ( quote )
- {
- if ( c == '\\' )
- {
- escape = true;
- continue;
- }
- }
- if ( c == '"' )
- quote = !quote;
- else if ( c == '/' && n == '/' )
- {
- i = str.find( '\n', i + 2 );
- continue;
- }
- else if ( c == '/' && n == '*' )
- {
- i = str.find( "*/", i + 2 ) + 2;
- continue;
- }
- noComments += c;
- }
- return json::parse( noComments );
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement