You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 line
809 B

5 年之前
  1. #pragma once
  2. #include <fstream>
  3. #include <iostream>
  4. #include <string>
  5. #include <cctype>
  6. #include <algorithm>
  7. namespace config
  8. {
  9. inline std::string get_value(const std::string& source)
  10. {
  11. std::string ret = source;
  12. try
  13. {
  14. std::ifstream config_file("/home/archivist/.rigidparadise/rp.cfg");
  15. if(!config_file.good())
  16. {
  17. std::cerr << "Unable to read configuration"<<std::endl;
  18. }
  19. while(config_file.good())
  20. {
  21. std::string str;
  22. getline (config_file, str);
  23. if(str.size()>1 && str[0] != '#')
  24. {
  25. auto end = std::find_if(str.begin(), str.end(), isspace);
  26. size_t pos = end-str.begin();
  27. std::string_view name{str.data(), pos};
  28. if(name == source)
  29. {
  30. ret = std::string{end+1, str.end()};
  31. }
  32. }
  33. }
  34. }
  35. catch(...)
  36. {}
  37. return ret;
  38. }
  39. }