PhoenixInkscape  2.0.0
Generate multiple png files with svg inkscape files
main.cpp
Go to the documentation of this file.
1 
2 /***************************************
3  Auteur : Pierre Aubert
4  Mail : pierre.aubert@lapp.in2p3.fr
5  Licence : CeCILL-C
6 ****************************************/
7 
8 #include "phoenix_assert.h"
9 #include "phoenix_check.h"
10 #include "PFileParser.h"
11 
14  PFileParser parser;
15  parser.setFileContent("Les GPUs\\dots{} pour quoi faire ?}\\label{chapGPU}\n");
16 
17  PString res(parser.getUntilKeyWithoutPatern("}"));
18  phoenix_assert(phoenix_check("testPFileParserPartern", res, "Les GPUs\\dots{"));
19 }
20 
23  PFileParser parser;
24  parser.setFileContent("Les GPUs\\dots{} pour quoi faire ?}\\label{chapGPU}\n");
25 
26  PString res(parser.getUntilKeyWithoutPaternExclude("}", "{"));
27  phoenix_assert(phoenix_check("testPFileParserParternExclude", res, "Les GPUs\\dots{} pour quoi faire ?"));
28 }
29 
32  PFileParser parser;
33  parser.setFileContent("Les GPUs\\dots{} pour quoi faire ?}\\label{chapGPU}\n");
34 
35  PString res(parser.getUntilKeyWithoutPaternRecurse("}", "{"));
36  phoenix_assert(phoenix_check("testPFileParserParternRecurse", res, "Les GPUs\\dots{} pour quoi faire ?"));
37 }
38 
41  PFileParser parser;
42  parser.setFileContent("des trucs \"a dire\" et d'autres chose");
43 
44  PString res(parser.getUntilKeyWithoutPaternRecurse("\"", "\""));
45  phoenix_assert(phoenix_check("testPFileParserParternRecurse2", res, "des trucs "));
46 }
47 
50  PFileParser parser;
51  parser.setFileContent("Les GPUs\\dots{} pour quoi faire ?}\\label{chapGPU}\n");
52 
53  PString res(parser.getUntilKeyWithoutPaternRecurse("}", "{", "} \\abcdefhijklmnopqrstuvwxyz"));
54  phoenix_assert(phoenix_check("testPFileParserParternRecurseAllowChar", res, "Les GPUs\\dots{} pour quoi faire ?"));
55 }
56 
59  PFileParser parser;
60  parser.setFileContent("des trucs \\\"a\\\" dire\" et d'autres chose");
61 
62  PString res(parser.getUntilKeyWithoutPaternRecurseExclude("\"", "\"", "\\"));
63  phoenix_assert(phoenix_check("testPFileParserParternRecurseExcludeEnd", res, "des trucs \\\"a\\\" dire"));
64 }
65 
68  PFileParser parser;
69  parser.setFileContent("des trucs \"a dire\" et d'autres chose");
70 
71  PString res(parser.getUntilKeyWithoutPaternRecurseExclude("\"", "\"", "\\"));
72  phoenix_assert(phoenix_check("testPFileParserParternRecurseExcludeEnd2", res, "des trucs "));
73 }
74 
77  PParseSeq seq;
78  PParseStep stepBegin;
79  stepBegin.setIsOptional(false);
80  PParseCmd cmdBegin;
81  cmdBegin.setIsMatch(true);
82  cmdBegin.setStr("\\begin");
83  stepBegin.getVecCmd().push_back(cmdBegin);
84  seq.getVecStep().push_back(stepBegin);
85  PParseStep stepOpenBrace;
86  stepOpenBrace.setIsOptional(false);
87  PParseCmd cmdOpenBrace;
88  cmdOpenBrace.setIsMatch(true);
89  cmdOpenBrace.setStr("{");
90  stepOpenBrace.getVecCmd().push_back(cmdOpenBrace);
91  seq.getVecStep().push_back(stepOpenBrace);
92  PParseStep stepEnvName;
93  stepEnvName.setIsOptional(false);
94  PParseCmd cmdEnvName;
95  cmdEnvName.setIsMatch(true);
96  cmdEnvName.setStr("envName");
97  stepEnvName.getVecCmd().push_back(cmdEnvName);
98  seq.getVecStep().push_back(stepEnvName);
99  PParseStep stepEndBrace;
100  stepEndBrace.setIsOptional(false);
101  PParseCmd cmdEndBrace;
102  cmdEndBrace.setIsMatch(true);
103  cmdEndBrace.setStr("}");
104  stepEndBrace.getVecCmd().push_back(cmdEndBrace);
105  seq.getVecStep().push_back(stepEndBrace);
106 
107  PFileParser parser;
108  parser.setFileContent("\\begin { envName } des trucs\n");
109  PString res = parser.isMatch(seq);
110  phoenix_assert(phoenix_check("testPFileParserSeq", res, "\\begin{envName}"));
111 }
112 
115  PVecString vecPatern;
116  vecPatern.push_back("\\begin");
117  vecPatern.push_back("{");
118  vecPatern.push_back("envName");
119  vecPatern.push_back("}");
120 
121  PFileParser parser;
122  parser.setFileContent("\\begin { envName } des trucs\n");
123  phoenix_assert(parser.isMatchSeq(vecPatern));
124 }
125 
126 
129  PParseSeq seq;
130  PParseStep step;
131  step.setIsOptional(false);
132  PParseCmd cmdBegin;
133  cmdBegin.setIsMatch(true);
134  cmdBegin.setStr("\\begin");
135  step.getVecCmd().push_back(cmdBegin);
136  PParseCmd cmdEnvName;
137  cmdEnvName.setIsMatch(true);
138  cmdEnvName.setStr("envName");
139  step.getVecCmd().push_back(cmdEnvName);
140  PParseCmd cmdEndBrace;
141  cmdEndBrace.setIsMatch(true);
142  cmdEndBrace.setStr("}");
143  step.getVecCmd().push_back(cmdEndBrace);
144  seq.getVecStep().push_back(step);
145 
146  PFileParser parser;
147  parser.setFileContent("\\begin { envName } des trucs\n");
148  PString res = parser.isMatch(seq);
149  phoenix_assert( phoenix_check("testPFileParserSeqOneStep", res, "\\begin"));
150 }
151 
154  PFileParser parser;
155  parser.setFileContent(" Les GPUs\\dots{} pour quoi faire ?}\\label{chapGPU}\n");
156  phoenix_assert(!parser.isMatch("Autre"));
157  phoenix_assert(parser.isMatch("Les"));
158  phoenix_assert(parser.isMatch("GPU"));
159 }
160 
162 
167 bool testPFileParserGetUntilKey(const PString & inputStr, const PString & search, const PString & result){
168  bool b(true);
169  PFileParser parser2;
170  parser2.setFileContent(inputStr);
171 
172  PString strFound(parser2.getUntilKey(search));
173 // std::cout << "testPFileParserGetUntilKey : inputStr = '" << inputStr << "', search = '"<<search<<"', strFound = '" << strFound << "', expectedResult = '" << result << "'" << std::endl;
174 
175  b &= phoenix_check("testPFileParserGetUntilKey", strFound, result);
176 // phoenix_functionOk("testPFileParserGetUntilKey", b);
177  return b;
178 }
179 
182  PFileParser parser;
183  parser.setFileContent("e :e");
184  parser.setSeparator(":");
185  parser.setWhiteSpace(" ");
186  parser.setLocation(PLocation(PPath("fileName"), 42, 23));
187  parser.setLine(24);
188  parser.setColumn(2);
189  parser.popPosition();
190  parser.getEscapeChar();
191  parser.getFileName();
192  parser.clear();
193 
194  phoenix_assert(!parser.isChSpace());
195  phoenix_assert(!parser.isChSeparator());
196  std::cout << "testPFileParserBase : next char '" << parser.getNextChar() << "'" << std::endl;
197  phoenix_assert(parser.isChSpace());
198  std::cout << "testPFileParserBase : next char '" << parser.getNextChar() << "'" << std::endl;
199  phoenix_assert(parser.isChSeparator());
200  std::cout << "testPFileParserBase : next char '" << parser.getNextChar() << "'" << std::endl;
201  phoenix_assert(!parser.isChSpace());
202  phoenix_assert(!parser.isChSeparator());
203 }
204 
207  PFileParser parser;
208  parser.setFileContent("one row\none other row");
209  phoenix_assert(parser.getCurrentRow() == "one row");
210 }
211 
214  PFileParser parser;
215  parser.setFileContent("one row\none other row");
216 
217  std::vector<PString> vecToken;
218  phoenix_assert(parser.isMatch(vecToken) == "");
219  vecToken.push_back("other");
220  phoenix_assert(parser.isMatch(vecToken) == "");
221  vecToken.push_back("one");
222  phoenix_assert(parser.isMatch(vecToken) == "one");
223 }
224 
227  PFileParser parser;
228  parser.setFileContent("one row\none other row");
229 
230  std::vector<PString> vecToken;
231  phoenix_assert(parser.isMatchToken(vecToken) == "");
232  vecToken.push_back("other");
233  phoenix_assert(parser.isMatchToken(vecToken) == "");
234  vecToken.push_back("one");
235  phoenix_assert(parser.isMatchToken(vecToken) == "one");
236 }
237 
240  PFileParser parser;
241  parser.setFileContent("one row\none other row");
242 
243  std::map<PString, int> mapToken;
244  PString matchKey("");
245  int matchValue(0);
246  phoenix_assert(!parser.isMatchToken(matchKey, matchValue, mapToken));
247  mapToken["other"] = 23;
248  phoenix_assert(!parser.isMatchToken(matchKey, matchValue, mapToken));
249 
250  mapToken["one"] = 1;
251  phoenix_assert(parser.isMatchToken(matchKey, matchValue, mapToken));
252  phoenix_assert(matchKey == "one");
253  phoenix_assert(matchValue == 1);
254 }
255 
258  PFileParser parser;
259  parser.setFileContent("one row\none other row");
260 
261  std::vector<std::vector<PString> > patern;
262  phoenix_assert(parser.isMatch(patern) == "");
263  PVecString vecPatern;
264  vecPatern.push_back("other");
265  patern.push_back(vecPatern);
266  phoenix_assert(parser.isMatch(patern) == "");
267  vecPatern.push_back("one");
268  patern.push_back(vecPatern);
269  phoenix_assert(parser.isMatch(patern) == "one");
270  phoenix_assert(parser.isWhiteSpace());
271  phoenix_assert(parser.getSeparator() != "");
272  phoenix_assert(parser.getCurrentCh() == 'r');
273  phoenix_assert(parser.getPrevCh() == ' ');
274  phoenix_assert(parser.getLine() == 1lu);
275  phoenix_assert(parser.getCurrentCharIdx() == 4lu);
276  std::cout << parser << std::endl;
277 }
278 
281  PFileParser parser;
282  parser.setFileContent("e : e");
283  parser.setWhiteSpace(" ");
284  parser.setSeparator(":");
285 
286  PString token1(parser.getNextToken());
287  phoenix_assert(token1 == "e");
288 // std::cout << "testPFileParserGetNextToken : b = " << b << ", token1 = '" << token1 << "'" << std::endl;
289  PString token2(parser.getNextToken());
290  phoenix_assert(token2 == ":");
291 // std::cout << "testPFileParserGetNextToken : b = " << b << ", token2 = '" << token2 << "'" << std::endl;
292  PString token3(parser.getNextToken());
293  phoenix_assert(token3 == "e");
294 // std::cout << "testPFileParserGetNextToken : b = " << b << ", token3 = '" << token3 << "'" << std::endl;
295  phoenix_assert(parser.getNextToken() == "");
296 }
297 
300  PFileParser parser;
301  parser.setFileContent("e : e");
302  parser.setWhiteSpace(" ");
303  parser.setSeparator(":");
304 
305  PString skippedStr("");
306  PString token1(parser.getNextToken(skippedStr));
307  phoenix_assert(token1 == "e");
308 // std::cout << "testPFileParserGetNextToken2 : b = " << b << ", token1 = '" << token1 << "'" << std::endl;
309  phoenix_assert(skippedStr == "");
310 // std::cout << "testPFileParserGetNextToken2 : b = " << b << ", skippedStr = '" << skippedStr << "'" << std::endl;
311 
312  skippedStr = "";
313  PString token2(parser.getNextToken(skippedStr));
314  phoenix_assert(token2 == ":");
315 // std::cout << "testPFileParserGetNextToken2 : b = " << b << ", token2 = '" << token2 << "'" << std::endl;
316  phoenix_assert(skippedStr == " ");
317 // std::cout << "testPFileParserGetNextToken2 : b = " << b << ", skippedStr = '" << skippedStr << "'" << std::endl;
318 
319  skippedStr = "";
320  PString token3(parser.getNextToken(skippedStr));
321  phoenix_assert(token3 == "e");
322 // std::cout << "testPFileParserGetNextToken2 : b = " << b << ", token3 = '" << token3 << "'" << std::endl;
323  phoenix_assert(skippedStr == " ");
324 // std::cout << "testPFileParserGetNextToken2 : b = " << b << ", skippedStr = '" << skippedStr << "'" << std::endl;
325  phoenix_assert(parser.getNextToken(skippedStr) == "");
326 }
327 
328 int main(int argc, char** argv){
341 
342  phoenix_assert(testPFileParserGetUntilKey("let's test a string", "", ""));
343  phoenix_assert(testPFileParserGetUntilKey("let's test a string", "some", "let's test a stringsome"));
344  phoenix_assert(testPFileParserGetUntilKey("let's test a string", "test", "let's test"));
345 
353  return 0;
354 }
355 
356 
std::vector< PString > PVecString
Definition: PString.h:96
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.
Definition: PFileParser.cpp:43
size_t getLine() const
Fonction qui renvoie le numéro de la ligne courante.
bool isWhiteSpace()
Says if the current char is a white space.
bool isMatchSeq(const PVecString &patern, bool alwaysPopBack=false)
Match a sequence of token in a vector.
bool isChSpace() const
Dis si le caractère courant est un caractère blanc.
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 getCurrentRow() const
Get the current parsed row.
PString getNextToken()
Get the next token.
PString getUntilKeyWithoutPatern(const PString &patern)
Renvoie la chaine de caractère du caractère courant jusqu'à patern exclu.
void clear()
Clear the save position of the parser in ther current file.
PString getSeparator() const
renvoie la liste des caractères séparateurs
PString getUntilKeyWithoutPaternRecurse(const PString &patern, const PString &beginPatern, const PString &allowedCharAfterBegin)
Get the string until end sequence and take account recursive patern (embeded strings)
void setLine(size_t currentLine)
Set the current line of the PFileParser.
Definition: PFileParser.cpp:74
void setWhiteSpace(const PString &whiteSpace)
Initialise la liste des caractères blancs.
Definition: PFileParser.cpp:35
bool isMatchToken(const PString &patern)
Says if the patern match with the current caracters of the PFileParser but treats the string as a tok...
bool isMatch(const PString &patern)
Says if the patern match with the current caracters of the PFileParser.
char getCurrentCh() const
Renvoie le caractère courant.
void popPosition()
Get to the last saved position of the PFileParser in the current file.
Definition: PFileParser.cpp:99
PString getUntilKey(const PString &patern)
Renvoie la chaine de caractère du caractère courant jusqu'à patern comprise.
PPath getFileName() const
Fonction qui renvoie le nom du fichier que l'on a ouvert.
bool isChSeparator() const
Dis si le caractère courant est un séparateur.
void setColumn(size_t currentCol)
Set the current column of the PFileParser.
Definition: PFileParser.cpp:81
void setLocation(const PLocation &location)
Set the current location of the PFileParser.
Definition: PFileParser.cpp:65
void setFileContent(const PString &fileContent)
Set the file content.
Definition: PFileParser.cpp:50
PString getUntilKeyWithoutPaternRecurseExclude(const PString &patern, const PString &beginPatern, const PString &echapExpr)
Get the string until end sequence and take account recursive patern (embeded strings)
char getPrevCh() const
Renvoie le caractère courant.
size_t getCurrentCharIdx() const
Return the index of the current character.
char getEscapeChar() const
Gets the escape character of the PFileParser.
char getNextChar()
Fonction qui renvoie le prochain caractère du fichier courant.
Classe qui permet de décrire une localisation, avec un nom de fichier et une ligne.
Definition: PLocation.h:15
Parser command.
Definition: PParseSeq.h:33
void setIsMatch(bool isMatch)
Set the variable p_isMatch, of type 'bool'.
Definition: PParseSeq.cpp:51
void setStr(const PString &str)
Set the variable p_str, of type 'PString'.
Definition: PParseSeq.cpp:58
Parsing sequence.
Definition: PParseSeq.h:77
const std ::vector< PParseStep > & getVecStep() const
Get the variable p_vecStep.
Definition: PParseSeq.cpp:256
Describes a parsing step.
Definition: PParseSeq.h:55
void setIsOptional(bool isOptional)
Set the variable p_isOptional, of type 'bool'.
Definition: PParseSeq.cpp:150
const std ::vector< PParseCmd > & getVecCmd() const
Get the variable p_vecCmd.
Definition: PParseSeq.cpp:178
Path of a directory or a file.
Definition: PPath.h:17
Extends the std::string.
Definition: PString.h:16
#define phoenix_assert(isOk)
bool phoenix_check(const std::string &testName, const std::string &val, const std::string &reference)
Check two string.
int main(int argc, char **argv)
Definition: main.cpp:290
void testPFileParserIsMatch()
Test the PFileParser.
Definition: main.cpp:153
void testPFileParserParternRecurseExcludeEnd()
Test the PFileParser.
Definition: main.cpp:58
void testPFileParserSeq()
Test the PFileParser.
Definition: main.cpp:76
void testPFileParserBase()
Test the PFileParser.
Definition: main.cpp:181
void testPFileParserSeqOneStep()
Test the PFileParser.
Definition: main.cpp:128
void testPFileParserMapIsMatchToken()
Check the PFileParser.
Definition: main.cpp:239
void testPFileParserGetCurrentRow()
Check the PFileParser.
Definition: main.cpp:206
void testPFileParserMatchSeq()
Test the PFileParser.
Definition: main.cpp:114
void testPFileParserVecVecIsMatch()
Check the PFileParser.
Definition: main.cpp:257
void testPFileParserParternRecurse2()
Test the PFileParser.
Definition: main.cpp:40
void testPFileParserParternExclude()
Test the PFileParser.
Definition: main.cpp:22
void testPFileParserGetNextToken2()
Test the getNextToken method of the PFileParser.
Definition: main.cpp:299
void testPFileParserVecIsMatch()
Check the PFileParser.
Definition: main.cpp:213
void testPFileParserGetNextToken()
Test the getNextToken method of the PFileParser.
Definition: main.cpp:280
void testPFileParserParternRecurse()
Test the PFileParser.
Definition: main.cpp:31
void testPFileParserParternRecurseAllowChar()
Test the PFileParser.
Definition: main.cpp:49
bool testPFileParserGetUntilKey(const PString &inputStr, const PString &search, const PString &result)
Test the PFileParser.
Definition: main.cpp:167
void testPFileParserPartern()
Test the PFileParser.
Definition: main.cpp:13
void testPFileParserVecIsMatchToken()
Check the PFileParser.
Definition: main.cpp:226
void testPFileParserParternRecurseExcludeEnd2()
Test the PFileParser.
Definition: main.cpp:67