| 19 | } // namespace |
| 20 | |
| 21 | FactoryOptionsParseResult parse_factory_options(const std::string& factory_string) { |
| 22 | FactoryOptionsParseResult result; |
| 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 |
no test coverage detected