6 * $Date: 2012-07-07 00:03:48 +0200 (Sa, 07. Jul 2012) $
7 ***************************************************************/
10 * \brief Contains the enum XmlToken and the class DinoXmlScanner.
15 * This file is part of the Open Graph Drawing Framework (OGDF).
19 * See README.txt in the root directory of the OGDF installation for details.
22 * This program is free software; you can redistribute it and/or
23 * modify it under the terms of the GNU General Public License
24 * Version 2 or 3 as published by the Free Software Foundation;
25 * see the file LICENSE.txt included in the packaging of this file
29 * This program is distributed in the hope that it will be useful,
30 * but WITHOUT ANY WARRANTY; without even the implied warranty of
31 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32 * GNU General Public License for more details.
35 * You should have received a copy of the GNU General Public
36 * License along with this program; if not, write to the Free
37 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
38 * Boston, MA 02110-1301, USA.
40 * \see http://www.gnu.org/copyleft/gpl.html
41 ***************************************************************/
48 #ifndef OGDF_DINO_XML_SCANNER_H
49 #define OGDF_DINO_XML_SCANNER_H
51 #include <ogdf/fileformats/DinoLineBuffer.h>
55 //---------------------------------------------------------
57 //---------------------------------------------------------
58 /** This enum type represents the values, which are returned by
59 * the function DinoXmlScanner::getNextToken().
60 * @see DinoXmlScanner::getNextToken()
63 openingBracket
, ///< <
64 closingBracket
, ///< >
66 exclamationMark
, ///< !
70 identifier
, ///< (a..z|A..Z){(a..z|A..Z|0..9|.|_|:)}
71 attributeValue
, ///< a sequence of characters, digits, minus - and dot .
72 quotedValue
, ///< all quoted content " ... " or ' ... '
73 endOfFile
, ///< End of file detected
74 invalidToken
, ///< No token identified
75 noToken
///< Used for the m_lookAheadToken to indicate that there
76 ///< is no lookahead token
80 //---------------------------------------------------------
81 // D i n o X m l S c a n n e r
82 //---------------------------------------------------------
83 /** This class scans the characters of the input file and
84 * provides the detected token.
86 class OGDF_EXPORT DinoXmlScanner
{
90 // Pointer to the line buffer
91 DinoLineBuffer
*m_pLineBuffer
;
93 // String which contains the characters of the current token
94 // Its size is limited to DinoLineBuffer::c_maxStringLength
95 char *m_pCurrentTokenString
;
99 DinoXmlScanner(const char *fileName
);
101 // destruction: destroys the parse tree
104 // This function represents the core of the scanner. It scans the input
105 // and returns the identified token. After performing getNextToken() the
106 // token is "consumed", i.e. the line buffer pointer already points to the
108 // The scanned string is deposited in m_pCurrentTokenString, hence it is
109 // available via getCurrentTokenString()
110 XmlToken
getNextToken();
112 // Returns the current token string
113 inline const char *getCurrentTokenString(){
114 return m_pCurrentTokenString
;
117 // This function provides a lookahead to the next token;
118 // the token is NOT consumed like it is the case for getNextToken()
119 XmlToken
testNextToken();
121 // This function provides a lookahead to the nextnext token;
122 // the tokens are NOT consumed like it is the case for getNextToken()
123 XmlToken
testNextNextToken();
125 // Skips until the searchCharacter is found;
127 // If skipOverSearchCharacter is set true the currentPosition will be set
128 // BEHIND the search character
129 // otherwise the pointer currentPosition points TO the searchCharacter
131 // Returns true if the searchCharacter is found
132 // Returns false if file ends before the searchCharacter is found
133 bool skipUntil(char searchCharacter
, bool skipOverSearchCharacter
= true);
135 // Skips until '>' is found (> is consumed)
136 // Nested brackets are taken into account
137 // Returns true if matching bracket has been found; false otherwise
138 bool skipUntilMatchingClosingBracket();
140 // Reads until the searchCharacter is found; the string starting at the current
141 // position and ending at the position where the search character is found
142 // is deposited in m_pCurrentTokenString.
143 // If includeSearchCharacter is false (default) the search character is
144 // not contained; otherwise it is contained
146 // Returns true if the searchCharacter is found
147 // Returns false if file ends before the searchCharacter is found
148 bool readStringUntil(char searchCharacter
, bool includeSearchCharacter
= false);
150 // Returns line number of the most recently read line of the input file
151 inline int getInputFileLineCounter() const {
152 return m_pLineBuffer
->getInputFileLineCounter();
155 // This function tests the scanner by reading the complete
156 // input file and printing the identified token to stdout
159 }; // class DinoXmlScanner
161 } // end namespace ogdf