21 #include <zypp-core/base/UserRequestException> 23 #include <zypp-core/parser/ParseException> 24 #include <zypp-core/ui/ProgressData> 36 inline const std::string & keyGarbage()
38 static const std::string & _val(
":/?|,\\" );
53 : _inputname { std::move(rhs._inputname) }
54 , _current_section { std::move(rhs._current_section) }
55 , _line_nr { std::move(rhs._line_nr) }
69 void IniParser::consume(
const std::string §ion,
const std::string &key,
const std::string &value )
80 std::string msg =
str::form(
"%s: Section [%s]: Line %d contains garbage (no '=' or '%s' in key)",
92 MIL <<
"Start parsing " << input_r << endl;
101 for ( ; line; line.
next() )
105 if (trimmed.empty() || trimmed[0] ==
';' || trimmed[0] ==
'#')
108 if (trimmed[0] ==
'[')
111 if ( pos != std::string::npos )
113 std::string section = trimmed.substr(1, pos-1);
126 if ( pos == std::string::npos || trimmed.find_first_of( keyGarbage() ) < pos )
133 std::string key =
str::rtrim(trimmed.substr(0, pos));
134 std::string value =
str::ltrim(trimmed.substr(pos+1));
139 if ( ! ticks.
set( input_r.
stream().tellg() ) )
146 MIL <<
"Done parsing " << input_r << endl;
void parse(const InputStream &imput_r, const ProgressData::ReceiverFnc &progress=ProgressData::ReceiverFnc())
Parse the stream.
ProgressData makeProgressData(const InputStream &input_r)
relates: ProgressData Setup from InputStream.
void sendTo(const ReceiverFnc &fnc_r)
Set ReceiverFnc.
#define ZYPP_THROW(EXCPT)
Drops a logline and throws the Exception.
bool next()
Advance to next line.
function< bool(const ProgressData &)> ReceiverFnc
Most simple version of progress reporting The percentage in most cases.
unsigned lineNo() const
Return the current line number.
bool toMax()
Set counter value to current max value (unless no range).
Simple lineparser: Traverse each line in a file.
std::string form(const char *format,...) __attribute__((format(printf
Printf style construction of std::string.
std::string _current_section
std::string ltrim(const std::string &s)
virtual ~IniParser()
Dtor.
virtual void beginParse()
Called when start parsing.
bool toMin()
Set counter value to current min value.
std::string trim(const std::string &s, const Trim trim_r)
Maintain [min,max] and counter (value) for progress counting.
virtual void garbageLine(const std::string §ion, const std::string &line)
Called whenever a garbage line is found.
std::string rtrim(const std::string &s)
virtual void endParse()
Called when the parse is done.
bool set(value_type val_r)
Set new counter value.
Easy-to use interface to the ZYPP dependency resolver.
virtual void consume(const std::string §ion)
Called when a section is found.