PhoenixFileParser  1.5.1
Set of tools to ease file parsing
Loading...
Searching...
No Matches
parser_json.h File Reference
#include "ConfigNode.h"
+ Include dependency graph for parser_json.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

bool parser_json (ConfigNode &main, const PPath &fileName)
 Load a JSON file.
 
bool parser_jsonString (ConfigNode &main, const PString &fileContent)
 Load a JSON string.
 
PString toJsonString (const ConfigNode &main, const PString &baseIndentation, const PString &baseNewLine)
 Convert the current ConfigNode to a JSON string.
 

Function Documentation

◆ parser_json()

bool parser_json ( ConfigNode & main,
const PPath & fileName )

Load a JSON file.

Parameters
[out]main: ConfigNode to be updated
fileName: name of the file to be loaded
Returns
true on success, false otherwise

Definition at line 219 of file parser_json.cpp.

219 {
220 PJsonParserData data;
221 PFileParser & parser = data.parser;
222 parser.setWhiteSpace(" \n\t");
223 parser.setSeparator(":-'\",{}[]>|");
224 parser.setEscapeChar('\\');
225 if(!parser.open(fileName)){
226 std::cerr << "parser_json : cannot open file '"<<fileName<<"'" << std::endl;
227 return false;
228 }
229 main.setFileName(fileName);
230 bool b(parser_json_fileParser(main, data));
231 return b;
232}
void setFileName(const PPath &fileName)
Set the fileName of the current ConfigNode.
classe qui permet de parser des fichiers texte en renvoyant les tokens les uns après les autres
Definition PFileParser.h:20
void setSeparator(const PString &separator)
Initialise la liste des caractères séparateurs.
bool open(const PPath &fileName)
Fonction qui ouvre le fichier que l'on va parser.
void setEscapeChar(char escapeChar)
Sets the escape character of the PFileParser.
void setWhiteSpace(const PString &whiteSpace)
Initialise la liste des caractères blancs.
bool parser_json_fileParser(ConfigNode &node, PJsonParserData &data)
Parse a json file.
Data used to parse a toml file.
PFileParser parser
File parser to be used.

References PFileParser::open(), PJsonParserData::parser, parser_json_fileParser(), PFileParser::setEscapeChar(), ConfigNode::setFileName(), PFileParser::setSeparator(), and PFileParser::setWhiteSpace().

+ Here is the call graph for this function:

◆ parser_jsonString()

bool parser_jsonString ( ConfigNode & main,
const PString & fileContent )

Load a JSON string.

Parameters
[out]main: ConfigNode to be updated
fileContent: string to be loaded
Returns
true on success, false otherwise

Definition at line 239 of file parser_json.cpp.

239 {
240 PJsonParserData data;
241 PFileParser & parser = data.parser;
242 parser.setWhiteSpace(" \n\t");
243 parser.setSeparator(":-'\",{}[]>|");
244 parser.setEscapeChar('\\');
245 parser.setFileContent(fileContent);
246 bool b(parser_json_fileParser(main, data));
247 return b;
248}
void setFileContent(const PString &fileContent)
Set the file content.

References PJsonParserData::parser, parser_json_fileParser(), PFileParser::setEscapeChar(), PFileParser::setFileContent(), PFileParser::setSeparator(), and PFileParser::setWhiteSpace().

+ Here is the call graph for this function:

◆ toJsonString()

PString toJsonString ( const ConfigNode & main,
const PString & baseIndentation,
const PString & baseNewLine )

Convert the current ConfigNode to a JSON string.

Parameters
main: ConfigNode to be converted
baseIndentation: indentation to be used
baseNewLine: new line to be used
Returns
corresponding PString

Definition at line 300 of file parser_json.cpp.

300 {
301 PString out("{");
302 out += toJsonSaveRecurse(main, baseIndentation, baseIndentation, baseNewLine, false);
303 out += baseNewLine + "}";
304 return out;
305}
PString toJsonSaveRecurse(const ConfigNode &node, const PString &indentation, const PString &baseIndentation, const PString &baseNewLine, bool isInList)
Convert the ConfigNode in a PString.

References toJsonSaveRecurse().

+ Here is the call graph for this function: