PhoenixFileParser  1.0.0
Set of tools to ease file parsing
Loading...
Searching...
No Matches
PFileParser Class Reference

classe qui permet de parser des fichiers texte en renvoyant les tokens les uns après les autres More...

#include <PFileParser.h>

Public Member Functions

void clear ()
 Clear the save position of the parser in ther current file.
 
size_t getColumn () const
 Fonction qui renvoie le numéro de la colonne du caractère courant.
 
char getCurrentCh () const
 Renvoie le caractère courant.
 
size_t getCurrentCharIdx () const
 Return the index of the current character.
 
PString getCurrentRow () const
 Get the current parsed row.
 
char getEscapeChar () const
 Gets the escape character of the PFileParser.
 
PPath getFileName () const
 Fonction qui renvoie le nom du fichier que l'on a ouvert.
 
size_t getLine () const
 Fonction qui renvoie le numéro de la ligne courante.
 
size_t getLineIndentation ()
 Get the current line indentation.
 
PLocation getLocation () const
 Fonction qui renvoie la PLocation du PFileParser.
 
size_t getNbTotalChar () const
 Return the number of characters in the current opened file.
 
char getNextChar ()
 Fonction qui renvoie le prochain caractère du fichier courant.
 
PString getNextToken ()
 Get the next token.
 
PString getNextToken (PString &skippedStr)
 Get the next token and return also the skipped characters until the next token.
 
char getPrevCh () const
 Renvoie le caractère courant.
 
PString getSeparator () const
 renvoie la liste des caractères séparateurs
 
PString getStrComposedOf (const PString &charset)
 Get string composed of the characters in the string charset.
 
PString getUntilKey (const PString &patern)
 Renvoie la chaine de caractère du caractère courant jusqu'à patern comprise.
 
PString getUntilKeyWithoutPatern (const PString &patern)
 Renvoie la chaine de caractère du caractère courant jusqu'à patern exclu.
 
PString getUntilKeyWithoutPaternExclude (const PString &patern, const PString &strNotBeforeEndPatern)
 Parse a string until the patern is found, only if it has not strNotBeforeEndPatern before it.
 
PString getUntilKeyWithoutPaternRecurse (const PString &patern, const PString &beginPatern)
 Get the string until end sequence and take account recursive patern (embeded strings)
 
PString getUntilKeyWithoutPaternRecurse (const PString &patern, const PString &beginPatern, const PString &allowedCharAfterBegin)
 Get the string until end sequence and take account recursive patern (embeded strings)
 
PString getUntilKeyWithoutPaternRecurseExclude (const PString &patern, const PString &beginPatern, const PString &echapExpr)
 Get the string until end sequence and take account recursive patern (embeded strings)
 
PString getWhiteSpace () const
 renvoie la liste des caractères blancs
 
bool isChSeparator () const
 Dis si le caractère courant est un séparateur.
 
bool isChSpace () const
 Dis si le caractère courant est un caractère blanc.
 
bool isEndOfFile () const
 Dit si on est à la fin du fichier.
 
PString isMatch (const PParseSeq &seq)
 Check the matching of a sequence in the current file.
 
bool isMatch (const PString &patern)
 Says if the patern match with the current caracters of the PFileParser.
 
bool isMatch (const PString &patern, const PString &forbiddenCharBefore)
 Says if the patern match with the current caracters of the PFileParser.
 
PString isMatch (const PVecString &patern)
 Check the matching between the current caracters and all the string in the vector.
 
PString isMatch (const std::vector< PVecString > &patern)
 Check the matching between the current caracters and all the string in the list of list of string.
 
bool isMatchRewind (const PString &patern)
 Do a isMatch and then go back at the previous position.
 
bool isMatchSeq (const PVecString &patern, bool alwaysPopBack=false)
 Match a sequence of token in a vector.
 
bool isMatchToken (const PString &patern)
 Says if the patern match with the current caracters of the PFileParser but treats the string as a token (cannot be part of a word)
 
PString isMatchToken (const PVecString &patern)
 Check the matching between the current caracters and all the string in the vector but treats the string as a token (cannot be part of a word)
 
template<typename T>
bool isMatchToken (PString &matchKey, T &matchValue, const std::map< PString, T > &patern)
 Check if one key of the map, matches the current token.
 
bool isWhiteSpace ()
 Says if the current char is a white space.
 
bool open (const PPath &fileName)
 Fonction qui ouvre le fichier que l'on va parser.
 
 PFileParser ()
 Constructeur de PFileParser.
 
void popPosition ()
 Get to the last saved position of the PFileParser in the current file.
 
void pushPosition ()
 Remember the current position of the PFileParser in the current file.
 
void setColumn (size_t currentCol)
 Set the current column of the PFileParser.
 
void setEscapeChar (char escapeChar)
 Sets the escape character of the PFileParser.
 
void setFileContent (const PString &fileContent)
 Set the file content.
 
void setLine (size_t currentLine)
 Set the current line of the PFileParser.
 
void setLocation (const PLocation &location)
 Set the current location of the PFileParser.
 
void setSeparator (const PString &separator)
 Initialise la liste des caractères séparateurs.
 
void setWhiteSpace (const PString &whiteSpace)
 Initialise la liste des caractères blancs.
 
void skipChars (const PString &chToSkip)
 Skip the characters in the given string.
 
void skipWhiteSpace ()
 Skip the white space if there is at the current caracter position.
 
virtual ~PFileParser ()
 Destructeur de PFileParser.
 

Private Member Functions

void incrementCurrentChar (size_t nbChar=1lu)
 Increment the current caracter.
 
void incrementCurrentLine ()
 Increment the current line.
 
void initialisationPFileParser ()
 Fonction d'initialisation du PFileParser.
 

Private Attributes

size_t p_currentChar
 Numéro du caractère courant.
 
bool p_currentCharEchaped
 True if the current char is escaped.
 
size_t p_currentLine
 Numéro de la ligne courante.
 
size_t p_currentLineFirstColumn
 Number of the first column caracter of the current line.
 
bool p_dontSkipSpace
 Say if we don't want to skip the spaces.
 
char p_echapChar
 Echap caracter.
 
PString p_fileContent
 Contenu du fichier de configuration.
 
PPath p_fileName
 Nom du fichier que l'on veut parser.
 
PString p_listSeparator
 liste des séparateurs
 
PString p_listWhiteSpace
 liste des espaces blancs
 
size_t p_nbTotalChar
 Nombre de caractères total.
 
std::vector< size_t > p_vecLine
 Vector of all the checkpoint rows in the text file (added with pushPosition() and removed with popPosition() or clear()
 
std::vector< size_t > p_vecPosition
 Vector of all the checkpoint positions in the text file (added with pushPosition() and removed with popPosition() or clear()
 

Friends

std::ostream & operator<< (std::ostream &out, const PFileParser &other)
 Définition de l'opérateur de flux sortant.
 

Detailed Description

classe qui permet de parser des fichiers texte en renvoyant les tokens les uns après les autres

Definition at line 20 of file PFileParser.h.

Constructor & Destructor Documentation

◆ PFileParser()

PFileParser::PFileParser ( )

Constructeur de PFileParser.

Definition at line 11 of file PFileParser.cpp.

11 {
13}
void initialisationPFileParser()
Fonction d'initialisation du PFileParser.

References initialisationPFileParser().

Referenced by operator<<.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ~PFileParser()

PFileParser::~PFileParser ( )
virtual

Destructeur de PFileParser.

Definition at line 16 of file PFileParser.cpp.

16 {
17
18}

Member Function Documentation

◆ clear()

void PFileParser::clear ( )

Clear the save position of the parser in ther current file.

Definition at line 110 of file PFileParser.cpp.

110 {
111 p_vecPosition.clear();
112 p_vecLine.clear();
113}
std::vector< size_t > p_vecPosition
Vector of all the checkpoint positions in the text file (added with pushPosition() and removed with p...
std::vector< size_t > p_vecLine
Vector of all the checkpoint rows in the text file (added with pushPosition() and removed with popPos...

References p_vecLine, and p_vecPosition.

◆ getColumn()

size_t PFileParser::getColumn ( ) const

Fonction qui renvoie le numéro de la colonne du caractère courant.

Returns
colonne du caractère courant

Definition at line 692 of file PFileParser.cpp.

692 {
695 }else{return 0lu;}
696}
size_t p_currentLineFirstColumn
Number of the first column caracter of the current line.
size_t p_currentChar
Numéro du caractère courant.

References p_currentChar, and p_currentLineFirstColumn.

Referenced by getLocation(), and operator<<.

+ Here is the caller graph for this function:

◆ getCurrentCh()

char PFileParser::getCurrentCh ( ) const

Renvoie le caractère courant.

Returns
caractère courant

Definition at line 669 of file PFileParser.cpp.

669 {
670 if(isEndOfFile()) return '\0';
672}
PString p_fileContent
Contenu du fichier de configuration.
Definition PFileParser.h:99
bool isEndOfFile() const
Dit si on est à la fin du fichier.

References isEndOfFile(), p_currentChar, and p_fileContent.

+ Here is the call graph for this function:

◆ getCurrentCharIdx()

size_t PFileParser::getCurrentCharIdx ( ) const

Return the index of the current character.

Returns
index of the current character

Definition at line 708 of file PFileParser.cpp.

708 {
709 return p_currentChar;
710}

References p_currentChar.

◆ getCurrentRow()

PString PFileParser::getCurrentRow ( ) const

Get the current parsed row.

Returns
current parsed row

Definition at line 415 of file PFileParser.cpp.

415 {
416 if(p_fileContent.empty()) return "";
417 size_t currentCharIndex(p_currentChar);
418 char ch = p_fileContent[currentCharIndex];
419 size_t indexBeginRow(currentCharIndex);
420 size_t indexEndRow(currentCharIndex);
421 if(ch != '\n'){
422 while(p_fileContent[indexEndRow] != '\n' && !isEndOfFile()){
423 ++indexEndRow;
424 }
425 }
426 if(ch == '\n' && indexBeginRow != 0lu){
427 --indexBeginRow;
428 }
429 while(p_fileContent[indexBeginRow] != '\n' && indexBeginRow != 0lu){
430 --indexBeginRow;
431 }
432 if(p_fileContent[indexBeginRow] == '\n'){indexBeginRow++;}
433 return p_fileContent.substr(indexBeginRow, indexEndRow - indexBeginRow);
434}

References isEndOfFile(), p_currentChar, and p_fileContent.

+ Here is the call graph for this function:

◆ getEscapeChar()

char PFileParser::getEscapeChar ( ) const

Gets the escape character of the PFileParser.

Returns
escape character of the PFileParser

Definition at line 134 of file PFileParser.cpp.

134 {
135 return p_echapChar;
136}
char p_echapChar
Echap caracter.

References p_echapChar.

◆ getFileName()

PPath PFileParser::getFileName ( ) const

Fonction qui renvoie le nom du fichier que l'on a ouvert.

Returns
nom du fichier que l'on a ouvert

Definition at line 141 of file PFileParser.cpp.

141 {
142 return p_fileName;
143}
PPath p_fileName
Nom du fichier que l'on veut parser.
Definition PFileParser.h:97

References p_fileName.

Referenced by operator<<.

+ Here is the caller graph for this function:

◆ getLine()

size_t PFileParser::getLine ( ) const

Fonction qui renvoie le numéro de la ligne courante.

Returns
numéro de la ligne courante

Definition at line 685 of file PFileParser.cpp.

685 {
686 return p_currentLine;
687}
size_t p_currentLine
Numéro de la ligne courante.

References p_currentLine.

Referenced by operator<<.

+ Here is the caller graph for this function:

◆ getLineIndentation()

size_t PFileParser::getLineIndentation ( )

Get the current line indentation.

Returns
current line indentation

Definition at line 715 of file PFileParser.cpp.

715 {
716 //First, let's get the current column
717 size_t indentation(0lu), currentCharIdx(p_currentLineFirstColumn);
718 while(currentCharIdx < p_nbTotalChar && PString(" \t").find(p_fileContent[currentCharIdx])){
719 ++indentation;
720 ++currentCharIdx;
721 }
722 if(currentCharIdx > p_currentChar){
723 p_currentChar = currentCharIdx; //Anyway, it was just white character
724 }
725
726 return indentation;
727}
size_t p_nbTotalChar
Nombre de caractères total.

References p_currentChar, p_currentLineFirstColumn, p_fileContent, and p_nbTotalChar.

◆ getLocation()

PLocation PFileParser::getLocation ( ) const

Fonction qui renvoie la PLocation du PFileParser.

Returns
PLocation du PFileParser

Definition at line 732 of file PFileParser.cpp.

732 {
733 return PLocation(p_fileName, p_currentLine, getColumn());
734}
size_t getColumn() const
Fonction qui renvoie le numéro de la colonne du caractère courant.

References getColumn(), p_currentLine, and p_fileName.

Referenced by DicoValue::errorAt().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getNbTotalChar()

size_t PFileParser::getNbTotalChar ( ) const

Return the number of characters in the current opened file.

Returns
number of characters in the current opened file

Definition at line 701 of file PFileParser.cpp.

701 {
702 return p_nbTotalChar;
703}

References p_nbTotalChar.

◆ getNextChar()

char PFileParser::getNextChar ( )

Fonction qui renvoie le prochain caractère du fichier courant.

Returns
prochain caractère du fichier courant ou le caractère NULL si on est à la fin

Definition at line 187 of file PFileParser.cpp.

187 {
190 char ch = p_fileContent[p_currentChar];
191 return ch;
192 }else{
194 return '\0';
195 }
196}
void incrementCurrentChar(size_t nbChar=1lu)
Increment the current caracter.

References incrementCurrentChar(), p_currentChar, p_fileContent, and p_nbTotalChar.

+ Here is the call graph for this function:

◆ getNextToken() [1/2]

PString PFileParser::getNextToken ( )

Get the next token.

Returns
next token

Definition at line 148 of file PFileParser.cpp.

148 {
149 PString dummySkipedStr("");
150 return getNextToken(dummySkipedStr);
151}
PString getNextToken()
Get the next token.

References getNextToken().

Referenced by DicoValue::errorAt(), and getNextToken().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getNextToken() [2/2]

PString PFileParser::getNextToken ( PString & skippedStr)

Get the next token and return also the skipped characters until the next token.

Parameters
[out]skippedStr: string of skipped characters
Returns
next token

Definition at line 157 of file PFileParser.cpp.

157 {
158 if(isEndOfFile()) return "";
159 char ch = p_fileContent[p_currentChar];
160 while(!isEndOfFile() && p_listWhiteSpace.find(ch)){
161 skippedStr += ch;
163 if(isEndOfFile()) return "";
165 }
166 //We are sur ethe current char is not a white character
167 if(p_listSeparator.find(ch) && !isEndOfFile()){ //If is it a separator, we stop
169 PString s("");
170 s += ch;
171 return s;
172 }
173 //If not we get all characters until the next white character or separator character
174 PString buf("");
175 while(!isEndOfFile() && !p_listWhiteSpace.find(ch) && !p_listSeparator.find(ch)){
176 buf += ch;
178 if(isEndOfFile()){return buf;}
180 }
181 return buf;
182}
PString p_listSeparator
liste des séparateurs
PString p_listWhiteSpace
liste des espaces blancs

References incrementCurrentChar(), isEndOfFile(), p_currentChar, p_fileContent, p_listSeparator, and p_listWhiteSpace.

+ Here is the call graph for this function:

◆ getPrevCh()

char PFileParser::getPrevCh ( ) const

Renvoie le caractère courant.

Returns
caractère courant

Definition at line 677 of file PFileParser.cpp.

677 {
678 if(isEndOfFile() && p_currentChar > 0lu) return '\0';
679 return p_fileContent[p_currentChar - 1lu];
680}

References isEndOfFile(), p_currentChar, and p_fileContent.

+ Here is the call graph for this function:

◆ getSeparator()

PString PFileParser::getSeparator ( ) const

renvoie la liste des caractères séparateurs

Returns
liste des caractères séparateurs

Definition at line 662 of file PFileParser.cpp.

662 {
663 return p_listSeparator;
664}

References p_listSeparator.

◆ getStrComposedOf()

PString PFileParser::getStrComposedOf ( const PString & charset)

Get string composed of the characters in the string charset.

Parameters
charset: set of the available characters to get the current string
Returns
corresponding string

Definition at line 394 of file PFileParser.cpp.

394 {
395 PString tmpWhiteSpace(p_listWhiteSpace.eraseChar(charset));
396 if(tmpWhiteSpace != ""){
397 skipChars(tmpWhiteSpace);
398 }
399 std::string out("");
400 bool isInCharSet(true);
401 while(!isEndOfFile() && isInCharSet){
402 char ch = p_fileContent[p_currentChar];
403 isInCharSet = charset.find(ch);
404 if(isInCharSet){
405 out += ch;
407 }
408 }
409 return out;
410}
void skipChars(const PString &chToSkip)
Skip the characters in the given string.

References incrementCurrentChar(), isEndOfFile(), p_currentChar, p_fileContent, p_listWhiteSpace, and skipChars().

Referenced by isMatch(), and DicoValue::parseDicoValue().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getUntilKey()

PString PFileParser::getUntilKey ( const PString & patern)

Renvoie la chaine de caractère du caractère courant jusqu'à patern comprise.

Parameters
patern: séquence d'arrêt
Returns
chaine de caractère du caractère courant jusqu'à patern comprise

Definition at line 202 of file PFileParser.cpp.

202 {
203 if(patern == "" || p_nbTotalChar == 0lu || isEndOfFile()) return "";
204 return getUntilKeyWithoutPatern(patern) + patern;
205}
PString getUntilKeyWithoutPatern(const PString &patern)
Renvoie la chaine de caractère du caractère courant jusqu'à patern exclu.

References getUntilKeyWithoutPatern(), isEndOfFile(), and p_nbTotalChar.

Referenced by parse_generic_string().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getUntilKeyWithoutPatern()

PString PFileParser::getUntilKeyWithoutPatern ( const PString & patern)

Renvoie la chaine de caractère du caractère courant jusqu'à patern exclu.

Parameters
patern: séquence d'arrêt
Returns
chaine de caractère du caractère courant jusqu'à patern exclu

Definition at line 211 of file PFileParser.cpp.

211 {
212 if(patern == "" || p_nbTotalChar == 0lu || isEndOfFile()) return "";
213 size_t sizePatern(patern.size());
214 std::string out(""); //on évite les petits désagréments
215 size_t sizeSrc(p_nbTotalChar - p_currentChar);
216 size_t beginTest(0lu), beginLine(0lu), beginI(0lu), nbMatch(0lu);
217 for(size_t i(0lu); i < sizeSrc; ++i){
218 if(p_fileContent[p_currentChar] == patern[nbMatch] && !p_currentCharEchaped){ //si le caractère i est le même que le caractère nbMatch
219 if(nbMatch == 0lu){ //c'est le premier qu'on teste
220 beginTest = p_currentChar; //il faut donc se rappeler où on a commencer à faire le test
221 beginLine = p_currentLine;
222 beginI = i;
223 }
224 ++nbMatch; //la prochaîne fois on testera le caractère suivant
225 if(nbMatch == sizePatern){ //dans ce cas, on a tout testé et tout les caractères correspondent, donc on sauvegarde
227 return out;
228 }
229 }else{ //si le caractère i n'est pas le même caractère que nbMatch
230 if(nbMatch == 0lu){ //si on n'en avait pas trouver de bon avant
231 out += p_fileContent[p_currentChar]; //on ne change rien à ce caractère
232 }else{ //si on avais déjà tester des caractères avant
233 out += p_fileContent[beginTest];
234 p_currentChar = beginTest;
235 p_currentLine = beginLine;
236 i = beginI;
237 }
238 beginTest = 0lu; //on remet le début des tests à 0 (pour évité les dépassements, on ne sait jamais)
239 nbMatch = 0lu; //on remet ne nombre des tests à 0, comme on n'a pas trouver de nouveau le motif
240 }
242 }
243 return out;
244}
bool p_currentCharEchaped
True if the current char is escaped.

References incrementCurrentChar(), isEndOfFile(), p_currentChar, p_currentCharEchaped, p_currentLine, p_fileContent, and p_nbTotalChar.

Referenced by createNestedCallFromStr(), dico_create_nested_call(), getUntilKey(), and DicoValue::parseString().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getUntilKeyWithoutPaternExclude()

PString PFileParser::getUntilKeyWithoutPaternExclude ( const PString & patern,
const PString & strNotBeforeEndPatern )

Parse a string until the patern is found, only if it has not strNotBeforeEndPatern before it.

Parameters
patern: patern to be found
strNotBeforeEndPatern: string which cannot be found before the patern, otherwise the patern is not considered as the end
Returns
string unit patern, without it

Definition at line 251 of file PFileParser.cpp.

251 {
252 if(patern == "" || p_nbTotalChar == 0lu || isEndOfFile()) return "";
253 std::string out(""); //on évite les petits désagréments
254 bool prevSkipSpace(p_dontSkipSpace);
255 p_dontSkipSpace = true;
256 bool skiptNextEnd(false);
257 while(!isEndOfFile()){
258 if(isMatch(strNotBeforeEndPatern)){
259 out += strNotBeforeEndPatern;
260 skiptNextEnd = true;
261 }else if(skiptNextEnd){
262 skiptNextEnd = false;
265 }else if(isMatch(patern)){
266 p_dontSkipSpace = prevSkipSpace;
267 return out;
268 }else{
271 }
272 }
273 p_dontSkipSpace = prevSkipSpace;
274 return out;
275}
bool p_dontSkipSpace
Say if we don't want to skip the spaces.
bool isMatch(const PString &patern)
Says if the patern match with the current caracters of the PFileParser.

References incrementCurrentChar(), isEndOfFile(), isMatch(), p_currentChar, p_dontSkipSpace, p_fileContent, and p_nbTotalChar.

+ Here is the call graph for this function:

◆ getUntilKeyWithoutPaternRecurse() [1/2]

PString PFileParser::getUntilKeyWithoutPaternRecurse ( const PString & patern,
const PString & beginPatern )

Get the string until end sequence and take account recursive patern (embeded strings)

Parameters
patern: end patern
beginPatern: definition of new embeded string
Returns
output string

Definition at line 362 of file PFileParser.cpp.

363{
364 if(patern == "" || beginPatern == "" || p_nbTotalChar == 0lu || isEndOfFile()) return "";
365 bool prevSkipSpace(p_dontSkipSpace);
366 p_dontSkipSpace = true;
367 std::string out("");
368 long int nbEmbeded(1l);
369 while(!isEndOfFile()){
370 if(isMatch(patern)){
371 --nbEmbeded;
372 if(nbEmbeded <= 0l){
373 p_dontSkipSpace = prevSkipSpace;
374 return out;
375 }else{
376 out += patern;
377 }
378 }else if(isMatch(beginPatern)){
379 out += beginPatern;
380 ++nbEmbeded;
381 }else{
384 }
385 }
386 p_dontSkipSpace = prevSkipSpace;
387 return out;
388}

References incrementCurrentChar(), isEndOfFile(), isMatch(), p_currentChar, p_dontSkipSpace, p_fileContent, and p_nbTotalChar.

+ Here is the call graph for this function:

◆ getUntilKeyWithoutPaternRecurse() [2/2]

PString PFileParser::getUntilKeyWithoutPaternRecurse ( const PString & patern,
const PString & beginPatern,
const PString & allowedCharAfterBegin )

Get the string until end sequence and take account recursive patern (embeded strings)

Parameters
patern: end patern
beginPatern: definition of new embeded string
allowedCharAfterBegin: characters allowed after the beginPatern
Returns
output string

Definition at line 283 of file PFileParser.cpp.

285{
286 if(patern == "" || beginPatern == "" || p_nbTotalChar == 0lu || isEndOfFile()) return "";
287 bool prevSkipSpace(p_dontSkipSpace);
288 p_dontSkipSpace = true;
289 std::string out("");
290 long int nbEmbeded(1lu);
291 while(!isEndOfFile()){
292 if(isMatch(patern)){
293 --nbEmbeded;
294 if(nbEmbeded <= 0l){
295 p_dontSkipSpace = prevSkipSpace;
296 return out;
297 }else{
298 out += patern;
299 }
300 }else if(isMatch(beginPatern)){
301 if(allowedCharAfterBegin.find(p_fileContent[p_currentChar])){
302 out += beginPatern;
303 ++nbEmbeded;
304 }
305 }else{
308 }
309 }
310 p_dontSkipSpace = prevSkipSpace;
311 return out;
312}

References incrementCurrentChar(), isEndOfFile(), isMatch(), p_currentChar, p_dontSkipSpace, p_fileContent, and p_nbTotalChar.

+ Here is the call graph for this function:

◆ getUntilKeyWithoutPaternRecurseExclude()

PString PFileParser::getUntilKeyWithoutPaternRecurseExclude ( const PString & patern,
const PString & beginPatern,
const PString & echapExpr )

Get the string until end sequence and take account recursive patern (embeded strings)

Parameters
patern: end patern
beginPatern: definition of new embeded string
echapExpr: echap expression
Returns
output string

Definition at line 320 of file PFileParser.cpp.

322{
323 if(patern == "" || beginPatern == "" || p_nbTotalChar == 0lu || isEndOfFile()) return "";
324 bool prevSkipSpace(p_dontSkipSpace);
325 p_dontSkipSpace = true;
326 std::string out("");
327 long int nbEmbeded(1lu);
328 bool skiptNextEnd(false);
329 while(!isEndOfFile()){
330 if(isMatch(echapExpr)){
331 out += echapExpr;
332 skiptNextEnd = true;
333 }else if(skiptNextEnd){
334 skiptNextEnd = false;
337 }else if(isMatch(patern)){
338 --nbEmbeded;
339 if(nbEmbeded <= 0l){
340 p_dontSkipSpace = prevSkipSpace;
341 return out;
342 }else{
343 out += patern;
344 }
345 }else if(isMatch(beginPatern)){
346 out += beginPatern;
347 ++nbEmbeded;
348 }else{
351 }
352 }
353 p_dontSkipSpace = prevSkipSpace;
354 return out;
355}

References incrementCurrentChar(), isEndOfFile(), isMatch(), p_currentChar, p_dontSkipSpace, p_fileContent, and p_nbTotalChar.

+ Here is the call graph for this function:

◆ getWhiteSpace()

PString PFileParser::getWhiteSpace ( ) const

renvoie la liste des caractères blancs

Returns
liste des caractères blancs

Definition at line 655 of file PFileParser.cpp.

655 {
656 return p_listWhiteSpace;
657}

References p_listWhiteSpace.

◆ incrementCurrentChar()

void PFileParser::incrementCurrentChar ( size_t nbChar = 1lu)
private

Increment the current caracter.

Parameters
nbChar: number of char to go ahead

Definition at line 768 of file PFileParser.cpp.

768 {
769 for(size_t i(0lu); i < nbChar; ++i){
770 if(p_fileContent[p_currentChar] == '\n'){
772 }
776 }
777 }
778}
void incrementCurrentLine()
Increment the current line.

References incrementCurrentLine(), p_currentChar, p_currentCharEchaped, p_echapChar, p_fileContent, and p_nbTotalChar.

Referenced by getNextChar(), getNextToken(), getStrComposedOf(), getUntilKeyWithoutPatern(), getUntilKeyWithoutPaternExclude(), getUntilKeyWithoutPaternRecurse(), getUntilKeyWithoutPaternRecurse(), getUntilKeyWithoutPaternRecurseExclude(), isMatch(), isWhiteSpace(), skipChars(), and skipWhiteSpace().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ incrementCurrentLine()

void PFileParser::incrementCurrentLine ( )
private

Increment the current line.

Definition at line 760 of file PFileParser.cpp.

760 {
763}

References p_currentChar, p_currentLine, and p_currentLineFirstColumn.

Referenced by incrementCurrentChar().

+ Here is the caller graph for this function:

◆ initialisationPFileParser()

void PFileParser::initialisationPFileParser ( )
private

Fonction d'initialisation du PFileParser.

Definition at line 747 of file PFileParser.cpp.

747 {
748 p_currentChar = 0lu;
749 p_currentLine = 1lu;
751 p_fileContent = "";
752 p_listWhiteSpace = " \t\n";
753 p_listSeparator = "()[]{}+=.;,:/*%<>#";
754 p_echapChar = '\0';
755 p_dontSkipSpace = false;
756 p_currentCharEchaped = false;
757}

References p_currentChar, p_currentCharEchaped, p_currentLine, p_currentLineFirstColumn, p_dontSkipSpace, p_echapChar, p_fileContent, p_listSeparator, and p_listWhiteSpace.

Referenced by PFileParser().

+ Here is the caller graph for this function:

◆ isChSeparator()

bool PFileParser::isChSeparator ( ) const

Dis si le caractère courant est un séparateur.

Returns
true si caractère courant est un séparateur

Definition at line 126 of file PFileParser.cpp.

126 {
127 if(isEndOfFile()) return false;
129}

References isEndOfFile(), p_currentChar, p_fileContent, and p_listSeparator.

+ Here is the call graph for this function:

◆ isChSpace()

bool PFileParser::isChSpace ( ) const

Dis si le caractère courant est un caractère blanc.

Returns
true si caractère courant est un caractère blanc

Definition at line 118 of file PFileParser.cpp.

118 {
119 if(isEndOfFile()) return false;
121}

References isEndOfFile(), p_currentChar, p_fileContent, and p_listWhiteSpace.

+ Here is the call graph for this function:

◆ isEndOfFile()

◆ isMatch() [1/5]

PString PFileParser::isMatch ( const PParseSeq & seq)

Check the matching of a sequence in the current file.

Parameters
seq: sequence to be checked
Returns
matched string

Definition at line 582 of file PFileParser.cpp.

582 {
583 pushPosition();
584 PString body("");
585 const PVecParseStep & vecStep = seq.getVecStep();
586 PVecParseStep::const_iterator itStep(vecStep.begin());
587 bool isParseNextStep(true);
588 while(itStep != vecStep.end() && isParseNextStep){
589 isParseNextStep = itStep->getIsOptional();
590 const PVecParseCmd & vecCmd = itStep->getVecCmd();
591 bool isMatchedCmd(false);
592 PVecParseCmd::const_iterator itCmd(vecCmd.begin());
593 while(itCmd != vecCmd.end() && !isMatchedCmd){
594 PString str(itCmd->getStr());
595 if(itCmd->getIsMatch()){
596 isMatchedCmd = isMatch(str);
597 body += str;
598 }else{
599 PString res(getStrComposedOf(str));
600 if(res != ""){
601 body += res;
602 isMatchedCmd = true;
603 }
604 }
605 ++itCmd;
606 }
607 isParseNextStep |= isMatchedCmd;
608 ++itStep;
609 }
610 if(!isParseNextStep){
611 popPosition();
612 body = "";
613 }
614 return body;
615}
std::vector< PParseCmd > PVecParseCmd
std::vector< PParseStep > PVecParseStep
PString getStrComposedOf(const PString &charset)
Get string composed of the characters in the string charset.
void popPosition()
Get to the last saved position of the PFileParser in the current file.
void pushPosition()
Remember the current position of the PFileParser in the current file.
const std ::vector< PParseStep > & getVecStep() const
Get the variable p_vecStep.

References getStrComposedOf(), PParseSeq::getVecStep(), isMatch(), popPosition(), and pushPosition().

+ Here is the call graph for this function:

◆ isMatch() [2/5]

bool PFileParser::isMatch ( const PString & patern)

Says if the patern match with the current caracters of the PFileParser.

Parameters
patern: patern we want to check (this patern should not begin with white caracters)
Returns
true if the patern match, false otherwise If the patern match, the current char will be in the next char of the patern

Definition at line 441 of file PFileParser.cpp.

441 {
442 if(patern == "" || isEndOfFile() || p_currentCharEchaped) return false;
444 size_t nbCharPatern(patern.size());
445 if(p_currentChar + nbCharPatern > p_nbTotalChar){return false;}
446 bool match = true;
447 size_t i(0lu);
448 while(match && i < nbCharPatern){
449 match = (patern[i] == p_fileContent[p_currentChar + i]);
450 ++i;
451 }
452 if(match){
453 incrementCurrentChar(nbCharPatern);
454 }
455 return match;
456}
void skipWhiteSpace()
Skip the white space if there is at the current caracter position.

References incrementCurrentChar(), isEndOfFile(), p_currentChar, p_currentCharEchaped, p_fileContent, p_nbTotalChar, and skipWhiteSpace().

Referenced by getUntilKeyWithoutPaternExclude(), getUntilKeyWithoutPaternRecurse(), getUntilKeyWithoutPaternRecurse(), getUntilKeyWithoutPaternRecurseExclude(), isMatch(), isMatch(), isMatch(), isMatch(), isMatchRewind(), isMatchSeq(), isMatchToken(), parse_generic_string(), DicoValue::parseDicoValue(), DicoValue::parseList(), DicoValue::parseListOrMap(), and DicoValue::parseString().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isMatch() [3/5]

bool PFileParser::isMatch ( const PString & patern,
const PString & forbiddenCharBefore )

Says if the patern match with the current caracters of the PFileParser.

Parameters
patern: patern we want to check (this patern should not begin with white caracters)
forbiddenCharBefore: lisr of characters which cannot be just before the first character of the patern
Returns
true if the patern match, false otherwise If the patern match, the current char will be in the next char of the patern

Definition at line 495 of file PFileParser.cpp.

495 {
496 if(p_currentChar > 0lu){
497 //If we find a forbidden character before the current char, the patern is canceled
498 if(forbiddenCharBefore.find(p_fileContent[p_currentChar - 1lu])){
499 return false;
500 }
501 }
502 return isMatch(patern);
503}

References isMatch(), p_currentChar, and p_fileContent.

+ Here is the call graph for this function:

◆ isMatch() [4/5]

PString PFileParser::isMatch ( const PVecString & patern)

Check the matching between the current caracters and all the string in the vector.

Parameters
patern: vector of the patern we want to check
Returns
matching patern if there is one, empty string otherwise

Definition at line 536 of file PFileParser.cpp.

536 {
537 if(patern.size() == 0lu) return "";
538 PVecString::const_iterator it(patern.begin());
539 while(it != patern.end()){
540 if(isMatch(*it)) return *it;
541 ++it;
542 }
543 return "";
544}

References isMatch().

+ Here is the call graph for this function:

◆ isMatch() [5/5]

PString PFileParser::isMatch ( const std::vector< PVecString > & patern)

Check the matching between the current caracters and all the string in the list of list of string.

Parameters
patern: list of the list of the patern we want to check
Returns
matching patern if there is one, empty string otherwise

Definition at line 564 of file PFileParser.cpp.

564 {
565 if(patern.size() == 0lu) return "";
566 std::vector<PVecString >::const_iterator itList(patern.begin());
567 while(itList != patern.end()){
568 PVecString::const_iterator it(itList->begin());
569 while(it != itList->end()){
570 if(isMatch(*it)) return *it;
571 ++it;
572 }
573 ++itList;
574 }
575 return "";
576}

References isMatch().

+ Here is the call graph for this function:

◆ isMatchRewind()

bool PFileParser::isMatchRewind ( const PString & patern)

Do a isMatch and then go back at the previous position.

Parameters
patern: patern we want to check (this patern should not begin with white caracters)
Returns
true if the patern match, false otherwise If the patern match, the current char will be in the next char of the patern

Definition at line 463 of file PFileParser.cpp.

463 {
464 pushPosition();
465 bool b = isMatch(patern);
466 popPosition();
467 return b;
468}

References isMatch(), popPosition(), and pushPosition().

Referenced by DicoValue::parseList(), and DicoValue::parseListOrMap().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isMatchSeq()

bool PFileParser::isMatchSeq ( const PVecString & patern,
bool alwaysPopBack = false )

Match a sequence of token in a vector.

Parameters
patern: set of token to match in this order and totally
alwaysPopBack: true to make the PFileParser at the exact same place before the check even is the sequence matches
Returns
true if the full sequence matches, false otherwise

Definition at line 475 of file PFileParser.cpp.

475 {
476 pushPosition();
477 PVecString::const_iterator it(patern.begin());
478 bool matchPatern(true);
479 while(it != patern.end() && matchPatern){
480 matchPatern = isMatch(*it);
481 ++it;
482 }
483 if(!matchPatern || alwaysPopBack){
484 popPosition();
485 }
486 return matchPatern;
487}

References isMatch(), popPosition(), and pushPosition().

+ Here is the call graph for this function:

◆ isMatchToken() [1/3]

bool PFileParser::isMatchToken ( const PString & patern)

Says if the patern match with the current caracters of the PFileParser but treats the string as a token (cannot be part of a word)

Parameters
patern: patern we want to check (this patern should not begin with white caracters)
Returns
true if the patern match, false otherwise If the patern match, the current char will be in the next char of the patern

Definition at line 510 of file PFileParser.cpp.

510 {
511 pushPosition();
512 if(!isMatch(patern)){
513 popPosition();
514 return false;
515 }
516 PString letterNumberUnderscore("_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ");
517 if(p_currentChar > patern.size()){
518 if(letterNumberUnderscore.find(p_fileContent[p_currentChar - patern.size() - 1lu])){
519 popPosition();
520 return false;
521 }
522 }
524 if(letterNumberUnderscore.find(p_fileContent[p_currentChar])){
525 popPosition();
526 return false;
527 }
528 }
529 return true;
530}

References isMatch(), p_currentChar, p_fileContent, p_nbTotalChar, popPosition(), and pushPosition().

Referenced by isMatchToken(), and isMatchToken().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isMatchToken() [2/3]

PString PFileParser::isMatchToken ( const PVecString & patern)

Check the matching between the current caracters and all the string in the vector but treats the string as a token (cannot be part of a word)

Parameters
patern: vector of the patern we want to check
Returns
matching patern if there is one, empty string otherwise

Definition at line 550 of file PFileParser.cpp.

550 {
551 if(patern.size() == 0lu) return "";
552 PVecString::const_iterator it(patern.begin());
553 while(it != patern.end()){
554 if(isMatchToken(*it)) return *it;
555 ++it;
556 }
557 return "";
558}
bool isMatchToken(const PString &patern)
Says if the patern match with the current caracters of the PFileParser but treats the string as a tok...

References isMatchToken().

+ Here is the call graph for this function:

◆ isMatchToken() [3/3]

template<typename T>
bool PFileParser::isMatchToken ( PString & matchKey,
T & matchValue,
const std::map< PString, T > & patern )

Check if one key of the map, matches the current token.

Parameters
[out]matchKey: matching key (on success)
[out]matchValue: matching value (on success)
patern: map of patterns to be checked
Returns
true if one of the map key matches the current token, false otherwise

Definition at line 19 of file PFileParser_impl.h.

19 {
20 if(patern.size() == 0lu) return false;
21 typename std::map<PString, T>::const_iterator it(patern.begin());
22 while(it != patern.end()){
23 if(isMatchToken(it->first)){
24 matchKey = it->first;
25 matchValue = it->second;
26 return true;
27 }
28 ++it;
29 }
30 return false;
31}

References isMatchToken().

+ Here is the call graph for this function:

◆ isWhiteSpace()

bool PFileParser::isWhiteSpace ( )

Says if the current char is a white space.

Returns
true if the current char is a white space, false if not If it matchs, the current caracter will be put on a non white space caracter

Definition at line 621 of file PFileParser.cpp.

621 {
622 if(isEndOfFile()) return false;
624 do{
627 return true;
628 }else return false;
629}

References incrementCurrentChar(), isEndOfFile(), p_currentChar, p_fileContent, and p_listWhiteSpace.

+ Here is the call graph for this function:

◆ open()

bool PFileParser::open ( const PPath & fileName)

Fonction qui ouvre le fichier que l'on va parser.

Parameters
fileName: nom du fichier à ouvrir
Returns
true si la fonction à réussie, false sinon

Definition at line 24 of file PFileParser.cpp.

24 {
25 p_fileName = fileName;
26 p_fileContent = fileName.loadFileContent();
28 return (p_fileContent != "");
29}

References p_fileContent, p_fileName, and p_nbTotalChar.

Referenced by DicoValue::load().

+ Here is the caller graph for this function:

◆ popPosition()

void PFileParser::popPosition ( )

Get to the last saved position of the PFileParser in the current file.

Definition at line 99 of file PFileParser.cpp.

99 {
100 if(p_vecPosition.size() == 0lu){
101 return;
102 }
104 p_currentLine = p_vecLine.back();
105 p_vecPosition.pop_back();
106 p_vecLine.pop_back();
107}

References p_currentChar, p_currentLine, p_vecLine, and p_vecPosition.

Referenced by isMatch(), isMatchRewind(), isMatchSeq(), and isMatchToken().

+ Here is the caller graph for this function:

◆ pushPosition()

void PFileParser::pushPosition ( )

Remember the current position of the PFileParser in the current file.

Definition at line 93 of file PFileParser.cpp.

93 {
95 p_vecLine.push_back(p_currentLine);
96}

References p_currentChar, p_currentLine, p_vecLine, and p_vecPosition.

Referenced by isMatch(), isMatchRewind(), isMatchSeq(), and isMatchToken().

+ Here is the caller graph for this function:

◆ setColumn()

void PFileParser::setColumn ( size_t currentCol)

Set the current column of the PFileParser.

Parameters
currentCol: current column of the PFileParser

Definition at line 81 of file PFileParser.cpp.

81 {
82 p_currentLineFirstColumn = currentCol;
83}

References p_currentLineFirstColumn.

Referenced by setLocation().

+ Here is the caller graph for this function:

◆ setEscapeChar()

void PFileParser::setEscapeChar ( char escapeChar)

Sets the escape character of the PFileParser.

Parameters
escapeChar: escape character of the PFileParser

Definition at line 58 of file PFileParser.cpp.

58 {
59 p_echapChar = escapeChar;
60}

References p_echapChar.

Referenced by DicoValue::fromString(), and DicoValue::loadParser().

+ Here is the caller graph for this function:

◆ setFileContent()

void PFileParser::setFileContent ( const PString & fileContent)

Set the file content.

Parameters
fileContent: file content

Definition at line 50 of file PFileParser.cpp.

50 {
51 p_fileContent = fileContent;
53}

References p_fileContent, and p_nbTotalChar.

Referenced by createNestedCallFromStr(), dico_create_nested_call(), and DicoValue::fromString().

+ Here is the caller graph for this function:

◆ setLine()

void PFileParser::setLine ( size_t currentLine)

Set the current line of the PFileParser.

Parameters
currentLine: current line of the PFileParser

Definition at line 74 of file PFileParser.cpp.

74 {
75 p_currentLine = currentLine;
76}

References p_currentLine.

Referenced by setLocation().

+ Here is the caller graph for this function:

◆ setLocation()

void PFileParser::setLocation ( const PLocation & location)

Set the current location of the PFileParser.

Parameters
location: current location of the PFileParser

Definition at line 65 of file PFileParser.cpp.

65 {
66 setLine(location.getLine());
67 setColumn(location.getColumn());
68 p_fileName = location.getFileName();
69}
void setLine(size_t currentLine)
Set the current line of the PFileParser.
void setColumn(size_t currentCol)
Set the current column of the PFileParser.
size_t getLine() const
renvoie la ligne du PLocation
Definition PLocation.cpp:67
PPath getFileName() const
renvoie le fichier du PLocation
Definition PLocation.cpp:60
size_t getColumn() const
renvoie la colonne du PLocation
Definition PLocation.cpp:74

References PLocation::getColumn(), PLocation::getFileName(), PLocation::getLine(), p_fileName, setColumn(), and setLine().

+ Here is the call graph for this function:

◆ setSeparator()

void PFileParser::setSeparator ( const PString & separator)

Initialise la liste des caractères séparateurs.

Parameters
separator: liste des caractères séparateurs Se sont les caractères que l'on ne prend en compte un par un

Definition at line 43 of file PFileParser.cpp.

43 {
44 p_listSeparator = separator;
45}

References p_listSeparator.

Referenced by DicoValue::loadParser().

+ Here is the caller graph for this function:

◆ setWhiteSpace()

void PFileParser::setWhiteSpace ( const PString & whiteSpace)

Initialise la liste des caractères blancs.

Parameters
whiteSpace: liste des caractères blancs Se sont les caractères que l'on ne prend jamais en compte

Definition at line 35 of file PFileParser.cpp.

35 {
36 p_listWhiteSpace = whiteSpace;
37}

References p_listWhiteSpace.

Referenced by DicoValue::loadParser().

+ Here is the caller graph for this function:

◆ skipChars()

void PFileParser::skipChars ( const PString & chToSkip)

Skip the characters in the given string.

Parameters
chToSkip: set of characters tb skip

Definition at line 644 of file PFileParser.cpp.

644 {
645 if(chToSkip.find(p_fileContent[p_currentChar])){
646 do{
648 }while(chToSkip.find(p_fileContent[p_currentChar]) && !isEndOfFile());
649 }
650}

References incrementCurrentChar(), isEndOfFile(), p_currentChar, and p_fileContent.

Referenced by getStrComposedOf().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ skipWhiteSpace()

void PFileParser::skipWhiteSpace ( )

Skip the white space if there is at the current caracter position.

Definition at line 632 of file PFileParser.cpp.

632 {
633 if(p_dontSkipSpace){return;}
635 do{
638 }
639}

References incrementCurrentChar(), isEndOfFile(), p_currentChar, p_dontSkipSpace, p_fileContent, and p_listWhiteSpace.

Referenced by isMatch(), DicoValue::loadParser(), and DicoValue::parseDicoValue().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Friends And Related Symbol Documentation

◆ operator<<

std::ostream & operator<< ( std::ostream & out,
const PFileParser & other )
friend

Définition de l'opérateur de flux sortant.

Parameters
out: flux dans lequel il faut écrire
other: PFileParser
Returns
flux contenant le PFileParser

Definition at line 741 of file PFileParser.cpp.

741 {
742 out << "file '" << other.getFileName() << "' line " << other.getLine() << ":" << other.getColumn();
743 return out;
744}
size_t getLine() const
Fonction qui renvoie le numéro de la ligne courante.
PPath getFileName() const
Fonction qui renvoie le nom du fichier que l'on a ouvert.

References getColumn(), getFileName(), getLine(), and PFileParser().

Member Data Documentation

◆ p_currentChar

◆ p_currentCharEchaped

bool PFileParser::p_currentCharEchaped
private

True if the current char is escaped.

Definition at line 121 of file PFileParser.h.

Referenced by getUntilKeyWithoutPatern(), incrementCurrentChar(), initialisationPFileParser(), and isMatch().

◆ p_currentLine

size_t PFileParser::p_currentLine
private

◆ p_currentLineFirstColumn

size_t PFileParser::p_currentLineFirstColumn
private

Number of the first column caracter of the current line.

Definition at line 107 of file PFileParser.h.

Referenced by getColumn(), getLineIndentation(), incrementCurrentLine(), initialisationPFileParser(), and setColumn().

◆ p_dontSkipSpace

bool PFileParser::p_dontSkipSpace
private

◆ p_echapChar

char PFileParser::p_echapChar
private

Echap caracter.

Definition at line 113 of file PFileParser.h.

Referenced by getEscapeChar(), incrementCurrentChar(), initialisationPFileParser(), and setEscapeChar().

◆ p_fileContent

◆ p_fileName

PPath PFileParser::p_fileName
private

Nom du fichier que l'on veut parser.

Definition at line 97 of file PFileParser.h.

Referenced by getFileName(), getLocation(), open(), and setLocation().

◆ p_listSeparator

PString PFileParser::p_listSeparator
private

liste des séparateurs

Definition at line 111 of file PFileParser.h.

Referenced by getNextToken(), getSeparator(), initialisationPFileParser(), isChSeparator(), and setSeparator().

◆ p_listWhiteSpace

PString PFileParser::p_listWhiteSpace
private

◆ p_nbTotalChar

◆ p_vecLine

std::vector<size_t> PFileParser::p_vecLine
private

Vector of all the checkpoint rows in the text file (added with pushPosition() and removed with popPosition() or clear()

Definition at line 117 of file PFileParser.h.

Referenced by clear(), popPosition(), and pushPosition().

◆ p_vecPosition

std::vector<size_t> PFileParser::p_vecPosition
private

Vector of all the checkpoint positions in the text file (added with pushPosition() and removed with popPosition() or clear()

Definition at line 115 of file PFileParser.h.

Referenced by clear(), popPosition(), and pushPosition().


The documentation for this class was generated from the following files: