PhoenixLecture  2.0.0
Set of tools to make lectures
parser_utils.cpp File Reference
#include "PFileParser.h"
#include "parser_utils.h"
+ Include dependency graph for parser_utils.cpp:

Go to the source code of this file.

Functions

PString convertCharToHtml (char ch)
 fonction qui converti une chaîne de caractères en html (elle remplace les caractères spéciaux) More...
 
PString convertStrToHtml (const PString &str)
 fonction qui converti une chaîne de caractères en html (elle remplace les caractères spéciaux) More...
 
PLatexObjgetLastPLatexObj (PLatexObj &obj)
 Get the last PLatexObj of the given one. More...
 
PParserEnv getParserEnv (const PVecParserEnv &vecParser, const PString &nameParser)
 Get the parser env. More...
 
void incrementCurrentChar (PFileParser &fileParser, PString &textObj)
 Increment current char position. More...
 
PString parser_makeHighlighting (const PString &strContent, const PParserEnv &parser)
 Do the highlighting of the input text. More...
 
bool parser_parseKeyword (PString &out, PString &textObj, PFileParser &fileParser, const PContext &context)
 Parse the keyword of the given parser. More...
 
bool parser_parseKeyword (PString &out, PString &textObj, PFileParser &fileParser, const PParserEnv &parser)
 Parse the keyword of the given parser. More...
 
void playTextLatexObj (PString &parent, PString &textObj)
 Play the text latex obj. More...
 

Function Documentation

◆ convertCharToHtml()

PString convertCharToHtml ( char  ch)

fonction qui converti une chaîne de caractères en html (elle remplace les caractères spéciaux)

Parameters
ch: char que l'on veut convertir en Html
Returns
string convertie en html

Definition at line 36 of file parser_utils.cpp.

36  {
37  switch(ch){
38  case '\\':
39  return "\";
40  case '&':
41  return "&";
42  case '<':
43  return "&lt;";
44  case '>':
45  return "&gt;";
46  case '~':
47  return "&#126;";
48  default:
49  break;
50  }
51  PString tmp("");
52  tmp += ch;
53  return tmp;
54 }
Extends the std::string.
Definition: PString.h:16

Referenced by incrementCurrentChar().

+ Here is the caller graph for this function:

◆ convertStrToHtml()

PString convertStrToHtml ( const PString str)

fonction qui converti une chaîne de caractères en html (elle remplace les caractères spéciaux)

Parameters
str: string que l'on veut convertir en Html
Returns
string convertie en html

Definition at line 14 of file parser_utils.cpp.

14  {
15  PString buffer(str.replace("&", "&amp;"));
16  buffer = buffer.replace("<", "&lt;");
17  buffer = buffer.replace(">", "&gt;");
18  buffer = buffer.replace("\\\"\\\\\\\"", "&bsol;&quot;&bsol;&bsol;&bsol;&quot;");
19  buffer = buffer.replace("\\\\\\\"\\\"", "&bsol;&bsol;&bsol;&quot;&bsol;&quot;");
20  buffer = buffer.replace("\"", "&quot;");
21  buffer = buffer.replace("\\dots{}", "...");
22  buffer = buffer.replace("\\'e", "é");
23  buffer = buffer.replace("\\'", "");
24  buffer = buffer.replace("~", "&#126;");
25  buffer = buffer.replace("\\and", "&amp;");
26 // buffer = buffer.replace("\\\\", "<br />");
27  buffer = buffer.replace("\\,", "");
28  buffer = buffer.replace("\\", "&bsol;");
29  return buffer;
30 }
PString replace(const PString &pattern, const PString &replaceStr) const
Replace a PString into an other PString.
Definition: PString.cpp:204

References PString::replace().

Referenced by parser_parseKeyword(), pbiblio_attributeHtml(), and platexobj_htmlStrText().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getLastPLatexObj()

PLatexObj* getLastPLatexObj ( PLatexObj obj)

Get the last PLatexObj of the given one.

Parameters
obj: main object to use
Returns
pointer to the last latex object

Definition at line 212 of file parser_utils.cpp.

212  {
213  PLatexType::PLatexType type = obj.getType();
214  PVecLatexObj & vecObj = obj.getVecContent();
215  if(vecObj.size() != 0lu){
216  if(type == PLatexType::CAPTION){return &obj;}
217  PLatexObj* outPtr = NULL;
218  PVecLatexObj::reverse_iterator it(vecObj.rbegin());
219  while(outPtr == NULL && it != vecObj.rend()){
220  outPtr = getLastPLatexObj(*it);
221  ++it;
222  }
223  return outPtr;
224  }else{ //No other content
225  if(type == PLatexType::TEXT){return NULL;} //Pure text cannot recieved label
226  else{return &obj;}
227  }
228 }
Describe a latex object.
Definition: PLatexObj.h:40
const std::vector< PLatexObj > & getVecContent() const
Gets the vecContent of the PLatexObj.
Definition: PLatexObj.cpp:410
const PLatexType::PLatexType & getType() const
Gets the type of the PLatexObj.
Definition: PLatexObj.cpp:298
PLatexType
Type of the PLatexObj.
Definition: PLatexType.h:12
PLatexObj * getLastPLatexObj(PLatexObj &obj)
Get the last PLatexObj of the given one.
std::vector< PLatexObj > PVecLatexObj
Vector of obj.

References PLatexType::CAPTION, PLatexObj::getType(), PLatexObj::getVecContent(), and PLatexType::TEXT.

Referenced by PGenericParser::parseLabel().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getParserEnv()

PParserEnv getParserEnv ( const PVecParserEnv vecParser,
const PString nameParser 
)

Get the parser env.

Parameters
vecParser: list of all parser
nameParser: name of the parser to get
Returns
PParserEnv

Definition at line 61 of file parser_utils.cpp.

61  {
62  const std::vector<PParserEnv> & vecPars = vecParser.getVecEnv();
63  for(std::vector<PParserEnv>::const_iterator it(vecPars.begin()); it != vecPars.end(); ++it){
64  if(it->getName() == nameParser){
65  return *it;
66  }
67  }
68  PParserEnv out;
69  return out;
70 }
Parser environement.
Definition: PLatexObj.h:363
const std::vector< PParserEnv > & getVecEnv() const
Gets the vecEnv of the PVecParserEnv.
Definition: PLatexObj.cpp:1562

References PVecParserEnv::getVecEnv().

Referenced by PMarkdownParser::parseExtraParser(), PConfigParser::parseParserLanguage(), and PConfigParser::parseParserLanguageFunction().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ incrementCurrentChar()

void incrementCurrentChar ( PFileParser fileParser,
PString textObj 
)

Increment current char position.

Parameters
[out]fileParser: file parser
[out]textObj: string to be used to store text

Definition at line 76 of file parser_utils.cpp.

76  {
77  //If nothing is known I need to save the current char in the MACRO TEXT
78  char ch = fileParser.getCurrentCh();
79  textObj += convertCharToHtml(ch);
80  fileParser.getNextChar();
81 }
char getCurrentCh() const
Renvoie le caractère courant.
char getNextChar()
Fonction qui renvoie le prochain caractère du fichier courant.
PString convertCharToHtml(char ch)
fonction qui converti une chaîne de caractères en html (elle remplace les caractères spéciaux)

References convertCharToHtml(), PFileParser::getCurrentCh(), and PFileParser::getNextChar().

Referenced by parser_makeHighlighting().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ parser_makeHighlighting()

PString parser_makeHighlighting ( const PString strContent,
const PParserEnv parser 
)

Do the highlighting of the input text.

Parameters
strContent: string content
parser: parser to be used
Returns
string with balise

Definition at line 186 of file parser_utils.cpp.

186  {
187  PString out(""), tmpText("");
188  PFileParser fileParser;
189  fileParser.setEscapeChar('\0');
190  fileParser.setWhiteSpace("");
191  fileParser.setFileContent(strContent);
192 
193  while(!fileParser.isEndOfFile()){
194  if(parser_parseKeyword(out, tmpText, fileParser, parser)){}
195  else{
196  PString plainText(fileParser.getStrComposedOf(parser.getPlainText()));
197  if(plainText == ""){
198  incrementCurrentChar(fileParser, tmpText);
199  }else{
200  tmpText += plainText;
201  }
202  }
203  }
204  playTextLatexObj(out, tmpText);
205  return out;
206 }
classe qui permet de parser des fichiers texte en renvoyant les tokens les uns après les autres
Definition: PFileParser.h:20
void setEscapeChar(char escapeChar)
Sets the escape character of the PFileParser.
Definition: PFileParser.cpp:58
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
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
const PString & getPlainText() const
Gets the plainText of the PParserEnv.
Definition: PLatexObj.cpp:1486
void playTextLatexObj(PString &parent, PString &textObj)
Play the text latex obj.
bool parser_parseKeyword(PString &out, PString &textObj, PFileParser &fileParser, const PContext &context)
Parse the keyword of the given parser.
void incrementCurrentChar(PFileParser &fileParser, PString &textObj)
Increment current char position.

References PParserEnv::getPlainText(), PFileParser::getStrComposedOf(), incrementCurrentChar(), PFileParser::isEndOfFile(), parser_parseKeyword(), playTextLatexObj(), PFileParser::setEscapeChar(), PFileParser::setFileContent(), and PFileParser::setWhiteSpace().

Referenced by PMarkdownParser::parseExtraParser(), PConfigParser::parseParserLanguage(), and PConfigParser::parseParserLanguageFunction().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ parser_parseKeyword() [1/2]

bool parser_parseKeyword ( PString out,
PString textObj,
PFileParser fileParser,
const PContext context 
)

Parse the keyword of the given parser.

Parameters
[out]out: output string
[out]textObj: string of text
[out]fileParser: file parser
context: highlighting parser
Returns
true if keyword has been found

Definition at line 102 of file parser_utils.cpp.

102  {
103  PString strBegin(context.getBegin()), strEnd(context.getEnd());
104  PString strNotAfterBegin(context.getNotAfterBegin());
105  PString strNotBeforeBegin(context.getNotBeforeBegin());
106  PString strNotBeforeEnd(context.getNotBeforeEnd());
107 
108  bool parseUntilEnd(false), isFind(false);
109  if(strBegin != ""){
110  fileParser.pushPosition();
111  if(strNotBeforeBegin == "" || (strNotBeforeBegin != "" && !fileParser.isMatch(strNotBeforeBegin))){
112  if(fileParser.isMatch(strBegin)){
113  if(strNotAfterBegin != ""){
114  parseUntilEnd = !fileParser.isMatch(strNotAfterBegin);
115  }else{
116  parseUntilEnd = true;
117  }
118  }
119  }
120  if(parseUntilEnd){
121  if(strEnd != ""){
122  playTextLatexObj(out, textObj);
123  PString content("");
124  if(strNotBeforeEnd != ""){
125 // content = fileParser.getUntilKeyWithoutPaternRecurseExclude(strEnd, strBegin, strNotBeforeEnd);
126  content = fileParser.getUntilKeyWithoutPaternExclude(strEnd, strNotBeforeEnd);
127  }else{
128 // content = fileParser.getUntilKeyWithoutPaternRecurse(strEnd, strBegin);
129  content = fileParser.getUntilKeyWithoutPatern(strEnd);
130  }
131  out += "<span class=\""+context.getName()+"\">" + convertStrToHtml(strBegin + content + strEnd) + "</span>";
132  isFind = true;
133  }else{
134  fileParser.popPosition();
135  }
136  }else{
137  fileParser.popPosition();
138  }
139  }
140  const PVecString & vecKeyword = context.getVecKeyword();
141  if(vecKeyword.size() != 0lu){
142  PString matchString(fileParser.isMatchToken(vecKeyword));
143  if(matchString != ""){
144  playTextLatexObj(out, textObj);
145  out += "<span class=\""+context.getName()+"\">" + convertStrToHtml(matchString) + "</span>";
146  isFind = true;
147  }
148  }
149  const PVecParseStep & vecStep = context.getSeq().getVecStep();
150  if(vecStep.size() != 0lu){
151  PString res(fileParser.isMatch(context.getSeq()));
152  if(res != ""){
153  playTextLatexObj(out, textObj);
154  out += "<span class=\""+context.getName()+"\">" + convertStrToHtml(res) + "</span>";
155  isFind = true;
156  }
157  }
158 
159  return isFind;
160 }
std::vector< PParseStep > PVecParseStep
Definition: PParseSeqDef.h:12
std::vector< PString > PVecString
Definition: PString.h:96
const PString & getNotBeforeBegin() const
Gets the notBeforeBegin of the PContext.
Definition: PLatexObj.cpp:1331
const PString & getBegin() const
Gets the begin of the PContext.
Definition: PLatexObj.cpp:1303
const PParseSeq & getSeq() const
Gets the seq of the PContext.
Definition: PLatexObj.cpp:1387
const PString & getEnd() const
Gets the end of the PContext.
Definition: PLatexObj.cpp:1317
const PString & getNotBeforeEnd() const
Gets the notBeforeEnd of the PContext.
Definition: PLatexObj.cpp:1359
const std::vector< PString > & getVecKeyword() const
Gets the vecKeyword of the PContext.
Definition: PLatexObj.cpp:1373
const PString & getName() const
Gets the name of the PContext.
Definition: PLatexObj.cpp:1289
const PString & getNotAfterBegin() const
Gets the notAfterBegin of the PContext.
Definition: PLatexObj.cpp:1345
PString getUntilKeyWithoutPaternExclude(const PString &patern, const PString &strNotBeforeEndPatern)
Parse a string until the patern is found, only if it has not strNotBeforeEndPatern before it.
PString getUntilKeyWithoutPatern(const PString &patern)
Renvoie la chaine de caractère du caractère courant jusqu'à patern exclu.
bool isMatchToken(const PString &patern)
Says if the patern match with the current caracters of the PFileParser but treats the string as a tok...
bool isMatch(const PString &patern)
Says if the patern match with the current caracters of the PFileParser.
void popPosition()
Get to the last saved position of the PFileParser in the current file.
Definition: PFileParser.cpp:99
void pushPosition()
Remember the current position of the PFileParser in the current file.
Definition: PFileParser.cpp:93
const std ::vector< PParseStep > & getVecStep() const
Get the variable p_vecStep.
Definition: PParseSeq.cpp:256
PString convertStrToHtml(const PString &str)
fonction qui converti une chaîne de caractères en html (elle remplace les caractères spéciaux)

References convertStrToHtml(), PContext::getBegin(), PContext::getEnd(), PContext::getName(), PContext::getNotAfterBegin(), PContext::getNotBeforeBegin(), PContext::getNotBeforeEnd(), PContext::getSeq(), PFileParser::getUntilKeyWithoutPatern(), PFileParser::getUntilKeyWithoutPaternExclude(), PContext::getVecKeyword(), PParseSeq::getVecStep(), PFileParser::isMatch(), PFileParser::isMatchToken(), playTextLatexObj(), PFileParser::popPosition(), and PFileParser::pushPosition().

Referenced by parser_makeHighlighting(), and parser_parseKeyword().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ parser_parseKeyword() [2/2]

bool parser_parseKeyword ( PString out,
PString textObj,
PFileParser fileParser,
const PParserEnv parser 
)

Parse the keyword of the given parser.

Parameters
[out]out: output string
[out]textObj: string of text
[out]fileParser: file parser
parser: highlighting parser
Returns
true if keyword has been found

Definition at line 170 of file parser_utils.cpp.

170  {
171  const PVecContext & vecContext = parser.getVecContext();
172  PVecContext::const_iterator it(vecContext.begin());
173  bool isSearch(true);
174  while(it != vecContext.end() && isSearch){
175  isSearch = !parser_parseKeyword(out, textObj, fileParser, *it);
176  ++it;
177  }
178  return !isSearch;
179 }
const std::vector< PContext > & getVecContext() const
Gets the vecContext of the PParserEnv.
Definition: PLatexObj.cpp:1500
std::vector< PContext > PVecContext
Vector of context.

References PParserEnv::getVecContext(), and parser_parseKeyword().

+ Here is the call graph for this function:

◆ playTextLatexObj()

void playTextLatexObj ( PString parent,
PString textObj 
)

Play the text latex obj.

Parameters
[out]parent: parent string
[out]textObj: string to deal with text

Definition at line 87 of file parser_utils.cpp.

87  {
88  if(textObj != ""){
89  parent += textObj;
90  textObj = "";
91  }
92 }

Referenced by parser_makeHighlighting(), and parser_parseKeyword().

+ Here is the caller graph for this function: