src/linux_parser.cpp
// DONE: An example of how to read data from the filesystem
An example of how to read data from the filesystem
An example of how to read data from the filesystem
string LinuxParser::OperatingSystem() {
  string line;
  string key;
  string value;
  std::ifstream filestream(kOSPath);
  if (filestream.is_open()) {
    while (std::getline(filestream, line)) {
      std::replace(line.begin(), line.end(), ' ', '_');
      std::replace(line.begin(), line.end(), '=', ' ');
      std::replace(line.begin(), line.end(), '"', ' ');
      std::istringstream linestream(line);
      while (linestream >> key >> value) {
        if (key == "PRETTY_NAME") {
          std::replace(value.begin(), value.end(), '_', ' ');
          return value;
        }
      }
    }
  }
  filestream.close();
  return value;
}
string LinuxParser :: OperatingSystem ( ) { string line ; string key ; string value ; std :: ifstream filestream ( kOSPath ) ; if ( filestream . is_open ( ) ) { while ( std :: getline ( filestream , line ) ) { std :: replace ( line . begin ( ) , line . end ( ) , ' ' , ' ' ) ; std :: replace ( line . begin ( ) , line . end ( ) , ' ' , ' ' ) ; std :: replace ( line . begin ( ) , line . end ( ) , ' ' , ' ' ) ; std :: istringstream linestream ( line ) ; while ( linestream >> key >> value ) { if ( key == " " ) { std :: replace ( value . begin ( ) , value . end ( ) , ' ' , ' ' ) ; return value ; } } } } filestream . close ( ) ; return value ; }
DONE: An example of how to read data from the filesystem
DONE : An example of how to read data from the filesystem
// Create an input fstream using the file that stores OS information // If the file opened without problems // Repeat the process bellow while we have lines in the file // Replaces some of the characters of the line (which is a string) for // processing the stream better // Create a stringstream from the current line // Read (key, value) pairs until the line ends. In this example, there is // only 1 (key, value) pair on each line // Check if the key is the one which has the OS's name as value // Replace '_' with ' ' in order to reverse the replacement made // earlier // Return the obtained string // Return empty string if finding the OS name failed