changed: names of methods in SpaceParser: PascalCase to snake_case

This commit is contained in:
Tomasz Sowa 2021-05-21 04:42:55 +02:00
parent 6e4a0f68b3
commit c11aa78335
2 changed files with 185 additions and 189 deletions

View File

@ -72,7 +72,7 @@ int SpaceParser::get_last_parsed_line()
SpaceParser::Status SpaceParser::ParseJSONFile(const char * file_name, Space & out_space, bool clear_space) SpaceParser::Status SpaceParser::parse_json_file(const char * file_name, Space & out_space, bool clear_space)
{ {
reading_from_file = true; reading_from_file = true;
parsing_space = false; parsing_space = false;
@ -83,7 +83,7 @@ SpaceParser::Status SpaceParser::ParseJSONFile(const char * file_name, Space & o
if( file ) if( file )
{ {
ParseRootSpace(clear_space); parse_root_space(clear_space);
file.close(); file.close();
} }
else else
@ -96,34 +96,34 @@ return status;
SpaceParser::Status SpaceParser::ParseJSONFile(const std::string & file_name, Space & out_space, bool clear_space) SpaceParser::Status SpaceParser::parse_json_file(const std::string & file_name, Space & out_space, bool clear_space)
{ {
return ParseJSONFile(file_name.c_str(), out_space, clear_space); return parse_json_file(file_name.c_str(), out_space, clear_space);
} }
SpaceParser::Status SpaceParser::ParseJSONFile(const wchar_t * file_name, Space & out_space, bool clear_space) SpaceParser::Status SpaceParser::parse_json_file(const wchar_t * file_name, Space & out_space, bool clear_space)
{ {
std::string file_name_utf8; std::string file_name_utf8;
wide_to_utf8(file_name, file_name_utf8); wide_to_utf8(file_name, file_name_utf8);
return ParseJSONFile(file_name_utf8.c_str(), out_space, clear_space); return parse_json_file(file_name_utf8.c_str(), out_space, clear_space);
} }
SpaceParser::Status SpaceParser::ParseJSONFile(const std::wstring & file_name, Space & out_space, bool clear_space) SpaceParser::Status SpaceParser::parse_json_file(const std::wstring & file_name, Space & out_space, bool clear_space)
{ {
return ParseJSONFile(file_name.c_str(), out_space, clear_space); return parse_json_file(file_name.c_str(), out_space, clear_space);
} }
SpaceParser::Status SpaceParser::ParseSpaceFile(const char * file_name, Space & out_space, bool clear_space) SpaceParser::Status SpaceParser::parse_space_file(const char * file_name, Space & out_space, bool clear_space)
{ {
reading_from_file = true; reading_from_file = true;
parsing_space = true; parsing_space = true;
@ -134,7 +134,7 @@ SpaceParser::Status SpaceParser::ParseSpaceFile(const char * file_name, Space &
if( file ) if( file )
{ {
ParseRootSpace(clear_space); parse_root_space(clear_space);
file.close(); file.close();
} }
else else
@ -147,32 +147,32 @@ return status;
SpaceParser::Status SpaceParser::ParseSpaceFile(const std::string & file_name, Space & out_space, bool clear_space) SpaceParser::Status SpaceParser::parse_space_file(const std::string & file_name, Space & out_space, bool clear_space)
{ {
return ParseSpaceFile(file_name.c_str(), out_space, clear_space); return parse_space_file(file_name.c_str(), out_space, clear_space);
} }
SpaceParser::Status SpaceParser::ParseSpaceFile(const wchar_t * file_name, Space & out_space, bool clear_space) SpaceParser::Status SpaceParser::parse_space_file(const wchar_t * file_name, Space & out_space, bool clear_space)
{ {
std::string file_name_utf8; std::string file_name_utf8;
wide_to_utf8(file_name, file_name_utf8); wide_to_utf8(file_name, file_name_utf8);
return ParseSpaceFile(file_name_utf8.c_str(), out_space, clear_space); return parse_space_file(file_name_utf8.c_str(), out_space, clear_space);
} }
SpaceParser::Status SpaceParser::ParseSpaceFile(const std::wstring & file_name, Space & out_space, bool clear_space) SpaceParser::Status SpaceParser::parse_space_file(const std::wstring & file_name, Space & out_space, bool clear_space)
{ {
return ParseSpaceFile(file_name.c_str(), out_space, clear_space); return parse_space_file(file_name.c_str(), out_space, clear_space);
} }
SpaceParser::Status SpaceParser::ParseJSON(const char * str, Space & out_space, bool clear_space) SpaceParser::Status SpaceParser::parse_json(const char * str, Space & out_space, bool clear_space)
{ {
reading_from_file = false; reading_from_file = false;
reading_from_wchar_string = false; reading_from_wchar_string = false;
@ -181,19 +181,19 @@ SpaceParser::Status SpaceParser::ParseJSON(const char * str, Space & out_space,
parsing_space = false; parsing_space = false;
root_space = &out_space; root_space = &out_space;
ParseRootSpace(clear_space); parse_root_space(clear_space);
return status; return status;
} }
SpaceParser::Status SpaceParser::ParseJSON(const std::string & str, Space & out_space, bool clear_space) SpaceParser::Status SpaceParser::parse_json(const std::string & str, Space & out_space, bool clear_space)
{ {
return ParseJSON(str.c_str(), out_space, clear_space); return parse_json(str.c_str(), out_space, clear_space);
} }
SpaceParser::Status SpaceParser::ParseJSON(const wchar_t * str, Space & out_space, bool clear_space) SpaceParser::Status SpaceParser::parse_json(const wchar_t * str, Space & out_space, bool clear_space)
{ {
reading_from_file = false; reading_from_file = false;
reading_from_wchar_string = true; reading_from_wchar_string = true;
@ -202,22 +202,22 @@ SpaceParser::Status SpaceParser::ParseJSON(const wchar_t * str, Space & out_spac
parsing_space = false; parsing_space = false;
root_space = &out_space; root_space = &out_space;
ParseRootSpace(clear_space); parse_root_space(clear_space);
return status; return status;
} }
SpaceParser::Status SpaceParser::ParseJSON(const std::wstring & str, Space & out_space, bool clear_space) SpaceParser::Status SpaceParser::parse_json(const std::wstring & str, Space & out_space, bool clear_space)
{ {
return ParseJSON(str.c_str(), out_space, clear_space); return parse_json(str.c_str(), out_space, clear_space);
} }
SpaceParser::Status SpaceParser::ParseSpace(const char * str, Space & out_space, bool clear_space) SpaceParser::Status SpaceParser::parse_space(const char * str, Space & out_space, bool clear_space)
{ {
reading_from_file = false; reading_from_file = false;
reading_from_wchar_string = false; reading_from_wchar_string = false;
@ -226,19 +226,19 @@ SpaceParser::Status SpaceParser::ParseSpace(const char * str, Space & out_space,
parsing_space = true; parsing_space = true;
root_space = &out_space; root_space = &out_space;
ParseRootSpace(clear_space); parse_root_space(clear_space);
return status; return status;
} }
SpaceParser::Status SpaceParser::ParseSpace(const std::string & str, Space & out_space, bool clear_space) SpaceParser::Status SpaceParser::parse_space(const std::string & str, Space & out_space, bool clear_space)
{ {
return ParseSpace(str.c_str(), out_space, clear_space); return parse_space(str.c_str(), out_space, clear_space);
} }
SpaceParser::Status SpaceParser::ParseSpace(const wchar_t * str, Space & out_space, bool clear_space) SpaceParser::Status SpaceParser::parse_space(const wchar_t * str, Space & out_space, bool clear_space)
{ {
reading_from_file = false; reading_from_file = false;
reading_from_wchar_string = true; reading_from_wchar_string = true;
@ -247,22 +247,22 @@ SpaceParser::Status SpaceParser::ParseSpace(const wchar_t * str, Space & out_spa
parsing_space = true; parsing_space = true;
root_space = &out_space; root_space = &out_space;
ParseRootSpace(clear_space); parse_root_space(clear_space);
return status; return status;
} }
SpaceParser::Status SpaceParser::ParseSpace(const std::wstring & str, Space & out_space, bool clear_space) SpaceParser::Status SpaceParser::parse_space(const std::wstring & str, Space & out_space, bool clear_space)
{ {
return ParseSpace(str.c_str(), out_space, clear_space); return parse_space(str.c_str(), out_space, clear_space);
} }
void SpaceParser::ParseRootSpace(bool clear_root_space) void SpaceParser::parse_root_space(bool clear_root_space)
{ {
line = 1; line = 1;
status = ok; status = ok;
@ -272,24 +272,24 @@ void SpaceParser::ParseRootSpace(bool clear_root_space)
root_space->set_empty_object(); root_space->set_empty_object();
} }
ReadChar(); // put first character to lastc read_char(); // put first character to lastc
if( parsing_space ) if( parsing_space )
{ {
separator = '='; separator = '=';
table_start = '('; table_start = '(';
table_end = ')'; table_end = ')';
ParseSpace(root_space); parse_space(root_space);
} }
else else
{ {
separator = ':'; separator = ':';
table_start = '['; table_start = '[';
table_end = ']'; table_end = ']';
Parse(root_space, false, false); parse(root_space, false, false);
} }
SkipWhite(); skip_white();
if( lastc != -1 ) if( lastc != -1 )
status = syntax_error; status = syntax_error;
@ -298,27 +298,27 @@ void SpaceParser::ParseRootSpace(bool clear_root_space)
} }
void SpaceParser::Parse(Space * space, bool is_object_value, bool is_table_value) void SpaceParser::parse(Space * space, bool is_object_value, bool is_table_value)
{ {
SkipWhite(); skip_white();
if( lastc == space_start ) if( lastc == space_start )
{ {
ParseSpace(space); parse_space(space);
} }
else else
if( lastc == table_start ) if( lastc == table_start )
{ {
ParseTable(space); parse_table(space);
} }
else else
if( lastc == '"' ) // IMPROVEME define a variable if( lastc == '"' ) // IMPROVEME define a variable
{ {
ParseTextValue(space); parse_text_value(space);
} }
else else
{ {
ReadStringValue(token, is_object_value, is_table_value); read_string_value(token, is_object_value, is_table_value);
if( token == L"null" ) if( token == L"null" )
{ {
@ -337,12 +337,12 @@ void SpaceParser::Parse(Space * space, bool is_object_value, bool is_table_value
else else
if( is_integer_token() ) if( is_integer_token() )
{ {
ParseIntegerValue(space); parse_integer_value(space);
} }
else else
if( is_floating_point_token() ) if( is_floating_point_token() )
{ {
ParseFloatingPointValue(space); parse_floating_point_value(space);
} }
else else
{ {
@ -362,7 +362,7 @@ void SpaceParser::Parse(Space * space, bool is_object_value, bool is_table_value
void SpaceParser::ParseSpace(Space * space) void SpaceParser::parse_space(Space * space)
{ {
/* /*
* in Space format in global namespace the space start character is not required * in Space format in global namespace the space start character is not required
@ -371,19 +371,19 @@ void SpaceParser::ParseSpace(Space * space)
if( need_space_start_character ) if( need_space_start_character )
{ {
ReadChar(); // inserting a next character after the space_start char to lastc read_char(); // inserting a next character after the space_start char to lastc
} }
if( !space->is_object() ) if( !space->is_object() )
space->set_empty_object(); space->set_empty_object();
ParseKeyValuePairs(space); parse_key_value_pairs(space);
if( need_space_start_character ) if( need_space_start_character )
{ {
if( lastc == space_end ) if( lastc == space_end )
{ {
ReadChar(); read_char();
} }
else else
{ {
@ -396,19 +396,19 @@ void SpaceParser::ParseSpace(Space * space)
void SpaceParser::ParseTextValue(Space * space) void SpaceParser::parse_text_value(Space * space)
{ {
space->set_empty_wstring(); space->set_empty_wstring();
std::wstring * str = space->get_wstr(); std::wstring * str = space->get_wstr();
if( parsing_space ) if( parsing_space )
ReadMultilineTokenQuoted(*str); read_multiline_token_quoted(*str);
else else
ReadTokenQuoted(*str); read_token_quoted(*str);
} }
void SpaceParser::ParseIntegerValue(Space * space) void SpaceParser::parse_integer_value(Space * space)
{ {
const wchar_t * after_str = nullptr; const wchar_t * after_str = nullptr;
bool was_overflow = false; bool was_overflow = false;
@ -440,7 +440,7 @@ void SpaceParser::ParseIntegerValue(Space * space)
} }
void SpaceParser::ParseFloatingPointValue(Space * space) void SpaceParser::parse_floating_point_value(Space * space)
{ {
wchar_t * after_str = nullptr; wchar_t * after_str = nullptr;
double val = wcstod(token.c_str(), &after_str); double val = wcstod(token.c_str(), &after_str);
@ -463,15 +463,15 @@ void SpaceParser::ParseFloatingPointValue(Space * space)
void SpaceParser::ParseTable(Space * space) void SpaceParser::parse_table(Space * space)
{ {
ReadChar(); // inserting a next character after the table_start char to lastc read_char(); // inserting a next character after the table_start char to lastc
space->set_empty_table(); space->set_empty_table();
ParseValuesList(space); parse_values_list(space);
if( lastc == table_end ) if( lastc == table_end )
{ {
ReadChar(); read_char();
} }
else else
{ {
@ -482,25 +482,25 @@ void SpaceParser::ParseTable(Space * space)
void SpaceParser::ParseKeyValuePairs(Space * space) void SpaceParser::parse_key_value_pairs(Space * space)
{ {
bool is_first = true; bool is_first = true;
SkipWhite(); skip_white();
while( status == ok && lastc != space_end && lastc != -1 ) while( status == ok && lastc != space_end && lastc != -1 )
{ {
if( !is_first ) if( !is_first )
{ {
SkipWhite(); skip_white();
if( lastc == option_delimiter ) if( lastc == option_delimiter )
{ {
ReadChar(); // inserting a next character after the option_delimiter to lastc read_char(); // inserting a next character after the option_delimiter to lastc
if( parsing_space ) if( parsing_space )
{ {
// in space format a space_end character is allowed to be after the last table item // in space format a space_end character is allowed to be after the last table item
SkipWhite(); skip_white();
if( lastc == space_end ) if( lastc == space_end )
break; break;
@ -516,24 +516,24 @@ void SpaceParser::ParseKeyValuePairs(Space * space)
if( status == ok ) if( status == ok )
{ {
ReadKey(); read_key();
if( status == ok ) if( status == ok )
{ {
SkipWhite(); skip_white();
if( lastc == separator ) if( lastc == separator )
{ {
ReadChar(); // inserting a next character after the separator to lastc read_char(); // inserting a next character after the separator to lastc
Space & new_space = space->add(token.c_str(), new Space()); Space & new_space = space->add(token.c_str(), new Space());
Parse(&new_space, true, false); parse(&new_space, true, false);
} }
else else
if( parsing_space && lastc == space_start ) if( parsing_space && lastc == space_start )
{ {
Space & new_space = space->add_child_space(token.c_str()); Space & new_space = space->add_child_space(token.c_str());
ParseSpace(&new_space); parse_space(&new_space);
} }
else else
{ {
@ -543,32 +543,32 @@ void SpaceParser::ParseKeyValuePairs(Space * space)
} }
is_first = false; is_first = false;
SkipWhite(); skip_white();
} }
} }
void SpaceParser::ParseValuesList(Space * space) void SpaceParser::parse_values_list(Space * space)
{ {
bool is_first = true; bool is_first = true;
SkipWhite(); skip_white();
while( status == ok && lastc != table_end && lastc != -1 ) while( status == ok && lastc != table_end && lastc != -1 )
{ {
if( !is_first ) if( !is_first )
{ {
SkipWhite(); skip_white();
if( lastc == option_delimiter ) // may add a new delimiter for tables? default the same as for objects... if( lastc == option_delimiter ) // may add a new delimiter for tables? default the same as for objects...
{ {
ReadChar(); // inserting a next character after the delimiter read_char(); // inserting a next character after the delimiter
if( parsing_space ) if( parsing_space )
{ {
// in space format a table_end character is allowed to be after the last table item // in space format a table_end character is allowed to be after the last table item
SkipWhite(); skip_white();
if( lastc == table_end ) if( lastc == table_end )
break; break;
@ -585,11 +585,11 @@ void SpaceParser::ParseValuesList(Space * space)
if( status == ok ) if( status == ok )
{ {
Space * new_space = &space->add(new Space()); Space * new_space = &space->add(new Space());
Parse(new_space, false, true); parse(new_space, false, true);
} }
is_first = false; is_first = false;
SkipWhite(); skip_white();
} }
} }
@ -686,14 +686,14 @@ bool SpaceParser::is_floating_point_token()
bool SpaceParser::IsWhite(int c) bool SpaceParser::is_white(int c)
{ {
// 13 (\r) is at the end of a line in a dos file \r\n // 13 (\r) is at the end of a line in a dos file \r\n
// 160 is an unbreakable space // 160 is an unbreakable space
if( c==' ' || c=='\t' || c==13 || c==160 || c==10 ) if( c==' ' || c=='\t' || c==13 || c==160 || c==10 )
return true; return true;
return false; return false;
} }
@ -706,41 +706,41 @@ bool SpaceParser::is_alfa_numeric_char(int c)
} }
void SpaceParser::SkipLine() void SpaceParser::skip_line()
{ {
while( lastc != -1 && (char_was_escaped || lastc != '\n') ) while( lastc != -1 && (char_was_escaped || lastc != '\n') )
ReadChar(); read_char();
} }
void SpaceParser::SkipWhite() void SpaceParser::skip_white()
{ {
if( parsing_space ) if( parsing_space )
{ {
while( IsWhite(lastc) || (!char_was_escaped && lastc == '#') ) while( is_white(lastc) || (!char_was_escaped && lastc == '#') )
{ {
if( lastc == '#' ) if( lastc == '#' )
SkipLine(); skip_line();
else else
ReadChar(); read_char();
} }
} }
else else
{ {
while( IsWhite(lastc) ) while( is_white(lastc) )
{ {
ReadChar(); read_char();
} }
} }
} }
void SpaceParser::TrimLastWhite(std::wstring & s) void SpaceParser::trim_last_white(std::wstring & s)
{ {
std::wstring::size_type i; std::wstring::size_type i;
for(i=s.size() ; i>0 && IsWhite(s[i-1]) ; --i) for(i=s.size() ; i>0 && is_white(s[i-1]) ; --i)
{ {
} }
@ -752,86 +752,86 @@ void SpaceParser::TrimLastWhite(std::wstring & s)
void SpaceParser::ReadTokenUntilDelimiter(std::wstring & token, int delimiter1, int delimiter2) void SpaceParser::read_token_until_delimiter(std::wstring & token, int delimiter1, int delimiter2)
{ {
token.clear(); token.clear();
while( lastc != -1 && (char_was_escaped || (lastc != '\n' && lastc != '#' && lastc != delimiter1 && lastc != delimiter2)) ) while( lastc != -1 && (char_was_escaped || (lastc != '\n' && lastc != '#' && lastc != delimiter1 && lastc != delimiter2)) )
{ {
token += static_cast<wchar_t>(lastc); token += static_cast<wchar_t>(lastc);
ReadChar(); read_char();
} }
TrimLastWhite(token); trim_last_white(token);
} }
void SpaceParser::ReadAlfaNumericToken(std::wstring & token) void SpaceParser::read_alfa_numeric_token(std::wstring & token)
{ {
token.clear(); token.clear();
while( is_alfa_numeric_char(lastc) ) while( is_alfa_numeric_char(lastc) )
{ {
token += static_cast<wchar_t>(lastc); token += static_cast<wchar_t>(lastc);
ReadChar(); read_char();
} }
} }
void SpaceParser::ReadStringValue(std::wstring & token, bool is_object_value, bool is_table_value) void SpaceParser::read_string_value(std::wstring & token, bool is_object_value, bool is_table_value)
{ {
if( parsing_space ) if( parsing_space )
{ {
if( is_object_value ) if( is_object_value )
{ {
ReadTokenUntilDelimiter(token, space_end, -1); read_token_until_delimiter(token, space_end, -1);
} }
else else
if( is_table_value ) if( is_table_value )
{ {
ReadTokenUntilDelimiter(token, table_end, option_delimiter); read_token_until_delimiter(token, table_end, option_delimiter);
} }
else else
{ {
ReadTokenUntilDelimiter(token, -1, -1); read_token_until_delimiter(token, -1, -1);
} }
} }
else else
{ {
ReadAlfaNumericToken(token); read_alfa_numeric_token(token);
} }
} }
void SpaceParser::ReadSpaceFieldToken(std::wstring & token) void SpaceParser::read_space_field_token(std::wstring & token)
{ {
token.clear(); token.clear();
while( lastc != -1 && (char_was_escaped || (lastc != separator && lastc != 10 && lastc != space_start && lastc != '#' )) ) while( lastc != -1 && (char_was_escaped || (lastc != separator && lastc != 10 && lastc != space_start && lastc != '#' )) )
{ {
token += static_cast<wchar_t>(lastc); token += static_cast<wchar_t>(lastc);
ReadChar(); read_char();
} }
TrimLastWhite(token); trim_last_white(token);
} }
// IMPROVEME in JSON we should not allow non-escaped a new line character // IMPROVEME in JSON we should not allow non-escaped a new line character
void SpaceParser::ReadTokenQuoted(std::wstring & token) void SpaceParser::read_token_quoted(std::wstring & token)
{ {
token.clear(); token.clear();
ReadChar(); // skipping the first quotation mark read_char(); // skipping the first quotation mark
while( lastc != -1 && (char_was_escaped || (lastc != '"' && lastc != 10)) ) while( lastc != -1 && (char_was_escaped || (lastc != '"' && lastc != 10)) )
{ {
token += static_cast<wchar_t>(lastc); token += static_cast<wchar_t>(lastc);
ReadChar(); read_char();
} }
if( !char_was_escaped && lastc == '"' ) if( !char_was_escaped && lastc == '"' )
{ {
ReadChar(); // skipping the last quotation mark read_char(); // skipping the last quotation mark
} }
else else
{ {
@ -840,20 +840,20 @@ void SpaceParser::ReadTokenQuoted(std::wstring & token)
} }
void SpaceParser::ReadMultilineTokenQuoted(std::wstring & token) void SpaceParser::read_multiline_token_quoted(std::wstring & token)
{ {
token.clear(); token.clear();
ReadChar(); // skipping the first quotation mark read_char(); // skipping the first quotation mark
while( lastc != -1 && (char_was_escaped || lastc != '"') ) while( lastc != -1 && (char_was_escaped || lastc != '"') )
{ {
token += static_cast<wchar_t>(lastc); token += static_cast<wchar_t>(lastc);
ReadChar(); read_char();
} }
if( !char_was_escaped && lastc == '"' ) if( !char_was_escaped && lastc == '"' )
{ {
ReadChar(); // skipping the last quotation mark read_char(); // skipping the last quotation mark
} }
else else
{ {
@ -866,26 +866,26 @@ void SpaceParser::ReadMultilineTokenQuoted(std::wstring & token)
* this method is used to read the field name (key) in an object * this method is used to read the field name (key) in an object
* or to read the space child name (used in Space format) * or to read the space child name (used in Space format)
*/ */
void SpaceParser::ReadKey() void SpaceParser::read_key()
{ {
SkipWhite(); skip_white();
if( parsing_space ) if( parsing_space )
{ {
if( lastc == '"' ) if( lastc == '"' )
{ {
ReadMultilineTokenQuoted(token); read_multiline_token_quoted(token);
} }
else else
{ {
ReadSpaceFieldToken(token); read_space_field_token(token);
} }
} }
else else
{ {
if( lastc == '"' ) if( lastc == '"' )
{ {
ReadTokenQuoted(token); read_token_quoted(token);
} }
else else
{ {
@ -897,7 +897,7 @@ void SpaceParser::ReadKey()
int SpaceParser::ReadUTF8Char() int SpaceParser::read_utf8_char()
{ {
int c; int c;
bool correct; bool correct;
@ -923,7 +923,7 @@ return lastc;
int SpaceParser::ReadASCIIChar() int SpaceParser::read_ascii_char()
{ {
lastc = file.get(); lastc = file.get();
@ -936,7 +936,7 @@ return lastc;
int SpaceParser::ReadCharFromWcharString() int SpaceParser::read_char_from_wchar_string()
{ {
if( *pchar_unicode == 0 ) if( *pchar_unicode == 0 )
lastc = -1; lastc = -1;
@ -950,7 +950,7 @@ return lastc;
} }
int SpaceParser::ReadCharFromUTF8String() int SpaceParser::read_char_from_utf8_string()
{ {
int c; int c;
bool correct; bool correct;
@ -975,7 +975,7 @@ return lastc;
} }
int SpaceParser::ReadCharFromAsciiString() int SpaceParser::read_char_from_ascii_string()
{ {
if( *pchar_ascii == 0 ) if( *pchar_ascii == 0 )
lastc = -1; lastc = -1;
@ -989,32 +989,32 @@ return lastc;
} }
int SpaceParser::ReadCharNoEscape() int SpaceParser::read_char_no_escape()
{ {
if( reading_from_file ) if( reading_from_file )
{ {
if( input_as_utf8 ) if( input_as_utf8 )
return ReadUTF8Char(); return read_utf8_char();
else else
return ReadASCIIChar(); return read_ascii_char();
} }
else else
{ {
if( reading_from_wchar_string ) if( reading_from_wchar_string )
{ {
return ReadCharFromWcharString(); return read_char_from_wchar_string();
} }
else else
{ {
if( input_as_utf8 ) if( input_as_utf8 )
return ReadCharFromUTF8String(); return read_char_from_utf8_string();
else else
return ReadCharFromAsciiString(); return read_char_from_ascii_string();
} }
} }
} }
bool SpaceParser::IsHexDigit(wchar_t c) bool SpaceParser::is_hex_digit(wchar_t c)
{ {
return ((c>='0' && c<='9') || return ((c>='0' && c<='9') ||
(c>='a' && c<='f') || (c>='a' && c<='f') ||
@ -1022,7 +1022,7 @@ bool SpaceParser::IsHexDigit(wchar_t c)
} }
int SpaceParser::HexToInt(wchar_t c) int SpaceParser::hex_to_int(wchar_t c)
{ {
if( c>='0' && c<='9' ) if( c>='0' && c<='9' )
return c - '0'; return c - '0';
@ -1037,37 +1037,37 @@ return 0;
} }
void SpaceParser::ReadUnicodeCodePoint() void SpaceParser::read_unicode_code_point()
{ {
wchar_t c; wchar_t c;
int value = 0; int value = 0;
for(int i=0 ; i<4 ; ++i) for(int i=0 ; i<4 ; ++i)
{ {
c = ReadCharNoEscape(); c = read_char_no_escape();
if( !IsHexDigit(c) ) if( !is_hex_digit(c) )
{ {
status = syntax_error; status = syntax_error;
return; return;
} }
value = (value << 4) | HexToInt(c); value = (value << 4) | hex_to_int(c);
} }
lastc = (wchar_t)value; lastc = (wchar_t)value;
} }
int SpaceParser::ReadChar() int SpaceParser::read_char()
{ {
char_was_escaped = false; char_was_escaped = false;
ReadCharNoEscape(); read_char_no_escape();
if( lastc == '\\' ) if( lastc == '\\' )
{ {
char_was_escaped = true; char_was_escaped = true;
ReadCharNoEscape(); read_char_no_escape();
switch(lastc) switch(lastc)
{ {
@ -1077,7 +1077,7 @@ int SpaceParser::ReadChar()
case 'n': lastc = '\n'; break; case 'n': lastc = '\n'; break;
case 'b': lastc = 0x08; break; case 'b': lastc = 0x08; break;
case 'f': lastc = 0x0c; break; case 'f': lastc = 0x0c; break;
case 'u': ReadUnicodeCodePoint(); break; case 'u': read_unicode_code_point(); break;
// "in other cases we return the last character, so two \\ returns one \ " // "in other cases we return the last character, so two \\ returns one \ "
} }
} }

View File

@ -67,7 +67,7 @@ public:
/* /*
the last status of parsing, set by Parse() methods the last status of parsing, set by parse() methods
*/ */
Status status; Status status;
@ -78,48 +78,48 @@ public:
main methods used to parse a JSON file main methods used to parse a JSON file
file_name is the path to a file file_name is the path to a file
*/ */
Status ParseJSONFile(const char * file_name, Space & out_space, bool clear_space = true); Status parse_json_file(const char * file_name, Space & out_space, bool clear_space = true);
Status ParseJSONFile(const std::string & file_name, Space & out_space, bool clear_space = true); Status parse_json_file(const std::string & file_name, Space & out_space, bool clear_space = true);
Status ParseJSONFile(const wchar_t * file_name, Space & out_space, bool clear_space = true); Status parse_json_file(const wchar_t * file_name, Space & out_space, bool clear_space = true);
Status ParseJSONFile(const std::wstring & file_name, Space & out_space, bool clear_space = true); Status parse_json_file(const std::wstring & file_name, Space & out_space, bool clear_space = true);
/* /*
main methods used to parse a Space file main methods used to parse a Space file
file_name is the path to a file file_name is the path to a file
*/ */
Status ParseSpaceFile(const char * file_name, Space & out_space, bool clear_space = true); Status parse_space_file(const char * file_name, Space & out_space, bool clear_space = true);
Status ParseSpaceFile(const std::string & file_name, Space & out_space, bool clear_space = true); Status parse_space_file(const std::string & file_name, Space & out_space, bool clear_space = true);
Status ParseSpaceFile(const wchar_t * file_name, Space & out_space, bool clear_space = true); Status parse_space_file(const wchar_t * file_name, Space & out_space, bool clear_space = true);
Status ParseSpaceFile(const std::wstring & file_name, Space & out_space, bool clear_space = true); Status parse_space_file(const std::wstring & file_name, Space & out_space, bool clear_space = true);
/* /*
main methods used to parse main methods used to parse
str - input string (either 8bit ascii or UTF-8 -- see UTF8() method) str - input string (either 8bit ascii or UTF-8 -- see UTF8() method)
*/ */
Status ParseJSON(const char * str, Space & out_space, bool clear_space = true); Status parse_json(const char * str, Space & out_space, bool clear_space = true);
Status ParseJSON(const std::string & str, Space & out_space, bool clear_space = true); Status parse_json(const std::string & str, Space & out_space, bool clear_space = true);
/* /*
main methods used to parse main methods used to parse
here input string is always in unicode (wide characters) here input string is always in unicode (wide characters)
*/ */
Status ParseJSON(const wchar_t * str, Space & out_space, bool clear_space = true); Status parse_json(const wchar_t * str, Space & out_space, bool clear_space = true);
Status ParseJSON(const std::wstring & str, Space & out_space, bool clear_space = true); Status parse_json(const std::wstring & str, Space & out_space, bool clear_space = true);
Status ParseSpace(const char * str, Space & out_space, bool clear_space = true); Status parse_space(const char * str, Space & out_space, bool clear_space = true);
Status ParseSpace(const std::string & str, Space & out_space, bool clear_space = true); Status parse_space(const std::string & str, Space & out_space, bool clear_space = true);
Status ParseSpace(const wchar_t * str, Space & out_space, bool clear_space = true); Status parse_space(const wchar_t * str, Space & out_space, bool clear_space = true);
Status ParseSpace(const std::wstring & str, Space & out_space, bool clear_space = true); Status parse_space(const std::wstring & str, Space & out_space, bool clear_space = true);
/* /*
* add two args Parse method * add two args parse method
* Status Parse(const char * str, Space & output_space); * Status parse(const char * str, Space & output_space);
* *
*/ */
@ -160,7 +160,7 @@ private:
int line; int line;
/* /*
true if Parse() method was called true if parse() method was called
false if ParseString() was called false if ParseString() was called
*/ */
bool reading_from_file; bool reading_from_file;
@ -260,51 +260,47 @@ private:
void ParseRootSpace(bool clear_root_space); void parse_root_space(bool clear_root_space);
void Parse(Space * space, bool is_object_value, bool is_table_value); void parse(Space * space, bool is_object_value, bool is_table_value);
void ParseSpace(Space * space); void parse_space(Space * space);
void ParseTable(Space * space); void parse_table(Space * space);
void ParseKeyValuePairs(Space * space); void parse_key_value_pairs(Space * space);
void ParseValuesList(Space * space); void parse_values_list(Space * space);
void ReadKey(); void read_key();
void ParseTextValue(Space * space);
void ParseIntegerValue(Space * space);
void ParseFloatingPointValue(Space * space);
void parse_text_value(Space * space);
void parse_integer_value(Space * space);
void parse_floating_point_value(Space * space);
bool is_alfa_numeric_char(int c); bool is_alfa_numeric_char(int c);
void ReadTokenUntilDelimiter(std::wstring & token, int delimiter1, int delimiter2); void read_token_until_delimiter(std::wstring & token, int delimiter1, int delimiter2);
void ReadAlfaNumericToken(std::wstring & token); void read_alfa_numeric_token(std::wstring & token);
void ReadStringValue(std::wstring & token, bool is_object_value, bool is_table_value); void read_string_value(std::wstring & token, bool is_object_value, bool is_table_value);
bool is_integer_token(); bool is_integer_token();
bool is_floating_point_token(); bool is_floating_point_token();
void ReadSpaceFieldToken(std::wstring & token); void read_space_field_token(std::wstring & token);
void ReadTokenQuoted(std::wstring & token); void read_token_quoted(std::wstring & token);
void ReadMultilineTokenQuoted(std::wstring & token); void read_multiline_token_quoted(std::wstring & token);
int read_utf8_char();
int read_ascii_char();
int ReadUTF8Char(); int read_char_from_wchar_string();
int ReadASCIIChar(); int read_char_from_utf8_string();
int ReadCharFromWcharString(); int read_char_from_ascii_string();
int ReadCharFromUTF8String(); int read_char_no_escape();
int ReadCharFromAsciiString(); int read_char();
int ReadCharNoEscape(); bool is_white(int c);
int ReadChar(); void skip_line();
bool IsWhite(int c); void skip_white();
void SkipLine(); void trim_last_white(std::wstring & s);
void SkipWhite(); bool is_hex_digit(wchar_t c);
void TrimLastWhite(std::wstring & s); int hex_to_int(wchar_t c);
bool IsHexDigit(wchar_t c); void read_unicode_code_point();
int HexToInt(wchar_t c);
void ReadUnicodeCodePoint();
}; };