PhoenixLecture  2.0.0
Set of tools to make lectures
parser_utils.h File Reference
#include "platexobj_utils.h"
+ Include dependency graph for parser_utils.h:
+ This graph shows which files directly or indirectly include this file:

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...
 
PString parser_makeHighlighting (const PString &strContent, const PParserEnv &parser)
 Do the highlighting of the input text. 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:

◆ 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: