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