removed: SpaceParser::SetSpace(...) methods, now ParseJSON/Space(...) methods take a space as an argument

pull/4/head
Tomasz Sowa 2 years ago
parent abeca010cc
commit 82a21f6d85

@ -55,18 +55,6 @@ SpaceParser::SpaceParser()
}
void SpaceParser::SetSpace(Space * pspace)
{
root_space = pspace;
}
void SpaceParser::SetSpace(Space & pspace)
{
root_space = &pspace;
}
void SpaceParser::SetDefault()
{
// you can change this separators to what you want
@ -110,17 +98,18 @@ int SpaceParser::get_last_parsed_line()
SpaceParser::Status SpaceParser::ParseJSONFile(const char * file_name)
SpaceParser::Status SpaceParser::ParseJSONFile(const char * file_name, Space & out_space, bool clear_space)
{
reading_from_file = true;
parsing_space = false;
root_space = &out_space;
file.clear();
file.open(file_name, std::ios_base::binary | std::ios_base::in);
if( file )
{
ParseRootSpace();
ParseRootSpace(clear_space);
file.close();
}
else
@ -133,44 +122,45 @@ return status;
SpaceParser::Status SpaceParser::ParseJSONFile(const std::string & file_name)
SpaceParser::Status SpaceParser::ParseJSONFile(const std::string & file_name, Space & out_space, bool clear_space)
{
return ParseJSONFile(file_name.c_str());
return ParseJSONFile(file_name.c_str(), out_space, clear_space);
}
SpaceParser::Status SpaceParser::ParseJSONFile(const wchar_t * file_name)
SpaceParser::Status SpaceParser::ParseJSONFile(const wchar_t * file_name, Space & out_space, bool clear_space)
{
std::string file_name_utf8;
wide_to_utf8(file_name, file_name_utf8);
return ParseJSONFile(file_name_utf8.c_str());
return ParseJSONFile(file_name_utf8.c_str(), out_space, clear_space);
}
SpaceParser::Status SpaceParser::ParseJSONFile(const std::wstring & file_name)
SpaceParser::Status SpaceParser::ParseJSONFile(const std::wstring & file_name, Space & out_space, bool clear_space)
{
return ParseJSONFile(file_name.c_str());
return ParseJSONFile(file_name.c_str(), out_space, clear_space);
}
SpaceParser::Status SpaceParser::ParseSpaceFile(const char * file_name)
SpaceParser::Status SpaceParser::ParseSpaceFile(const char * file_name, Space & out_space, bool clear_space)
{
reading_from_file = true;
parsing_space = true;
root_space = &out_space;
file.clear();
file.open(file_name, std::ios_base::binary | std::ios_base::in);
if( file )
{
ParseRootSpace();
ParseRootSpace(clear_space);
file.close();
}
else
@ -183,126 +173,129 @@ return status;
SpaceParser::Status SpaceParser::ParseSpaceFile(const std::string & file_name)
SpaceParser::Status SpaceParser::ParseSpaceFile(const std::string & file_name, Space & out_space, bool clear_space)
{
return ParseSpaceFile(file_name.c_str());
return ParseSpaceFile(file_name.c_str(), out_space, clear_space);
}
SpaceParser::Status SpaceParser::ParseSpaceFile(const wchar_t * file_name)
SpaceParser::Status SpaceParser::ParseSpaceFile(const wchar_t * file_name, Space & out_space, bool clear_space)
{
std::string file_name_utf8;
wide_to_utf8(file_name, file_name_utf8);
return ParseSpaceFile(file_name_utf8.c_str());
return ParseSpaceFile(file_name_utf8.c_str(), out_space, clear_space);
}
SpaceParser::Status SpaceParser::ParseSpaceFile(const std::wstring & file_name)
SpaceParser::Status SpaceParser::ParseSpaceFile(const std::wstring & file_name, Space & out_space, bool clear_space)
{
return ParseSpaceFile(file_name.c_str());
return ParseSpaceFile(file_name.c_str(), out_space, clear_space);
}
SpaceParser::Status SpaceParser::ParseJSON(const char * str)
SpaceParser::Status SpaceParser::ParseJSON(const char * str, Space & out_space, bool clear_space)
{
reading_from_file = false;
reading_from_wchar_string = false;
pchar_ascii = str;
pchar_unicode = 0;
parsing_space = false;
root_space = &out_space;
ParseRootSpace();
ParseRootSpace(clear_space);
return status;
return status;
}
SpaceParser::Status SpaceParser::ParseJSON(const std::string & str)
SpaceParser::Status SpaceParser::ParseJSON(const std::string & str, Space & out_space, bool clear_space)
{
return ParseJSON(str.c_str());
return ParseJSON(str.c_str(), out_space, clear_space);
}
SpaceParser::Status SpaceParser::ParseJSON(const wchar_t * str)
SpaceParser::Status SpaceParser::ParseJSON(const wchar_t * str, Space & out_space, bool clear_space)
{
reading_from_file = false;
reading_from_wchar_string = true;
pchar_unicode = str;
pchar_ascii = 0;
parsing_space = false;
root_space = &out_space;
ParseRootSpace();
ParseRootSpace(clear_space);
return status;
return status;
}
SpaceParser::Status SpaceParser::ParseJSON(const std::wstring & str)
SpaceParser::Status SpaceParser::ParseJSON(const std::wstring & str, Space & out_space, bool clear_space)
{
return ParseJSON(str.c_str());
return ParseJSON(str.c_str(), out_space, clear_space);
}
SpaceParser::Status SpaceParser::ParseSpace(const char * str)
SpaceParser::Status SpaceParser::ParseSpace(const char * str, Space & out_space, bool clear_space)
{
reading_from_file = false;
reading_from_wchar_string = false;
pchar_ascii = str;
pchar_unicode = 0;
parsing_space = true;
root_space = &out_space;
ParseRootSpace();
ParseRootSpace(clear_space);
return status;
return status;
}
SpaceParser::Status SpaceParser::ParseSpace(const std::string & str)
SpaceParser::Status SpaceParser::ParseSpace(const std::string & str, Space & out_space, bool clear_space)
{
return ParseSpace(str.c_str());
return ParseSpace(str.c_str(), out_space, clear_space);
}
SpaceParser::Status SpaceParser::ParseSpace(const wchar_t * str)
SpaceParser::Status SpaceParser::ParseSpace(const wchar_t * str, Space & out_space, bool clear_space)
{
reading_from_file = false;
reading_from_wchar_string = true;
pchar_unicode = str;
pchar_ascii = 0;
parsing_space = true;
root_space = &out_space;
ParseRootSpace();
ParseRootSpace(clear_space);
return status;
return status;
}
SpaceParser::Status SpaceParser::ParseSpace(const std::wstring & str)
SpaceParser::Status SpaceParser::ParseSpace(const std::wstring & str, Space & out_space, bool clear_space)
{
return ParseSpace(str.c_str());
return ParseSpace(str.c_str(), out_space, clear_space);
}
void SpaceParser::ParseRootSpace()
void SpaceParser::ParseRootSpace(bool clear_root_space)
{
line = 1;
status = ok;
if( !root_space )
if( clear_root_space )
{
status = no_space;
return;
root_space->set_empty_object();
}
ReadChar(); // put first character to lastc
@ -784,37 +777,6 @@ void SpaceParser::TrimLastWhite(std::wstring & s)
}
/*
void SpaceParser::Trim(std::wstring & s)
{
std::wstring::size_type i;
if( s.empty() )
return;
// looking for white characters at the end
for(i=s.size()-1 ; i>0 && IsWhite(s[i]) ; --i);
if( i==0 && IsWhite(s[i]) )
{
// the whole string consists of white characters
s.clear();
return;
}
// deleting white characters at the end
if( i != s.size() - 1 )
s.erase(i+1, std::wstring::npos);
// looking for white characters at the beginning
for(i=0 ; i<s.size() && IsWhite(s[i]) ; ++i);
// deleting white characters at the beginning
if( i != 0 )
s.erase(0, i);
}
*/
void SpaceParser::ReadTokenUntilDelimiter(std::wstring & token, int delimiter1, int delimiter2)
{
@ -867,7 +829,6 @@ void SpaceParser::ReadStringValue(std::wstring & token, bool is_object_value, bo
}
// rename to something like ReadSpaceFieldToken???
void SpaceParser::ReadSpaceFieldToken(std::wstring & token)
{
token.clear();

@ -60,11 +60,6 @@ public:
SpaceParser();
/*
setting the root space
*/
void SetSpace(Space * pspace);
void SetSpace(Space & pspace);
/*
@ -77,7 +72,7 @@ public:
/*
status of parsing
*/
enum Status { ok, cant_open_file, syntax_error, no_space };
enum Status { ok, cant_open_file, syntax_error };
/*
@ -92,42 +87,42 @@ public:
main methods used to parse a JSON file
file_name is the path to a file
*/
Status ParseJSONFile(const char * file_name);
Status ParseJSONFile(const std::string & file_name);
Status ParseJSONFile(const wchar_t * file_name);
Status ParseJSONFile(const std::wstring & file_name);
Status ParseJSONFile(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 ParseJSONFile(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);
/*
main methods used to parse a Space file
file_name is the path to a file
*/
Status ParseSpaceFile(const char * file_name);
Status ParseSpaceFile(const std::string & file_name);
Status ParseSpaceFile(const wchar_t * file_name);
Status ParseSpaceFile(const std::wstring & file_name);
Status ParseSpaceFile(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 ParseSpaceFile(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);
/*
main methods used to parse
str - input string (either 8bit ascii or UTF-8 -- see UTF8() method)
*/
Status ParseJSON(const char * str);
Status ParseJSON(const std::string & str);
Status ParseJSON(const char * str, Space & out_space, bool clear_space = true);
Status ParseJSON(const std::string & str, Space & out_space, bool clear_space = true);
/*
main methods used to parse
here input string is always in unicode (wide characters)
*/
Status ParseJSON(const wchar_t * str);
Status ParseJSON(const std::wstring & str);
Status ParseJSON(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 ParseSpace(const char * str);
Status ParseSpace(const std::string & str);
Status ParseSpace(const wchar_t * str);
Status ParseSpace(const std::wstring & str);
Status ParseSpace(const char * str, Space & out_space, bool clear_space = true);
Status ParseSpace(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 ParseSpace(const std::wstring & str, Space & out_space, bool clear_space = true);
@ -310,8 +305,7 @@ private:
// new
void ParseRootSpace();
void ParseRootSpace(bool clear_root_space);
void Parse(Space * space, bool is_object_value, bool is_table_value);
void ParseSpace(Space * space);
void ParseTable(Space * space);

Loading…
Cancel
Save