Commit 97aefc38 authored by Lefebvre, Jordan's avatar Lefebvre, Jordan

Migrating all json error messages to set_error().

parent 82c1888d
......@@ -53,7 +53,7 @@ class RADIX_PUBLIC JSONParserImpl
skip_whitespace();
if (m_po != m_text.size())
{
m_last_error = "unexpected trailing character(s)";
set_error("unexpected trailing character(s)");
return false;
}
return true;
......@@ -84,7 +84,7 @@ class RADIX_PUBLIC JSONParserImpl
file.open(fn, std::ios::in | std::ios::binary | std::ios::ate);
if (!file.is_open())
{
m_last_error = "could not open file";
set_error("could not open file");
return false;
}
bool result = parse_from_stream(file);
......@@ -93,6 +93,7 @@ class RADIX_PUBLIC JSONParserImpl
}
private:
void set_error(const std::string& error) { m_last_error = error; }
//-------------------------------------------------------------------------
bool is_whitespace()
{
......@@ -159,13 +160,13 @@ class RADIX_PUBLIC JSONParserImpl
}
else if (m_po >= m_text.size())
{
m_last_error = "no closing bracket ']' for array";
set_error("no closing bracket ']' for array");
}
else if (trailing_comma)
{
m_last_error = "trailing comma in array";
m_line = line_prev;
m_col = col_prev;
set_error("trailing comma in array");
m_line = line_prev;
m_col = col_prev;
}
else if (m_text[m_po] == ']')
break;
......@@ -189,15 +190,16 @@ class RADIX_PUBLIC JSONParserImpl
break;
else
{
m_last_error = "invalid character '";
m_last_error += ch;
m_last_error += "' in array";
std::string err_msg = "invalid character '";
err_msg += ch;
err_msg += "' in array";
set_error(err_msg);
return value_type();
}
}
if (m_po >= m_text.size() || m_text[m_po] != ']')
{
m_last_error = "no closing bracket ']' for array";
set_error("no closing bracket ']' for array");
return value_type();
}
m_po++;
......@@ -226,7 +228,7 @@ class RADIX_PUBLIC JSONParserImpl
len++;
if (m_po >= m_text.size())
{
m_last_error = "invalid number (no digits after -)";
set_error("invalid number (no digits after -)");
return value_type();
}
}
......@@ -235,7 +237,7 @@ class RADIX_PUBLIC JSONParserImpl
char ch = m_text[m_po];
if (m_po >= m_text.size() || !(ch >= '0' && m_text[m_po] <= '9'))
{
m_last_error = "invalid number (no digits)";
set_error("invalid number (no digits)");
return value_type();
}
m_po++;
......@@ -274,7 +276,7 @@ class RADIX_PUBLIC JSONParserImpl
len++;
if (m_po >= m_text.size())
{
m_last_error = "invalid number (no digits after decimal)";
set_error("invalid number (no digits after decimal)");
return value_type();
}
ch = m_text[m_po];
......@@ -287,7 +289,7 @@ class RADIX_PUBLIC JSONParserImpl
}
if (n_digits == 0)
{
m_last_error = "invalid number (no digits after decimal)";
set_error("invalid number (no digits after decimal)");
return value_type();
}
}
......@@ -300,7 +302,7 @@ class RADIX_PUBLIC JSONParserImpl
len++;
if (m_po >= m_text.size())
{
m_last_error = "invalid number (no digits for exponent)";
set_error("invalid number (no digits for exponent)");
return value_type();
}
ch = m_text[m_po];
......@@ -313,7 +315,7 @@ class RADIX_PUBLIC JSONParserImpl
}
if (m_po >= m_text.size())
{
m_last_error = "invalid number (no digits for exponent)";
set_error("invalid number (no digits for exponent)");
return value_type();
}
......@@ -326,7 +328,7 @@ class RADIX_PUBLIC JSONParserImpl
}
if (n_digits == 0)
{
m_last_error = "invalid number (no digits after decimal)";
set_error("invalid number (no digits after decimal)");
return value_type();
}
}
......@@ -386,7 +388,7 @@ class RADIX_PUBLIC JSONParserImpl
return value_type();
}
}
m_last_error = "invalid literal";
set_error("invalid literal");
return value_type();
}
......@@ -410,9 +412,9 @@ class RADIX_PUBLIC JSONParserImpl
{
if (trailing_comma)
{
m_last_error = "trailing comma in object";
m_line = line_prev;
m_col = col_prev;
set_error("trailing comma in object");
m_line = line_prev;
m_col = col_prev;
return value_type();
}
break;
......@@ -424,9 +426,9 @@ class RADIX_PUBLIC JSONParserImpl
{
if (trailing_comma)
{
m_last_error = "trailing comma on invalid key in object";
m_line = line_prev;
m_col = col_prev;
set_error("trailing comma on invalid key in object");
m_line = line_prev;
m_col = col_prev;
}
return value_type();
}
......@@ -435,7 +437,7 @@ class RADIX_PUBLIC JSONParserImpl
// parse ':'
if (m_po >= m_text.size() || m_text[m_po] != ':')
{
m_last_error = "no ':' following key in object";
set_error("no ':' following key in object");
return value_type();
}
m_po++;
......@@ -447,13 +449,13 @@ class RADIX_PUBLIC JSONParserImpl
{
if (m_last_error == "")
{
m_last_error = "missing value in object";
set_error("missing value in object");
}
if (trailing_comma)
{
m_last_error = "trailing comma in object";
m_line = line_prev;
m_col = col_prev;
set_error("trailing comma in object");
m_line = line_prev;
m_col = col_prev;
}
return value_type();
}
......@@ -476,13 +478,13 @@ class RADIX_PUBLIC JSONParserImpl
break;
else
{
m_last_error = "invalid character in object";
set_error("invalid character in object");
return value_type();
}
}
if (m_po >= m_text.size() || m_text[m_po] != '}')
{
m_last_error = "no closing curly bracket '}' for object";
set_error("no closing curly bracket '}' for object");
return value_type();
}
m_po++;
......@@ -501,7 +503,7 @@ class RADIX_PUBLIC JSONParserImpl
(*len)++;
if (m_po >= m_text.size())
{
m_last_error = "incomplete unicode character escape sequence in string";
set_error("incomplete unicode character escape sequence in string");
return false;
}
char ch = m_text[m_po];
......@@ -527,18 +529,18 @@ class RADIX_PUBLIC JSONParserImpl
if (!((ch >= '0' && ch <= '9') || (ch >= 'A' && ch <= 'F') ||
(ch >= 'a' && ch <= 'f')))
{
m_last_error = "invalid unicode character escape sequence in string";
set_error("invalid unicode character escape sequence in string");
return false;
}
}
if (code_len < 4)
{
m_last_error = "incomplete unicode character escape sequence in string";
set_error("incomplete unicode character escape sequence in string");
return false;
}
return true;
}
m_last_error = "invalid escape sequence in string";
set_error("invalid escape sequence in string");
return false;
}
......@@ -552,7 +554,7 @@ class RADIX_PUBLIC JSONParserImpl
{
if (m_po >= m_text.size() || m_text[m_po] != '"')
{
m_last_error = "string missing opening quote";
set_error("string missing opening quote");
return "";
}
m_po++;
......@@ -563,7 +565,7 @@ class RADIX_PUBLIC JSONParserImpl
// disallow control characters <= 0x1f and extended ascii >= 0x80
if (ch <= 0x1f)
{
m_last_error = "invalid character in string";
set_error("invalid character in string");
return "";
}
if (ch == '\\')
......@@ -582,7 +584,7 @@ class RADIX_PUBLIC JSONParserImpl
m_col++;
len++;
}
m_last_error = "string missing closing quote";
set_error("string missing closing quote");
return "";
}
......@@ -590,7 +592,7 @@ class RADIX_PUBLIC JSONParserImpl
value_type parse_string()
{
std::string str = parse_string_contents();
if (m_last_error != "") return value_type();
if (!m_last_error.empty()) return value_type();
return value_type(str);
}
......
......@@ -239,7 +239,7 @@ bool parse_and_test(const std::string& file)
JSONParser parser;
std::string filename =
to_native_path(dirname(__FILE__) + "/testfiles/" + file);
std::cout << "Test file: " << filename << std::endl;
// std::cout << "Test file: " << filename << std::endl;
bool benchmark = (file.substr(0, 4).compare("benc") == 0);
if (benchmark)
{
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment