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

Go to the source code of this file.

Functions

PString pbiblio_checkAttrName (const PString &attrName)
 Check the attribute name. More...
 
PString pbiblio_checkAttrValue (const PString &attrValue)
 Check the attribute value. More...
 
bool pbiblio_parseAttribute (PFileParser &parser, PString &attrName, PString &attrValue)
 Parse an attribute of the current bibliography entry. More...
 
PBiblioEntryType::PBiblioEntryType pbiblio_strToEntryType (const PString &str)
 Convert a string into an entry type. More...
 
void pbliblio_convertMapStrToBibEntry (PBiblioEntry &biblioEntry, PMapStrEntry &mapStrEntry)
 Convert the map of string into a PBiblioEntry. More...
 
bool pbliblio_file (PMapBiblioEntry &mapBiblioEntry, const PPath &fileName)
 Parse the full bibliography file. More...
 
bool pbliblio_parser (PFileParser &parser, PMapBiblioEntry &mapBiblioEntry)
 Parse the full bibliography file. More...
 
bool pbliblio_parserEntry (PFileParser &parser, PMapStrEntry &mapStrEntry, PBiblioEntryType::PBiblioEntryType &type)
 Parse the full bibliography file. More...
 

Function Documentation

◆ pbiblio_checkAttrName()

PString pbiblio_checkAttrName ( const PString attrName)

Check the attribute name.

Parameters
attrName: attribute name
Returns
modified attribute name if necessary

Definition at line 61 of file pbiblio_parser.cpp.

61  {
62  if(attrName == "authors"){return "author";}
63  return attrName;
64 }

Referenced by pbliblio_parserEntry().

+ Here is the caller graph for this function:

◆ pbiblio_checkAttrValue()

PString pbiblio_checkAttrValue ( const PString attrValue)

Check the attribute value.

Parameters
attrValue: attribute value
Returns
modified attribute value if necessary

Definition at line 70 of file pbiblio_parser.cpp.

70  {
71  return attrValue.eraseChar("{}\"%").replace("\\url", "");
72 }
PString replace(const PString &pattern, const PString &replaceStr) const
Replace a PString into an other PString.
Definition: PString.cpp:204
PString eraseChar(char ch) const
Erase char ch of current string.
Definition: PString.cpp:478

References PString::eraseChar(), and PString::replace().

Referenced by pbliblio_parserEntry().

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

◆ pbiblio_parseAttribute()

bool pbiblio_parseAttribute ( PFileParser parser,
PString attrName,
PString attrValue 
)

Parse an attribute of the current bibliography entry.

Parameters
[out]parser: parser to be used
[out]attrName: aatribute name
[out]attrValue: attribute value

Definition at line 29 of file pbiblio_parser.cpp.

29  {
30  parser.skipWhiteSpace();
31  attrName = parser.getNextToken(); //Name of the attribute
32  //Then we expect an =
33  PString token = parser.getNextToken();
34  if(token != "="){
35  std::cerr << "pbliblio_parser : error at " << parser.getLocation() << std::endl;
36  std::cerr << "\tunexpected token '" << token << "'" << std::endl;
37  return false;
38  }
39  //Now parse the value
40  token = parser.getNextToken();
41  PString tmpAttrValue("");
42  if(token == "{"){
43  tmpAttrValue = parser.getUntilKeyWithoutPaternRecurse("}","{");
44  }else if(token == "\""){
45  parser.setEscapeChar('\\');
46  tmpAttrValue = parser.getUntilKeyWithoutPatern("\"");
47  parser.setEscapeChar('\0');
48  }else{
49  tmpAttrValue = parser.getUntilKeyWithoutPatern(",");
50  }
51  attrValue = tmpAttrValue.eraseFirstLastChar(" \n\t");
52 
53  if(parser.isMatch(",")){} //Just skip the next , if there is one
54  return true;
55 }
PString getNextToken()
Get the next token.
PString getUntilKeyWithoutPatern(const PString &patern)
Renvoie la chaine de caractère du caractère courant jusqu'à patern exclu.
void setEscapeChar(char escapeChar)
Sets the escape character of the PFileParser.
Definition: PFileParser.cpp:58
PString getUntilKeyWithoutPaternRecurse(const PString &patern, const PString &beginPatern, const PString &allowedCharAfterBegin)
Get the string until end sequence and take account recursive patern (embeded strings)
bool isMatch(const PString &patern)
Says if the patern match with the current caracters of the PFileParser.
PLocation getLocation() const
Fonction qui renvoie la PLocation du PFileParser.
void skipWhiteSpace()
Skip the white space if there is at the current caracter position.
Extends the std::string.
Definition: PString.h:16
PString eraseFirstLastChar(const PString &vecChar) const
Erase first and last char in a string.
Definition: PString.cpp:545

References PString::eraseFirstLastChar(), PFileParser::getLocation(), PFileParser::getNextToken(), PFileParser::getUntilKeyWithoutPatern(), PFileParser::getUntilKeyWithoutPaternRecurse(), PFileParser::isMatch(), PFileParser::setEscapeChar(), and PFileParser::skipWhiteSpace().

Referenced by pbliblio_parserEntry().

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

◆ pbiblio_strToEntryType()

PBiblioEntryType::PBiblioEntryType pbiblio_strToEntryType ( const PString str)

Convert a string into an entry type.

Parameters
str: string to be used
Returns
corresponding entry type

Definition at line 14 of file pbiblio_parser.cpp.

14  {
15  if(str == "article"){return PBiblioEntryType::ARTICLE;}
16  else if(str == "book"){return PBiblioEntryType::BOOK;}
17  else if(str == "software"){return PBiblioEntryType::SOFTWARE;}
18  else if(str == "inproceedings"){return PBiblioEntryType::INPROCEEDINGS;}
19  else if(str == "phdthesis"){return PBiblioEntryType::PHDTHESIS;}
20  else if(str == "techreport"){return PBiblioEntryType::TECHREPORT;}
21  else {return PBiblioEntryType::NONE;}
22 }

References PBiblioEntryType::ARTICLE, PBiblioEntryType::BOOK, PBiblioEntryType::INPROCEEDINGS, PBiblioEntryType::NONE, PBiblioEntryType::PHDTHESIS, PBiblioEntryType::SOFTWARE, and PBiblioEntryType::TECHREPORT.

Referenced by pbliblio_parserEntry().

+ Here is the caller graph for this function:

◆ pbliblio_convertMapStrToBibEntry()

void pbliblio_convertMapStrToBibEntry ( PBiblioEntry biblioEntry,
PMapStrEntry mapStrEntry 
)

Convert the map of string into a PBiblioEntry.

Parameters
[out]biblioEntry: output of the conversion
mapStrEntry: map to be converted

Definition at line 103 of file pbiblio_parser.cpp.

103  {
104  biblioEntry.setLabel(mapStrEntry["label"]);
105  biblioEntry.setTitle(mapStrEntry["title"]);
106  biblioEntry.setAuthor(mapStrEntry["author"]);
107  biblioEntry.setJournal(mapStrEntry["journal"]);
108  biblioEntry.setYear(mapStrEntry["year"]);
109  biblioEntry.setUrl(mapStrEntry["url"]);
110 }
void setLabel(const PString &label)
Sets the label of the PBiblioEntry.
Definition: PLatexObj.cpp:1627
void setTitle(const PString &title)
Sets the title of the PBiblioEntry.
Definition: PLatexObj.cpp:1641
void setJournal(const PString &journal)
Sets the journal of the PBiblioEntry.
Definition: PLatexObj.cpp:1648
void setYear(const PString &year)
Sets the year of the PBiblioEntry.
Definition: PLatexObj.cpp:1683
void setAuthor(const PString &author)
Sets the author of the PBiblioEntry.
Definition: PLatexObj.cpp:1634
void setUrl(const PString &url)
Sets the url of the PBiblioEntry.
Definition: PLatexObj.cpp:1704

References PBiblioEntry::setAuthor(), PBiblioEntry::setJournal(), PBiblioEntry::setLabel(), PBiblioEntry::setTitle(), PBiblioEntry::setUrl(), and PBiblioEntry::setYear().

Referenced by pbliblio_parser().

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

◆ pbliblio_file()

bool pbliblio_file ( PMapBiblioEntry mapBiblioEntry,
const PPath fileName 
)

Parse the full bibliography file.

Parameters
[out]mapBiblioEntry: map of all the bibliography entries
fileName: name ofthe file to be parsed
Returns
true on success, false otherwise

Definition at line 139 of file pbiblio_parser.cpp.

139  {
140  PFileParser parser;
141  if(!parser.open(fileName)){
142  std::cerr << "pbliblio_file : can't open file '" << fileName << "'" << std::endl;
143  return false;
144  }
145  parser.setSeparator("()[]{}+=*.;,/%#':<>\"");
146 
147  return pbliblio_parser(parser, mapBiblioEntry);
148 }
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
bool open(const PPath &fileName)
Fonction qui ouvre le fichier que l'on va parser.
Definition: PFileParser.cpp:24
bool pbliblio_parser(PFileParser &parser, PMapBiblioEntry &mapBiblioEntry)
Parse the full bibliography file.

References PFileParser::open(), pbliblio_parser(), and PFileParser::setSeparator().

Referenced by processAllFile().

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

◆ pbliblio_parser()

bool pbliblio_parser ( PFileParser parser,
PMapBiblioEntry mapBiblioEntry 
)

Parse the full bibliography file.

Parameters
[out]parser: parser to be used
[out]mapBiblioEntry: map of all the bibliography entries
Returns
true on success, false otherwise

Definition at line 117 of file pbiblio_parser.cpp.

117  {
118  while(!parser.isEndOfFile()){
119  PMapStrEntry mapStrEntry;
121  if(pbliblio_parserEntry(parser, mapStrEntry, type)){
122  PBiblioEntry biblioEntry;
123  pbliblio_convertMapStrToBibEntry(biblioEntry, mapStrEntry);
124  biblioEntry.setId(mapBiblioEntry.size());
125  biblioEntry.setType(type);
126  mapBiblioEntry[biblioEntry.getLabel()] = biblioEntry;
127  }else{
128  return false;
129  }
130  }
131  return true;
132 }
Entry in the bibliography.
Definition: PLatexObj.h:409
const PString & getLabel() const
Gets the label of the PBiblioEntry.
Definition: PLatexObj.cpp:1921
void setId(size_t id)
Sets the id of the PBiblioEntry.
Definition: PLatexObj.cpp:1613
void setType(const PBiblioEntryType::PBiblioEntryType &type)
Sets the type of the PBiblioEntry.
Definition: PLatexObj.cpp:1620
bool isEndOfFile() const
Dit si on est à la fin du fichier.
Definition: PFileParser.cpp:88
bool pbliblio_parserEntry(PFileParser &parser, PMapStrEntry &mapStrEntry, PBiblioEntryType::PBiblioEntryType &type)
Parse the full bibliography file.
void pbliblio_convertMapStrToBibEntry(PBiblioEntry &biblioEntry, PMapStrEntry &mapStrEntry)
Convert the map of string into a PBiblioEntry.
std::map< PString, PString > PMapStrEntry
Describes one bibliograpy entry in string.

References PBiblioEntry::getLabel(), PFileParser::isEndOfFile(), pbliblio_convertMapStrToBibEntry(), pbliblio_parserEntry(), PBiblioEntry::setId(), and PBiblioEntry::setType().

Referenced by pbliblio_file().

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

◆ pbliblio_parserEntry()

bool pbliblio_parserEntry ( PFileParser parser,
PMapStrEntry mapStrEntry,
PBiblioEntryType::PBiblioEntryType type 
)

Parse the full bibliography file.

Parameters
[out]parser: parser to be used
[out]mapStrEntry: map of all the bibliography entries
type: type of the biblio entry
Returns
true on success, false otherwise

Definition at line 80 of file pbiblio_parser.cpp.

80  {
81  parser.getUntilKeyWithoutPatern("@"); //Get the start of the entry
82  PString entryType(parser.getUntilKeyWithoutPatern("{").eraseChar(" \n\t").toLower());
83  type = pbiblio_strToEntryType(entryType);
84  PString entryLabel(parser.getUntilKeyWithoutPatern(",").eraseChar(" \n\t"));
85  mapStrEntry["label"] = entryLabel;
86 
87  while(!parser.isEndOfFile() && !parser.isMatch("}")){
88  PString attrName(""), attrValue("");
89  if(pbiblio_parseAttribute(parser, attrName, attrValue)){
90  mapStrEntry[pbiblio_checkAttrName(attrName)] = pbiblio_checkAttrValue(attrValue);
91  }else{
92  return false;
93  }
94  }
95  return true;
96 }
PString toLower() const
Convert PString in lower case.
Definition: PString.cpp:598
PString pbiblio_checkAttrName(const PString &attrName)
Check the attribute name.
PString pbiblio_checkAttrValue(const PString &attrValue)
Check the attribute value.
bool pbiblio_parseAttribute(PFileParser &parser, PString &attrName, PString &attrValue)
Parse an attribute of the current bibliography entry.
PBiblioEntryType::PBiblioEntryType pbiblio_strToEntryType(const PString &str)
Convert a string into an entry type.

References PString::eraseChar(), PFileParser::getUntilKeyWithoutPatern(), PFileParser::isEndOfFile(), PFileParser::isMatch(), pbiblio_checkAttrName(), pbiblio_checkAttrValue(), pbiblio_parseAttribute(), pbiblio_strToEntryType(), and PString::toLower().

Referenced by pbliblio_parser().

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