Directory: | ./ |
---|---|
File: | tmp_project/PhoenixTex2Html/src/PLatexObj/select_css_theme.cpp |
Date: | 2025-03-24 18:12:43 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 27 | 30 | 90.0% |
Branches: | 36 | 46 | 78.3% |
Line | Branch | Exec | Source |
---|---|---|---|
1 | /*************************************** | ||
2 | Auteur : Pierre Aubert | ||
3 | Mail : pierre.aubert@lapp.in2p3.fr | ||
4 | Licence : CeCILL-C | ||
5 | ****************************************/ | ||
6 | |||
7 | #include "PFileParser.h" | ||
8 | #include "select_css_theme.h" | ||
9 | |||
10 | ///Parse the theme switch | ||
11 | /** @param[out] outputCss : output css selected theme | ||
12 | * @param[out] parser : PFileParser to be used | ||
13 | * @param vecTheme : vector of all possible theme | ||
14 | * @param themeName : theme to be used | ||
15 | */ | ||
16 | 1300260 | bool parseThemeSwitch(PString & outputCss, PFileParser & parser, const PVecString & vecTheme, const PString & themeName){ | |
17 |
1/1✓ Branch 1 taken 1300260 times.
|
1300260 | PString themeMatch(parser.isMatch(vecTheme)); |
18 |
2/2✓ Branch 1 taken 1280500 times.
✓ Branch 2 taken 19760 times.
|
1300260 | if(themeMatch == ""){return false;} //Not an existing theme |
19 |
2/2✓ Branch 1 taken 19760 times.
✓ Branch 4 taken 19760 times.
|
19760 | PString strSpace(parser.getStrComposedOf(" \n\t")); |
20 |
2/2✓ Branch 1 taken 14820 times.
✓ Branch 2 taken 4940 times.
|
19760 | if(themeMatch != themeName){ |
21 |
3/4✓ Branch 1 taken 14820 times.
✓ Branch 4 taken 14820 times.
✓ Branch 7 taken 14820 times.
✗ Branch 8 not taken.
|
14820 | if(parser.isMatch("{")){ //It is a theme, but the the one we want |
22 |
2/2✓ Branch 1 taken 14820 times.
✓ Branch 4 taken 14820 times.
|
14820 | parser.getUntilKeyWithoutPatern("}"); //So we skip it |
23 | 14820 | return false; | |
24 | }else{ //It is not a theme, so we have to keep this css | ||
25 | ✗ | outputCss = themeMatch + strSpace; | |
26 | ✗ | return true; | |
27 | } | ||
28 | } | ||
29 |
3/4✓ Branch 1 taken 4940 times.
✓ Branch 4 taken 4940 times.
✓ Branch 7 taken 4940 times.
✗ Branch 8 not taken.
|
4940 | if(parser.isMatch("{")){ //It is the theme we want |
30 |
3/3✓ Branch 1 taken 4940 times.
✓ Branch 4 taken 4940 times.
✓ Branch 7 taken 4940 times.
|
4940 | outputCss = parser.getUntilKeyWithoutPatern("}"); //So we keep it |
31 | }else{ //It is not a theme, so we have to keep this css | ||
32 | ✗ | outputCss = themeMatch + strSpace; | |
33 | } | ||
34 | 4940 | return true; | |
35 | 1300260 | } | |
36 | |||
37 | ///Select the right css option by respect to the given theme | ||
38 | /** @param vecTheme : vector of all possible theme | ||
39 | * @param themeName : theme to be used | ||
40 | * @param css : raw css with all possible themes | ||
41 | * @return css with selected theme | ||
42 | */ | ||
43 | 22360 | PString select_css_theme(const PVecString & vecTheme, const PString & themeName, const PString & css){ | |
44 |
1/1✓ Branch 1 taken 22360 times.
|
22360 | PFileParser parser; |
45 |
2/2✓ Branch 1 taken 22360 times.
✓ Branch 4 taken 22360 times.
|
22360 | parser.setWhiteSpace(""); |
46 |
2/2✓ Branch 1 taken 22360 times.
✓ Branch 4 taken 22360 times.
|
22360 | parser.setSeparator(""); |
47 |
1/1✓ Branch 1 taken 22360 times.
|
22360 | parser.setFileContent(css); |
48 |
1/1✓ Branch 1 taken 22360 times.
|
22360 | PString outputCss(""); |
49 | |||
50 |
3/3✓ Branch 1 taken 1322620 times.
✓ Branch 3 taken 1300260 times.
✓ Branch 4 taken 22360 times.
|
1322620 | while(!parser.isEndOfFile()){ |
51 |
1/1✓ Branch 1 taken 1300260 times.
|
1300260 | PString tmpCss(""); |
52 |
3/3✓ Branch 1 taken 1300260 times.
✓ Branch 3 taken 4940 times.
✓ Branch 4 taken 1295320 times.
|
1300260 | if(parseThemeSwitch(tmpCss, parser, vecTheme, themeName)){ |
53 |
1/1✓ Branch 1 taken 4940 times.
|
4940 | outputCss += tmpCss; |
54 | }else{ | ||
55 |
2/2✓ Branch 1 taken 1295320 times.
✓ Branch 4 taken 1295320 times.
|
1295320 | outputCss += parser.getCurrentCh(); |
56 |
1/1✓ Branch 1 taken 1295320 times.
|
1295320 | parser.getNextChar(); |
57 | } | ||
58 | 1300260 | } | |
59 | 44720 | return outputCss; | |
60 | 22360 | } | |
61 | |||
62 | |||
63 |