1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/parser/IniParser.h
12 #ifndef ZYPP_PARSER_INIPARSER_H
13 #define ZYPP_PARSER_INIPARSER_H
19 #include "zypp/base/PtrTypes.h"
20 #include "zypp/base/NonCopyable.h"
21 #include "zypp/base/InputStream.h"
22 #include "zypp/ProgressData.h"
24 ///////////////////////////////////////////////////////////////////
26 { /////////////////////////////////////////////////////////////////
27 ///////////////////////////////////////////////////////////////////
29 { /////////////////////////////////////////////////////////////////
31 ///////////////////////////////////////////////////////////////////
33 /// \brief Simple INI-file parser
35 /// Lines staring with \c ; or \c # are treated as comment. Section
36 /// names are enclosed by <tt>[]</tt>. Key and value are separated by \c =.
38 /// Lines without \c = or with a key containing any of "<tt>,|\\/</tt>"
39 /// or section lines without closing \c ] are considered garbage.
41 class IniParser : private base::NonCopyable
49 * \throw ParseException on errors. Invoke \ref consume
50 * for each tag. \ref consume might throw other exceptions
53 void parse( const InputStream & imput_r, const ProgressData::ReceiverFnc & progress = ProgressData::ReceiverFnc() );
56 /** Called when start parsing. */
57 virtual void beginParse();
58 /** Called when a section is found. */
59 virtual void consume( const std::string §ion );
60 /** Called when a key value is found. */
61 virtual void consume( const std::string §ion, const std::string &key, const std::string &value );
62 /** Called when the parse is done. */
63 virtual void endParse();
65 /** Called whenever a garbage line is found.
67 * \throw ParseException if not overloaded.
69 * Derived parsers may overload this to examine the line
70 * and call this method to actually throw the exception.
72 * Used by some parsers to accept multi-line entires.
74 virtual void garbageLine( const std::string §ion, const std::string &line );
77 /** Name of the current InputStream. */
78 const std::string & inputname() const
84 std::string _inputname;
85 std::string _current_section;
87 //ProgressData _ticks;
90 /////////////////////////////////////////////////////////////////
92 ///////////////////////////////////////////////////////////////////
93 /////////////////////////////////////////////////////////////////
95 ///////////////////////////////////////////////////////////////////
96 #endif // ZYPP_PARSER_INIPARSER_H