37 #include <drain/Sprinter.h>
40 #include "TextReader.h"
41 #include "TreeUnordered.h"
73 void readTree(T & tree, std::istream & istr);
110 void handleValue(std::istream & istr, T & tree,
const std::string & key){
124 const bool DATA = !tree.data.empty();
125 const bool CHILDREN = !tree.empty();
127 if (! (DATA||CHILDREN)){
129 ostr << layout.mapChars.prefix << layout.mapChars.suffix;
133 const std::string pad(2*indent,
' ');
146 ostr << layout.mapChars.prefix;
152 for (
const auto & entry: tree){
158 sep = layout.mapChars.separator;
163 ostr << layout.pairChars.prefix;
164 ostr <<
'"' << entry.first <<
'"' << layout.pairChars.separator <<
' ';
167 ostr << layout.pairChars.suffix;
173 ostr << pad << layout.mapChars.suffix;
185 log.
error(
"File read error");
194 log.
error(
"Syntax error: read '", c,
"' when expecting '{'");
202 bool completed =
true;
229 log.
error() <<
"Syntax error: read \"" << key <<
"\" followed by '" << c <<
"' when expecting object {...}, string \"...\", array [...], or number" << log.endl;
235 log.
warn(
"empty section after key=", key);
245 log.
error(
"Syntax error: char '", c,
"' (", (
short)c,
"), expected '\"', '}' or ','");
255 typedef drain::UnorderedMultiTree<drain::Variable,true> JSONtree2;
266 JSONtree2 & child = dst.addChild(key);
270 char c = istr.peek();
Definition: Castable.h:76
Definition: FileInfo.h:48
Utility for extracting JSON-compatible strings, numbers or arrays of numbers in text data.
Definition: JSON.h:60
static void handleValue(std::istream &istr, T &tree, const std::string &key)
In reading trees.
Definition: JSON.h:110
static void readValue(std::istream &istr, Castable &v, bool keepType=false)
Read a value (JSON syntax). Read stream until a value has been extracted, with type recognition.
Definition: JSON.cpp:52
static std::ostream & treeToStream(std::ostream &ostr, const T &tree, const drain::SprinterLayout &layout=drain::Sprinter::jsonLayout, short indent=0)
Write a tree into an output stream using JSON layout by default.
Definition: JSON.h:122
static void readTree(T &tree, std::istream &istr)
Reads and parses a JSON file.
Definition: JSON.h:179
static void readArray(const std::string &s, Castable &v)
Given comma-separated string of values, assign them to variable of minimum compatible type.
Definition: JSON.cpp:116
LogSourc e is the means for a function or any program segment to "connect" to a Log.
Definition: Log.h:308
Logger & error(const TT &... args)
Echoes.
Definition: Log.h:412
Logger & unimplemented(const TT &... args)
Feature to be done. Special type of Logger::note().
Definition: Log.h:507
Logger & warn(const TT &... args)
Possible error, but execution can continue.
Definition: Log.h:426
static std::ostream & toStream(std::ostream &ostr, const std::initializer_list< T > &x, const SprinterLayout &layout=defaultLayout)
New (experimental)
Definition: Sprinter.h:420
static const SprinterLayout jsonLayout
Resembles JSON structure: {"a":1,"b":22,"c":3}.
Definition: Sprinter.h:221
static char skipWhiteSpace(std::istream &istr)
Definition: TextReader.h:91
static std::string scanSegment(std::istream &istr, const std::string &endChars)
Read input stream until any char in endChars is encountered. The end char will not be included,...
Definition: TextReader.h:60
Definition: DataSelector.cpp:1277
Definition: Sprinter.h:137