Directory: | ./ |
---|---|
File: | tmp_project/PhoenixTex2Html/src/PLatexObj/platexobj_utils.cpp |
Date: | 2025-03-24 18:12:43 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 51 | 52 | 98.1% |
Branches: | 73 | 80 | 91.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 "platexobj_html.h" | ||
8 | |||
9 | #include "platexobj_utils.h" | ||
10 | |||
11 | ///Say if the PLatexObj is a part, charpter, section, subsection or subsubsection | ||
12 | /** @param obj : PLatexObj to be checked | ||
13 | * @return true if the obj is a part, charpter, section, subsection or subsubsection, false otherwise | ||
14 | */ | ||
15 | 109254 | bool isSection(const PLatexObj & obj){ | |
16 | 109254 | PLatexType::PLatexType type(obj.getType()); | |
17 |
10/10✓ Branch 0 taken 108448 times.
✓ Branch 1 taken 806 times.
✓ Branch 2 taken 107460 times.
✓ Branch 3 taken 988 times.
✓ Branch 4 taken 106396 times.
✓ Branch 5 taken 1064 times.
✓ Branch 6 taken 104649 times.
✓ Branch 7 taken 1747 times.
✓ Branch 8 taken 38 times.
✓ Branch 9 taken 104611 times.
|
109254 | return (type == PLatexType::PART || type == PLatexType::CHAPTER || type == PLatexType::SECTION || type == PLatexType::SUBSECTION || type == PLatexType::SUBSUBSECTION); |
18 | } | ||
19 | |||
20 | ///Say if the PLatexObj is a book separator | ||
21 | /** @param obj : PLatexObj to be checked | ||
22 | * @return true if the obj is a book separator, false otherwise | ||
23 | */ | ||
24 | 15432 | bool isSeparator(const PLatexObj & obj){ | |
25 | 15432 | PLatexType::PLatexType type(obj.getType()); | |
26 | 15432 | return type == PLatexType::BOOKPARTSEPARATOR; | |
27 | } | ||
28 | |||
29 | ///Say if the PLatexObj is a part, charpter, section, subsection, subsubsection or a book separator | ||
30 | /** @param obj : PLatexObj to be checked | ||
31 | * @return true if the obj is a part, charpter, section, subsection, subsubsection or a book separator, false otherwise | ||
32 | */ | ||
33 | 3168 | bool isSectionOrSeparator(const PLatexObj & obj){ | |
34 |
4/4✓ Branch 1 taken 2930 times.
✓ Branch 2 taken 238 times.
✓ Branch 4 taken 2 times.
✓ Branch 5 taken 2928 times.
|
3168 | return isSection(obj) || isSeparator(obj); |
35 | } | ||
36 | |||
37 | ///Say if the PLatexObj is a newline or not | ||
38 | /** @param obj : PLatexObj to be checked | ||
39 | * @return true if the obj is a newline, false otherwise | ||
40 | */ | ||
41 | 39434 | bool isNewLine(const PLatexObj & obj){ | |
42 | 39434 | PLatexType::PLatexType type(obj.getType()); | |
43 |
4/4✓ Branch 0 taken 39380 times.
✓ Branch 1 taken 54 times.
✓ Branch 2 taken 3071 times.
✓ Branch 3 taken 36309 times.
|
39434 | return type == PLatexType::SPACEPARAGRAPH || type == PLatexType::AUTOSPACEPARAGRAPH; |
44 | } | ||
45 | |||
46 | ///Return the section level | ||
47 | /** @param obj : PLatexObj to be checked | ||
48 | * @return level of the PLatexObj | ||
49 | */ | ||
50 | 1548 | long unsigned int getSectionLevel(const PLatexObj & obj){ | |
51 | 1548 | PLatexType::PLatexType type(obj.getType()); | |
52 |
2/2✓ Branch 0 taken 244 times.
✓ Branch 1 taken 1304 times.
|
1548 | if(type == PLatexType::PART){return 0lu;} |
53 |
2/2✓ Branch 0 taken 338 times.
✓ Branch 1 taken 966 times.
|
1304 | else if(type == PLatexType::CHAPTER){return 1lu;} |
54 |
2/2✓ Branch 0 taken 423 times.
✓ Branch 1 taken 543 times.
|
966 | else if(type == PLatexType::SECTION){return 2lu;} |
55 |
2/2✓ Branch 0 taken 525 times.
✓ Branch 1 taken 18 times.
|
543 | else if(type == PLatexType::SUBSECTION){return 3lu;} |
56 |
2/2✓ Branch 0 taken 12 times.
✓ Branch 1 taken 6 times.
|
18 | else if(type == PLatexType::SUBSUBSECTION){return 4lu;} |
57 |
1/2✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
|
6 | else if(type == PLatexType::BOOKPARTSEPARATOR){return 0lu;} |
58 | ✗ | return -1lu; | |
59 | } | ||
60 | |||
61 | ///Convert all the echaped char | ||
62 | /** @param str : string | ||
63 | * @return string | ||
64 | */ | ||
65 | 2229104 | PString convertBackSlahedStr(const PString & str){ | |
66 |
2/2✓ Branch 2 taken 2229104 times.
✓ Branch 5 taken 2229104 times.
|
4458208 | PString out(str.replace("\\n", "\n")); |
67 |
4/4✓ Branch 1 taken 2229104 times.
✓ Branch 4 taken 2229104 times.
✓ Branch 7 taken 2229104 times.
✓ Branch 10 taken 2229104 times.
|
2229104 | out = out.replace("\\t", "\t"); |
68 |
4/4✓ Branch 1 taken 2229104 times.
✓ Branch 4 taken 2229104 times.
✓ Branch 7 taken 2229104 times.
✓ Branch 10 taken 2229104 times.
|
2229104 | out = out.replace("\\r", "\r"); |
69 |
4/4✓ Branch 1 taken 2229104 times.
✓ Branch 4 taken 2229104 times.
✓ Branch 7 taken 2229104 times.
✓ Branch 10 taken 2229104 times.
|
2229104 | out = out.replace("<", "<"); |
70 |
4/4✓ Branch 1 taken 2229104 times.
✓ Branch 4 taken 2229104 times.
✓ Branch 7 taken 2229104 times.
✓ Branch 10 taken 2229104 times.
|
2229104 | out = out.replace(">", ">"); |
71 |
4/4✓ Branch 1 taken 2229104 times.
✓ Branch 4 taken 2229104 times.
✓ Branch 7 taken 2229104 times.
✓ Branch 10 taken 2229104 times.
|
2229104 | out = out.replace("\", "\\"); |
72 |
4/4✓ Branch 1 taken 2229104 times.
✓ Branch 4 taken 2229104 times.
✓ Branch 7 taken 2229104 times.
✓ Branch 10 taken 2229104 times.
|
2229104 | out = out.replace("~", "~"); |
73 |
4/4✓ Branch 1 taken 2229104 times.
✓ Branch 4 taken 2229104 times.
✓ Branch 7 taken 2229104 times.
✓ Branch 10 taken 2229104 times.
|
2229104 | out = out.replace("&", "&"); |
74 | 2229104 | return out; | |
75 | } | ||
76 | |||
77 | ///Get the section number from its file name | ||
78 | /** @param fileName : input filename | ||
79 | * @return corresponding section number | ||
80 | */ | ||
81 | 193 | PString getSecNumberFromFileName(const PPath & fileName){ | |
82 |
1/4✗ Branch 1 not taken.
✓ Branch 2 taken 193 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
|
193 | if(fileName.size() <= 1lu){return fileName;} |
83 | 193 | long unsigned int begin(fileName.size() - 1lu); | |
84 | |||
85 |
3/6✓ Branch 0 taken 1716 times.
✗ Branch 1 not taken.
✓ Branch 3 taken 1716 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1716 times.
✗ Branch 6 not taken.
|
1716 | while(begin > 0lu && begin < fileName.size()){ |
86 | 1716 | char ch = fileName[begin]; | |
87 |
2/2✓ Branch 0 taken 193 times.
✓ Branch 1 taken 1523 times.
|
1716 | if(ch == '-'){ |
88 | 193 | break; | |
89 | } | ||
90 | 1523 | --begin; | |
91 | } | ||
92 | |||
93 |
2/2✓ Branch 1 taken 193 times.
✓ Branch 4 taken 193 times.
|
193 | PString out(fileName.substr(0lu, begin)); |
94 |
1/1✓ Branch 1 taken 193 times.
|
193 | return out; |
95 | 193 | } | |
96 | |||
97 | ///Get the title of a part/chapter/section etc | ||
98 | /** @param outputMode : mode used to create and remember formalae | ||
99 | * @param obj : section to be used | ||
100 | * @return title of the corresponding section | ||
101 | */ | ||
102 | 3107 | PString getSectionTitle(POutoutMode & outputMode, const PLatexObj & obj){ | |
103 | 3107 | return platexobj_htmlStr(outputMode, obj.getComplexTitle()); | |
104 | } | ||
105 | |||
106 | ///Append a vector of PLatexObj in the given vector of content | ||
107 | /** @param[out] vecContent : vector of content to be updated | ||
108 | * @param vecObj : vector of PLatexObj to be appended | ||
109 | */ | ||
110 | 1218 | void appendVecContent(std::vector<PLatexObj> & vecContent, const std::vector<PLatexObj> & vecObj){ | |
111 |
2/2✓ Branch 4 taken 1356 times.
✓ Branch 5 taken 1218 times.
|
2574 | for(std::vector<PLatexObj>::const_iterator it(vecObj.begin()); it != vecObj.end(); ++it){ |
112 |
1/1✓ Branch 2 taken 1356 times.
|
1356 | vecContent.push_back(*it); |
113 | } | ||
114 | 1218 | } | |
115 | |||
116 | ///Append a PLatexObj in the given vector of content | ||
117 | /** @param[out] vecContent : vector of content to be updated | ||
118 | * @param obj : PLatexObj to be appended | ||
119 | */ | ||
120 | 1615 | void appendVecContent(std::vector<PLatexObj> & vecContent, const PLatexObj & obj){ | |
121 |
2/2✓ Branch 1 taken 1068 times.
✓ Branch 2 taken 547 times.
|
1615 | if(obj.getType() == PLatexType::NONE){ |
122 | 1068 | appendVecContent(vecContent, obj.getVecContent()); | |
123 | }else{ | ||
124 | 547 | vecContent.push_back(obj); | |
125 | } | ||
126 | 1615 | } | |
127 | |||
128 |