diff options
author | Jelte Jansen <jelte@isc.org> | 2012-04-02 15:16:27 +0200 |
---|---|---|
committer | Jelte Jansen <jelte@isc.org> | 2012-04-02 15:16:27 +0200 |
commit | 6e57b76919731d8f5a15d21d2c008336362f44c9 (patch) | |
tree | a503a5017c3414e6f39c31bfd8d25b79d3a7bf07 /src/lib/cc/data.cc | |
parent | [1626] Add more testcases (diff) | |
download | kea-6e57b76919731d8f5a15d21d2c008336362f44c9.tar.xz kea-6e57b76919731d8f5a15d21d2c008336362f44c9.zip |
[1626] use one list of 'whitespace' chars
and even more tests
Moved a couple of 'basic' tests out of 'escape' and to 'to_and_from_string' test
Diffstat (limited to 'src/lib/cc/data.cc')
-rw-r--r-- | src/lib/cc/data.cc | 25 |
1 files changed, 18 insertions, 7 deletions
diff --git a/src/lib/cc/data.cc b/src/lib/cc/data.cc index 018b4ab05a..6ec243a1a0 100644 --- a/src/lib/cc/data.cc +++ b/src/lib/cc/data.cc @@ -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 |