namespace sysconfig {
map<string,string> read( const Pathname & _path )
{
- DBG << "Load '" << _path << "'" << endl;
- map<string,string> ret;
+ DBG << "Load '" << _path << "'" << endl;
+ map<string,string> ret;
- string line;
- ifstream in( _path.asString().c_str() );
- if ( in.fail() ) {
- WAR << "Unable to load '" << _path << "'" << endl;
- return ret;
- }
- while( getline( in, line ) ) {
- if ( *line.begin() != '#' ) {
- string::size_type pos = line.find( '=', 0 );
- if ( pos != string::npos ) {
- string key = str::trim( line.substr( 0, pos ) );
- string value = str::trim( line.substr( pos + 1, line.length() - pos - 1 ) );
- if ( value.length() >= 2 && *(value.begin()) == '"' &&
- *(value.rbegin()) == '"' ) {
- value = value.substr( 1, value.length() - 2 );
- }
- if ( value.length() >= 2 && *(value.begin()) == '\'' &&
- *(value.rbegin()) == '\'' ) {
- value = value.substr( 1, value.length() - 2 );
- }
- DBG << "KEY: '" << key << "' VALUE: '" << value << "'" << endl;
- ret[key] = value;
- }
- }
- }
- return ret;
+ string line;
+ ifstream in( _path.asString().c_str() );
+ if ( in.fail() ) {
+ WAR << "Unable to load '" << _path << "'" << endl;
+ return ret;
+ }
+
+ while( getline( in, line ) ) {
+ if ( *line.begin() != '#' ) {
+
+ string::size_type pos = line.find( '=', 0 );
+
+ if ( pos != string::npos ) {
+
+ string key = str::trim( line.substr( 0, pos ) );
+ string value = str::trim( line.substr( pos + 1, line.length() - pos - 1 ) );
+
+ if ( value.length() >= 2
+ && *(value.begin()) == '"'
+ && *(value.rbegin()) == '"' )
+ {
+ value = value.substr( 1, value.length() - 2 );
+ }
+ if ( value.length() >= 2
+ && *(value.begin()) == '\''
+ && *(value.rbegin()) == '\'' )
+ {
+ value = value.substr( 1, value.length() - 2 );
+ }
+ XXX << "KEY: '" << key << "' VALUE: '" << value << "'" << endl;
+ ret[key] = value;
+
+ } // '=' found
+
+ } // not comment
+
+ } // while getline
+
+ return ret;
}
} // namespace sysconfig