00001 /*---------------------------------------------------------------------\ 00002 | ____ _ __ __ ___ | 00003 | |__ / \ / / . \ . \ | 00004 | / / \ V /| _/ _/ | 00005 | / /__ | | | | | | | 00006 | /_____||_| |_| |_| | 00007 | | 00008 \---------------------------------------------------------------------*/ 00012 #include <iostream> 00013 #include <sstream> 00014 00015 #include "zypp/base/Logger.h" 00016 #include "zypp/base/String.h" 00017 #include "zypp/base/IOStream.h" 00018 00019 #include "zypp/parser/IniParser.h" 00020 00021 using std::endl; 00022 00024 namespace zypp 00025 { 00026 00027 namespace parser 00028 { 00029 00031 // 00032 // METHOD NAME : IniParser::IniParser 00033 // METHOD TYPE : Ctor 00034 // 00035 IniParser::IniParser() 00036 : _line_nr(0) 00037 {} 00038 00040 // 00041 // METHOD NAME : IniParser::~IniParser 00042 // METHOD TYPE : Dtor 00043 // 00044 IniParser::~IniParser() 00045 {} 00046 00047 void IniParser::beginParse() 00048 {} 00049 00050 void IniParser::consume( const std::string §ion, const std::string &key, const std::string &value ) 00051 {} 00052 00053 void IniParser::consume( const std::string §ion ) 00054 {} 00055 00056 void IniParser::endParse() 00057 {} 00058 00060 // 00061 // METHOD NAME : IniParser::parse 00062 // METHOD TYPE : void 00063 // 00064 void IniParser::parse( const InputStream & input_r ) 00065 { 00066 MIL << "Start parsing " << input_r << endl; 00067 _inputname = input_r.name(); 00068 beginParse(); 00069 00070 iostr::EachLine line( input_r ); 00071 for ( ; line; line.next() ) 00072 { 00073 std::string trimmed = str::trim(*line); 00074 00075 if (trimmed.empty() || trimmed[0] == ';' || trimmed[0] == '#') 00076 continue ; /* Comment lines */ 00077 00078 if (trimmed[0] == '[') 00079 { 00080 std::string section = trimmed.substr(1, trimmed.find(']')-1); 00081 consume(section); 00082 section.swap(_current_section); 00083 continue; 00084 } 00085 00086 std::string::size_type pos = trimmed.find('='); 00087 00088 if (pos != std::string::npos) 00089 { 00090 std::string key = str::rtrim(trimmed.substr(0, pos)); 00091 std::string value = str::ltrim(trimmed.substr(pos+1)); 00092 consume( _current_section, key, value); 00093 } 00094 00095 } 00096 00097 endParse(); 00098 _inputname.clear(); 00099 MIL << "Done parsing " << input_r << endl; 00100 } 00101 00103 } // namespace parser 00106 } // namespace zypp
1.4.6