|
@@ -30,6 +30,10 @@
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
+namespace {
|
|
|
+const char* WHITESPACE = " \b\f\n\r\t";
|
|
|
+} // end anonymous namespace
|
|
|
+
|
|
|
namespace isc {
|
|
|
namespace data {
|
|
|
|
|
@@ -461,12 +465,12 @@ from_stringstream_list(std::istream &in, const std::string& file, int& line,
|
|
|
ElementPtr list = Element::createList();
|
|
|
ConstElementPtr cur_list_element;
|
|
|
|
|
|
- skip_chars(in, " \t\n\r\b", line, pos);
|
|
|
+ skip_chars(in, WHITESPACE, line, pos);
|
|
|
while (c != EOF && c != ']') {
|
|
|
if (in.peek() != ']') {
|
|
|
cur_list_element = Element::fromJSON(in, file, line, pos);
|
|
|
list->add(cur_list_element);
|
|
|
- skip_to(in, file, line, pos, ",]", " \t\n");
|
|
|
+ skip_to(in, file, line, pos, ",]", WHITESPACE);
|
|
|
}
|
|
|
c = in.get();
|
|
|
pos++;
|
|
@@ -479,7 +483,7 @@ from_stringstream_map(std::istream &in, const std::string& file, int& line,
|
|
|
int& pos)
|
|
|
{
|
|
|
ElementPtr map = Element::createMap();
|
|
|
- skip_chars(in, " \t\n\r\b", line, pos);
|
|
|
+ skip_chars(in, WHITESPACE, line, pos);
|
|
|
char c = in.peek();
|
|
|
if (c == EOF) {
|
|
|
throwJSONError(std::string("Unterminated map, <string> or } expected"), file, line, pos);
|
|
@@ -490,7 +494,7 @@ from_stringstream_map(std::istream &in, const std::string& file, int& line,
|
|
|
while (c != EOF && c != '}') {
|
|
|
std::string key = str_from_stringstream(in, file, line, pos);
|
|
|
|
|
|
- skip_to(in, file, line, pos, ":", " \t\n");
|
|
|
+ skip_to(in, file, line, pos, ":", WHITESPACE);
|
|
|
// skip the :
|
|
|
in.get();
|
|
|
pos++;
|
|
@@ -498,7 +502,7 @@ from_stringstream_map(std::istream &in, const std::string& file, int& line,
|
|
|
ConstElementPtr value = Element::fromJSON(in, file, line, pos);
|
|
|
map->set(key, value);
|
|
|
|
|
|
- skip_to(in, file, line, pos, ",}", " \t\n");
|
|
|
+ skip_to(in, file, line, pos, ",}", WHITESPACE);
|
|
|
c = in.get();
|
|
|
pos++;
|
|
|
}
|
|
@@ -577,7 +581,7 @@ Element::fromJSON(std::istream &in, const std::string& file, int& line,
|
|
|
char c = 0;
|
|
|
ElementPtr element;
|
|
|
bool el_read = false;
|
|
|
- skip_chars(in, " \n\t\r\b", line, pos);
|
|
|
+ skip_chars(in, WHITESPACE, line, pos);
|
|
|
while (c != EOF && !el_read) {
|
|
|
c = in.get();
|
|
|
pos++;
|
|
@@ -644,7 +648,14 @@ ElementPtr
|
|
|
Element::fromJSON(const std::string &in) {
|
|
|
std::stringstream ss;
|
|
|
ss << in;
|
|
|
- return (fromJSON(ss, "<string>"));
|
|
|
+ int line = 1, pos = 1;
|
|
|
+ ElementPtr result(fromJSON(ss, "<string>", line, pos));
|
|
|
+ skip_chars(ss, WHITESPACE, line, pos);
|
|
|
+ // ss must now be at end
|
|
|
+ if (ss.peek() != EOF) {
|
|
|
+ throwJSONError("Extra data", "<string>", line, pos);
|
|
|
+ }
|
|
|
+ return result;
|
|
|
}
|
|
|
|
|
|
// to JSON format
|