MCPcopy Create free account
hub / github.com/USBGuard/usbguard / parseLine

Method parseLine

src/Library/KeyValueParserPrivate.cpp:62–91  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

60 }
61
62 std::pair<std::string, std::string> KeyValueParserPrivate::parseLine(std::string& str)
63 {
64 std::string::size_type sep_pos;
65 std::string key, val;
66 sep_pos = str.find(this->_separator);
67
68 if (sep_pos == std::string::npos) {
69 throw Exception("KeyValueParser", "Parser", "Separator not found: syntax error");
70 }
71 else {
72 key = str.substr(0, sep_pos);
73 val = str.substr(sep_pos + 1);
74 key = trim(key);
75 val = trim(val);
76
77 if (!this->_case_sensitive) {
78 for (size_t i = 0 ; i < key.length() ; i++) {
79 key[i] = std::toupper(key[i], this->_loc);
80 }
81 }
82
83 if (_validate_keys && this->checkKeyValidity(key)) {
84 USBGUARD_LOG(Error) << "Error: parsed key is not in key set: '" << key << "'";
85 throw Exception("KeyValueParser", "Parser", "Invalid key");
86 }
87 else {
88 return std::make_pair(key, val);
89 }
90 }
91 }
92
93 void KeyValueParserPrivate::parseStream(std::istream& stream)
94 {

Callers 2

parseStreamMethod · 0.95
parseMethod · 0.45

Calls 3

checkKeyValidityMethod · 0.95
ExceptionFunction · 0.85
trimFunction · 0.85

Tested by

no test coverage detected