PhoenixLecture  2.0.0
Set of tools to make lectures
select_css_theme.cpp
Go to the documentation of this file.
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 
11 
16 bool parseThemeSwitch(PString & outputCss, PFileParser & parser, const PVecString & vecTheme, const PString & themeName){
17  PString themeMatch(parser.isMatch(vecTheme));
18  if(themeMatch == ""){return false;} //Not an existing theme
19  PString strSpace(parser.getStrComposedOf(" \n\t"));
20  if(themeMatch != themeName){
21  if(parser.isMatch("{")){ //It is a theme, but the the one we want
22  parser.getUntilKeyWithoutPatern("}"); //So we skip it
23  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  if(parser.isMatch("{")){ //It is the theme we want
30  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  return true;
35 }
36 
38 
43 PString select_css_theme(const PVecString & vecTheme, const PString & themeName, const PString & css){
44  PFileParser parser;
45  parser.setWhiteSpace("");
46  parser.setSeparator("");
47  parser.setFileContent(css);
48  PString outputCss("");
49 
50  while(!parser.isEndOfFile()){
51  PString tmpCss("");
52  if(parseThemeSwitch(tmpCss, parser, vecTheme, themeName)){
53  outputCss += tmpCss;
54  }else{
55  outputCss += parser.getCurrentCh();
56  parser.getNextChar();
57  }
58  }
59  return outputCss;
60 }
61 
62 
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
PString getUntilKeyWithoutPatern(const PString &patern)
Renvoie la chaine de caractère du caractère courant jusqu'à patern exclu.
PString getStrComposedOf(const PString &charset)
Get string composed of the characters in the string charset.
void setWhiteSpace(const PString &whiteSpace)
Initialise la liste des caractères blancs.
Definition: PFileParser.cpp:35
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 setFileContent(const PString &fileContent)
Set the file content.
Definition: PFileParser.cpp:50
bool isEndOfFile() const
Dit si on est à la fin du fichier.
Definition: PFileParser.cpp:88
char getNextChar()
Fonction qui renvoie le prochain caractère du fichier courant.
Extends the std::string.
Definition: PString.h:16
PString select_css_theme(const PVecString &vecTheme, const PString &themeName, const PString &css)
Select the right css option by respect to the given theme.
bool parseThemeSwitch(PString &outputCss, PFileParser &parser, const PVecString &vecTheme, const PString &themeName)
Parse the theme switch.