30 std::cerr <<
"\t" << errorMsg << std::endl;
58 value = parser.
getStrComposedOf(
"abcdefghijklmnopqsrtuvwxyzABCDEFGHIJKLMNOPQSRTUVWXYZ0123456789._-+");
99 std::stringstream location;
100 if(prevChild != NULL){
103 return parser_jsonErrorAt(data,
"key '"+key+
"' already defined at " + location.str());
131 if(!parser.
isMatch(
"{")){
return false;}
154 if(!parser.
isMatch(
"[")){
return false;}
225 if(!parser.
open(fileName)){
226 std::cerr <<
"parser_json : cannot open file '"<<fileName<<
"'" << std::endl;
259PString
toJsonSaveRecurse(
const ConfigNode & node,
const PString & indentation,
const PString & baseIndentation,
const PString & baseNewLine,
bool isInList){
260 PString out(
""), newIndentation(indentation);
261 const PString & name = node.
getName();
262 if(name !=
"" || isInList){
263 newIndentation = indentation + baseIndentation;
267 if(mapChild.size() != 0lu){
268 if(name !=
""){out += baseNewLine + indentation + name.addPrefixSuffix(
"\"",
"\"") +
": {";}
269 else if(isInList){out += baseNewLine+indentation+
"{";}
271 for(VecConfigNode::const_iterator it(vecChild.begin()); it != vecChild.end(); ++it){
273 out +=
toJsonSaveRecurse(**it, newIndentation, baseIndentation, baseNewLine,
false);
276 if(name !=
""){out += baseNewLine+indentation+
"}";}
277 else if(isInList){out += baseNewLine+indentation+
"}";}
278 }
else if(vecChild.size() != 0lu){
279 if(name !=
""){out += baseNewLine + indentation + name.addPrefixSuffix(
"\"",
"\"") +
": [";}
281 for(VecConfigNode::const_iterator it(vecChild.begin()); it != vecChild.end(); ++it){
283 out +=
toJsonSaveRecurse(**it, newIndentation, baseIndentation, baseNewLine,
true);
286 if(name !=
""){out +=
"]";}
288 if(name !=
""){out += baseNewLine + indentation + name.addPrefixSuffix(
"\"",
"\"") +
": " + node.
getValue().addPrefixSuffix(
"\"",
"\"");}
289 else{out += node.
getValue().addPrefixSuffix(
"\"",
"\"");}
302 out +=
toJsonSaveRecurse(main, baseIndentation, baseIndentation, baseNewLine,
false);
303 out += baseNewLine +
"}";
std::vector< ConfigNode * > VecConfigNode
std::map< PString, ConfigNode * > MapConfigNode
const PString & getValue() const
Gets the value of the ConfigNode.
void setValue(const PString &value)
Sets the value of the ConfigNode.
PLocation getLocation() const
Gets the location of the ConfigNode.
void setLineCol(const PLocation &location)
Set the line and the column of the current ConfigNode.
const PString & getName() const
Gets the name of the ConfigNode.
const std::vector< ConfigNode * > & getVecChild() const
Gets the vecChild of the ConfigNode.
ConfigNode * addChild(const PString &name="")
Add a child in the current ConfigNode.
ConfigNode * getChild(const PString &name)
Get the child of the given name.
const std::map< PString, ConfigNode * > & getMapChild() const
Gets the mapChild of the ConfigNode.
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
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.
PString getNextToken()
Get the next token.
void setEscapeChar(char escapeChar)
Sets the escape character of the PFileParser.
PString getStrComposedOf(const PString &charset)
Get string composed of the characters in the string charset.
void setWhiteSpace(const PString &whiteSpace)
Initialise la liste des caractères blancs.
bool isMatchRewind(const PString &patern)
Do a isMatch and then go back at the previous position.
bool isMatch(const PString &patern)
Says if the patern match with the current caracters of the PFileParser.
void popPosition()
Get to the last saved position of the PFileParser in the current file.
void clearPosition()
Clear the save position of the parser in ther current file.
PString getUntilKey(const PString &patern)
Renvoie la chaine de caractère du caractère courant jusqu'à patern comprise.
PLocation getLocation() const
Fonction qui renvoie la PLocation du PFileParser.
void setFileContent(const PString &fileContent)
Set the file content.
void pushPosition()
Remember the current position of the PFileParser in the current file.
bool isEndOfFile() const
Dit si on est à la fin du fichier.
bool parser_jsonErrorAt(PJsonParserData &data, const PString &errorMsg)
Print the parsing error.
bool parser_json(ConfigNode &main, const PPath &fileName)
Load a JSON file.
bool parser_json_value(PString &value, PJsonParserData &data)
Parse a json.
PString toJsonSaveRecurse(const ConfigNode &node, const PString &indentation, const PString &baseIndentation, const PString &baseNewLine, bool isInList)
Convert the ConfigNode in a PString.
bool parser_jsonString(PString &str, PJsonParserData &data)
Parse a JSON string.
bool parser_json_key(ConfigNode &node, PJsonParserData &data)
Parse a json.
PString toJsonString(const ConfigNode &main, const PString &baseIndentation, const PString &baseNewLine)
Convert the current ConfigNode to a JSON string.
bool parser_json_map(ConfigNode &node, PJsonParserData &data)
Parse a json.
bool parser_json_fileParser(ConfigNode &node, PJsonParserData &data)
Parse a json file.
bool parser_json_list(ConfigNode &node, PJsonParserData &data)
Parse a json.
Data used to parse a toml file.
PFileParser parser
File parser to be used.
bool isRun
True to continue the parsing, false to stop.