28 using namespace zypp::base;
36 DBG <<
"Load '" << _path <<
"'" << endl;
40 ifstream in( _path.asString().c_str() );
42 WAR <<
"Unable to load '" << _path <<
"'" << endl;
47 if ( *line.begin() !=
'#' ) {
51 if ( pos != string::npos ) {
53 string key =
str::trim( line.substr( 0, pos ) );
54 string value =
str::trim( line.substr( pos + 1, line.length() - pos - 1 ) );
56 if ( value.length() >= 2
57 && *(value.begin()) ==
'"'
58 && *(value.rbegin()) ==
'"' )
60 value = value.substr( 1, value.length() - 2 );
62 if ( value.length() >= 2
63 && *(value.begin()) ==
'\''
64 && *(value.rbegin()) ==
'\'' )
66 value = value.substr( 1, value.length() - 2 );
68 XXX <<
"KEY: '" << key <<
"' VALUE: '" << value <<
"'" << endl;
76 MIL <<
"done reading '" << _path <<
"'" << endl;
80 bool write(
const Pathname & path_r,
const std::string & key_r,
const std::string & val_r,
const std::string & newcomment_r )
84 WAR <<
"Empty key in write " << path_r << endl;
88 PathInfo pi( path_r );
91 if ( ! pi.userMayRW() )
97 StrMatcher matches(
"^[ \t]*"+key_r+
"[ \t]*=", Match::REGEX );
100 [&](
int num_r, std::string line_r )->
bool
102 if ( !found && matches( line_r ) )
104 o << key_r <<
'=' << val_r << endl;
106 MIL << path_r <<
": " << key_r <<
'=' << val_r <<
" changed on line " << num_r << endl;
114 if ( newcomment_r.empty() )
116 WAR << path_r <<
": " << key_r <<
'=' << val_r <<
" can not be added (no comment provided)." << endl;
120 std::vector<std::string> lines;
121 str::split( newcomment_r, std::back_inserter(lines),
"\r\n" );
123 for (
auto line : lines )
125 if ( line[0] !=
'#' )
129 o << key_r <<
'=' << val_r << endl;
131 MIL << path_r <<
": " << key_r <<
'=' << val_r <<
" appended. " << endl;
148 bool writeStringVal(
const Pathname & path_r,
const std::string & key_r,
const std::string & val_r,
const std::string & newcomment_r )