PhoenixLecture  2.0.0
Set of tools to make lectures
platexobj_utils.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 "platexobj_html.h"
8 
9 #include "platexobj_utils.h"
10 
12 
15 bool isSection(const PLatexObj & obj){
16  PLatexType::PLatexType type(obj.getType());
17  return (type == PLatexType::PART || type == PLatexType::CHAPTER || type == PLatexType::SECTION || type == PLatexType::SUBSECTION || type == PLatexType::SUBSUBSECTION);
18 }
19 
21 
24 bool isSeparator(const PLatexObj & obj){
25  PLatexType::PLatexType type(obj.getType());
26  return type == PLatexType::BOOKPARTSEPARATOR;
27 }
28 
30 
33 bool isSectionOrSeparator(const PLatexObj & obj){
34  return isSection(obj) || isSeparator(obj);
35 }
36 
38 
41 bool isNewLine(const PLatexObj & obj){
42  PLatexType::PLatexType type(obj.getType());
44 }
45 
47 
50 long unsigned int getSectionLevel(const PLatexObj & obj){
51  PLatexType::PLatexType type(obj.getType());
52  if(type == PLatexType::PART){return 0lu;}
53  else if(type == PLatexType::CHAPTER){return 1lu;}
54  else if(type == PLatexType::SECTION){return 2lu;}
55  else if(type == PLatexType::SUBSECTION){return 3lu;}
56  else if(type == PLatexType::SUBSUBSECTION){return 4lu;}
57  else if(type == PLatexType::BOOKPARTSEPARATOR){return 0lu;}
58  return -1lu;
59 }
60 
62 
66  PString out(str.replace("\\n", "\n"));
67  out = out.replace("\\t", "\t");
68  out = out.replace("\\r", "\r");
69  out = out.replace("&lt;", "<");
70  out = out.replace("&gt;", ">");
71  out = out.replace("&bsol;", "\\");
72  out = out.replace("&#126;", "~");
73  out = out.replace("&amp;", "&");
74  return out;
75 }
76 
78 
82  if(fileName.size() <= 1lu){return fileName;}
83  long unsigned int begin(fileName.size() - 1lu);
84 
85  while(begin > 0lu && begin < fileName.size()){
86  char ch = fileName[begin];
87  if(ch == '-'){
88  break;
89  }
90  --begin;
91  }
92 
93  PString out(fileName.substr(0lu, begin));
94  return out;
95 }
96 
98 
102 PString getSectionTitle(POutoutMode & outputMode, const PLatexObj & obj){
103  return platexobj_htmlStr(outputMode, obj.getComplexTitle());
104 }
105 
107 
110 void appendVecContent(std::vector<PLatexObj> & vecContent, const std::vector<PLatexObj> & vecObj){
111  for(std::vector<PLatexObj>::const_iterator it(vecObj.begin()); it != vecObj.end(); ++it){
112  vecContent.push_back(*it);
113  }
114 }
115 
117 
120 void appendVecContent(std::vector<PLatexObj> & vecContent, const PLatexObj & obj){
121  if(obj.getType() == PLatexType::NONE){
122  appendVecContent(vecContent, obj.getVecContent());
123  }else{
124  vecContent.push_back(obj);
125  }
126 }
127 
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 std::vector< PLatexObj > & getComplexTitle() const
Gets the complexTitle of the PLatexObj.
Definition: PLatexObj.cpp:396
const PLatexType::PLatexType & getType() const
Gets the type of the PLatexObj.
Definition: PLatexObj.cpp:298
Path of a directory or a file.
Definition: PPath.h:17
Extends the std::string.
Definition: PString.h:16
PString replace(const PString &pattern, const PString &replaceStr) const
Replace a PString into an other PString.
Definition: PString.cpp:204
PLatexType
Type of the PLatexObj.
Definition: PLatexType.h:12
@ SUBSUBSECTION
Definition: PLatexType.h:54
@ AUTOSPACEPARAGRAPH
Definition: PLatexType.h:28
@ SPACEPARAGRAPH
Definition: PLatexType.h:27
@ BOOKPARTSEPARATOR
Definition: PLatexType.h:64
PString platexobj_htmlStr(POutoutMode &outputMode, const PLatexObj &obj, bool isBibliography=false, bool allowText=true)
bool isSectionOrSeparator(const PLatexObj &obj)
Say if the PLatexObj is a part, charpter, section, subsection, subsubsection or a book separator.
void appendVecContent(std::vector< PLatexObj > &vecContent, const std::vector< PLatexObj > &vecObj)
Append a vector of PLatexObj in the given vector of content.
bool isNewLine(const PLatexObj &obj)
Say if the PLatexObj is a newline or not.
PString getSecNumberFromFileName(const PPath &fileName)
Get the section number from its file name.
bool isSection(const PLatexObj &obj)
Say if the PLatexObj is a part, charpter, section, subsection or subsubsection.
bool isSeparator(const PLatexObj &obj)
Say if the PLatexObj is a book separator.
PString getSectionTitle(POutoutMode &outputMode, const PLatexObj &obj)
Get the title of a part/chapter/section etc.
long unsigned int getSectionLevel(const PLatexObj &obj)
Return the section level.
PString convertBackSlahedStr(const PString &str)
Convert all the echaped char.
Output mode of the html backend.