inst_util.cc
// Look up a keyed value from a /etc/lsb-release formatted file.
// TODO(dgarrett): If we ever call this more than once, cache
// file contents to avoid reparsing.
Look up a keyed value from a /etc/lsb-release formatted file.
TODO(dgarrett): If we ever call this more than once, cache
file contents to avoid reparsing.
Look up a keyed value from a / etc / lsb - release formatted file . TODO ( dgarrett ) : If we ever call this more than once cache file contents to avoid reparsing .
bool LsbReleaseValue(const string& file,
                     const string& key,
                     string* result) {
  string preamble = key + "=";
  string file_contents;
  if (!ReadFileToString(file, &file_contents))
    return false;
  std::vector<string> file_lines;
  SplitString(file_contents, '\n', &file_lines);
  std::vector<string>::iterator line;
  for (line = file_lines.begin(); line < file_lines.end(); line++) {
    if (line->compare(0, preamble.size(), preamble) == 0) {
      *result = line->substr(preamble.size());
      return true;
    }
  }
  return false;
}
bool LsbReleaseValue ( const string & file , const string & key , string * result ) { string preamble = key + " " ; string file_contents ; if ( ! ReadFileToString ( file , & file_contents ) ) return false ; std :: vector < string > file_lines ; SplitString ( file_contents , ' \n ' , & file_lines ) ; std :: vector < string > :: iterator line ; for ( line = file_lines . begin ( ) ; line < file_lines . end ( ) ; line ++ ) { if ( line -> compare ( 0 , preamble . size ( ) , preamble ) == 0 ) { * result = line -> substr ( preamble . size ( ) ) ; return true ; } } return false ; }
Look up a keyed value from a /etc/lsb-release formatted file.
Look up a keyed value from a / etc / lsb - release formatted file .