"Fossies" - the Fresh Open Source Software Archive

Member "cb2bib-2.0.1/src/c2b/texParser.h" (12 Feb 2021, 1977 Bytes) of package /linux/privat/cb2bib-2.0.1.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "texParser.h" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 2.0.0_vs_2.0.1.

    1 /***************************************************************************
    2  *   Copyright (C) 2004-2021 by Pere Constans
    3  *   constans@molspaces.com
    4  *   cb2Bib version 2.0.1. Licensed under the GNU GPL version 3.
    5  *   See the LICENSE file that comes with this distribution.
    6  ***************************************************************************/
    7 #ifndef TEXPARSER_H
    8 #define TEXPARSER_H
    9 
   10 #include <QString>
   11 #include <QTextStream>
   12 
   13 
   14 /**
   15     Minimalist TeX parser
   16 */
   17 class texParser
   18 {
   19 
   20 public:
   21     inline texParser() : _stop_parsing(false) {}
   22     inline virtual ~texParser() {}
   23 
   24 
   25 protected:
   26     virtual void parseComment(const QString& /* p */) {}
   27     virtual void parseElement(const QString& /* p */, const QString& /* e */, const QString& /* v */) {}
   28     virtual void parseEmptyLine() {}
   29     virtual void parseLaTeXMarkup(const QString& /* p */, const QString& /* e */) {}
   30     virtual void parseTextParagraph(const QString& /* p */) {}
   31     void parse(QString tex);
   32 
   33     inline void stop()
   34     {
   35         _stop_parsing = true;
   36     }
   37 
   38 
   39 private:
   40     QString _element;
   41     QString _line;
   42     QString _paragraph;
   43     QTextStream _stream;
   44     bool _stop_parsing;
   45     void doElement();
   46     void gotoEnd(const QString& e);
   47     void gotoEndBraces(const QString& e);
   48     void gotoEndMacro(const QString& e);
   49 
   50     inline const QString& readLine(const bool trim = false)
   51     {
   52         if (trim)
   53             _line = _stream.readLine().trimmed();
   54         else
   55             _line = _stream.readLine();
   56         return _line;
   57     }
   58 
   59     inline void flushElement(const QString& e, const QString& v)
   60     {
   61         flush();
   62         parseElement(_element, e, v);
   63     }
   64 
   65     inline void flushLaTeXMarkup(const QString& e)
   66     {
   67         _element = _line;
   68         flush();
   69         parseLaTeXMarkup(_element, e);
   70     }
   71 
   72     inline void flush()
   73     {
   74         if (_paragraph.isEmpty())
   75             return;
   76         parseTextParagraph(_paragraph.mid(1));
   77         _paragraph.clear();
   78     }
   79 };
   80 
   81 #endif