inst_util.cc
// Replace the first instance of pattern in the file with value.
Replace the first instance of pattern in the file with value.
Replace the first instance of pattern in the file with value .
bool ReplaceInFile(const string& pattern,
                   const string& value,
                   const string& path) {
  string contents;
  if (!ReadFileToString(path, &contents))
    return false;
  size_t offset = contents.find(pattern);
  if (offset == string::npos) {
    printf("ReplaceInFile failed to find '%s' in %s\n",
           pattern.c_str(),
           path.c_str());
    return false;
  }
  contents.replace(offset, pattern.length(), value);
  if (!WriteStringToFile(contents, path))
    return false;
  return true;
}
bool ReplaceInFile ( const string & pattern , const string & value , const string & path ) { string contents ; if ( ! ReadFileToString ( path , & contents ) ) return false ; size_t offset = contents . find ( pattern ) ; if ( offset == string :: npos ) { printf ( " \n " , pattern . c_str ( ) , path . c_str ( ) ) ; return false ; } contents . replace ( offset , pattern . length ( ) , value ) ; if ( ! WriteStringToFile ( contents , path ) ) return false ; return true ; }
Replace the first instance of pattern in the file with value.
Replace the first instance of pattern in the file with value .
// Modify contents