CoolProp 8.0.0
An open-source fluid property and humid air property database
FactoryOptions.cpp
Go to the documentation of this file.
2
3#include <algorithm>
4#include <cctype>
5#include <cstddef>
6#include <string>
7
10
11namespace CoolProp {
12
13namespace {
14
15bool is_all_whitespace(const std::string& s) {
16 return std::all_of(s.begin(), s.end(), [](unsigned char c) { return std::isspace(c) != 0; });
17}
18
19} // namespace
20
21FactoryOptionsParseResult parse_factory_options(const std::string& factory_string) {
23
24 const std::size_t pos = factory_string.find_first_of('?');
25 if (pos == std::string::npos) {
26 result.clean_string = factory_string;
27 return result;
28 }
29
30 result.clean_string = factory_string.substr(0, pos);
31 std::string tail = factory_string.substr(pos + 1);
32
33 if (tail.empty() || is_all_whitespace(tail)) {
34 return result;
35 }
36
37 if (tail.front() == '@') {
38 const std::string path = tail.substr(1);
39 if (path.empty()) {
40 throw ValueError("factory-string options: '@' indirection requires a non-empty path");
41 }
42 // get_file_contents() reads the file verbatim and throws on
43 // read failure. The path may contain '?' / '&' / spaces /
44 // etc. — no further parsing of the path string.
45 result.options_json = get_file_contents(path.c_str());
46 return result;
47 }
48
49 result.options_json = std::move(tail);
50 return result;
51}
52
53} // namespace CoolProp