1 |
|
|
/*************************************** |
2 |
|
|
Auteur : Pierre Aubert |
3 |
|
|
Mail : pierre.aubert@lapp.in2p3.fr |
4 |
|
|
Licence : CeCILL-C |
5 |
|
|
****************************************/ |
6 |
|
|
|
7 |
|
|
#include "pxml_utils.h" |
8 |
|
|
#include "PParseSeq_utils.h" |
9 |
|
|
|
10 |
|
|
using namespace std; |
11 |
|
|
|
12 |
|
|
///Load a ParseSeq with a XML balise |
13 |
|
|
/** @param[out] seq : ParseSeq to be initialised |
14 |
|
|
* @param xmlSeq : sequence in XML |
15 |
|
|
* @return true on success, false otherwise |
16 |
|
|
* Parse a xml such as : |
17 |
|
|
* \<sequence\> |
18 |
|
|
* \<step\> |
19 |
|
|
* \<str\>0123456789\</str\> |
20 |
|
|
* \</step\> |
21 |
|
|
* \<step optional="true"\> |
22 |
|
|
* \<match\>lu\</match\> |
23 |
|
|
* \<m\>u</m\> |
24 |
|
|
* \</step\> |
25 |
|
|
* \</sequence\> |
26 |
|
|
* It get a number followed by lu or u or nothing |
27 |
|
|
*/ |
28 |
|
7 |
bool loadParserSeq(PParseSeq & seq, const PXml & xmlSeq){ |
29 |
✓✓✗✓
|
7 |
if(xmlSeq.getName() != "sequence"){ |
30 |
|
|
cerr << "loadParserSeq : expect <sequence> balise, not <"<<xmlSeq.getName()<<"> balise" << endl; |
31 |
|
|
return false; |
32 |
|
|
} |
33 |
|
7 |
PVecXml listXmlStep; |
34 |
✓✓✓✗
|
7 |
if(pxml_getVecChildIfExist(listXmlStep, xmlSeq, "step")){ |
35 |
✓✓ |
24 |
for(PVecXml::iterator itStep(listXmlStep.begin()); itStep != listXmlStep.end(); ++itStep){ |
36 |
✓ |
34 |
PParseStep step; |
37 |
✓ |
34 |
PXmlAttr attrStep; |
38 |
✓✓✓✓
|
17 |
if(pxml_getAttrIfExist(attrStep, *itStep, "optional")){ |
39 |
✓✓ |
10 |
std::string val(attrStep.getValue()); |
40 |
✗✓✗✗ ✗✗✓ |
5 |
step.setIsOptional(val == "true" || val == "True" || val == "TRUE"); |
41 |
|
|
} |
42 |
✓ |
17 |
PVecXml & listCmd(itStep->getVecChild()); |
43 |
✓✓ |
68 |
for(PVecXml::iterator itCmd(listCmd.begin()); itCmd != listCmd.end(); ++itCmd){ |
44 |
✓ |
102 |
PParseCmd cmd; |
45 |
✓✓ |
51 |
cmd.setStr(pxml_getFullContent(*itCmd)); |
46 |
✓✓ |
102 |
std::string cmdName(itCmd->getName()); |
47 |
✓✗✓✓
|
51 |
bool isString(cmdName == "str" || cmdName == "s"); |
48 |
✓✗✓✓
|
51 |
bool isMatch(cmdName == "match" || cmdName == "m"); |
49 |
✓ |
51 |
cmd.setIsMatch(isMatch); |
50 |
✓✓✓✓
|
51 |
if(isString || isMatch){ |
51 |
✓✓ |
17 |
step.getVecCmd().push_back(cmd); |
52 |
|
|
} |
53 |
|
|
} |
54 |
✓✓ |
17 |
seq.getVecStep().push_back(step); |
55 |
|
|
} |
56 |
|
|
} |
57 |
|
7 |
return true; |
58 |
|
|
} |
59 |
|
|
|
60 |
|
|
|
61 |
|
|
///Create a full sequence of string to match totaly |
62 |
|
|
/** @param vecStr : vector of string |
63 |
|
|
* @return corresponding sequence |
64 |
|
|
*/ |
65 |
|
1 |
PParseSeq createSequenceAllMatch(const std::vector<std::string> & vecStr){ |
66 |
|
1 |
PParseSeq seq; |
67 |
✓✓ |
5 |
for(std::vector<std::string>::const_iterator it(vecStr.begin()); it != vecStr.end(); ++it){ |
68 |
✓ |
8 |
PParseStep stepBegin; |
69 |
✓ |
4 |
stepBegin.setIsOptional(false); |
70 |
✓ |
8 |
PParseCmd cmdBegin; |
71 |
✓ |
4 |
cmdBegin.setIsMatch(true); |
72 |
✓ |
4 |
cmdBegin.setStr(*it); |
73 |
✓✓ |
4 |
stepBegin.getVecCmd().push_back(cmdBegin); |
74 |
✓✓ |
4 |
seq.getVecStep().push_back(stepBegin); |
75 |
|
|
} |
76 |
|
1 |
return seq; |
77 |
|
|
} |
78 |
|
|
|
79 |
|
|
|