---------------------------------------------------------------------- SplitStringIntoKeyValues() ----------------------------------------------------------------------
| 959 | // SplitStringIntoKeyValues() |
| 960 | // ---------------------------------------------------------------------- |
| 961 | bool SplitStringIntoKeyValues(const string& line, |
| 962 | const string& key_value_delimiters, |
| 963 | const string& value_value_delimiters, |
| 964 | string *key, vector<string> *values) { |
| 965 | key->clear(); |
| 966 | values->clear(); |
| 967 | |
| 968 | // find the key string |
| 969 | size_t end_key_pos = line.find_first_of(key_value_delimiters); |
| 970 | if (end_key_pos == string::npos) { |
| 971 | VLOG(1) << "cannot parse key from line: " << line; |
| 972 | return false; // no key |
| 973 | } |
| 974 | key->assign(line, 0, end_key_pos); |
| 975 | |
| 976 | // find the values string |
| 977 | string remains(line, end_key_pos, line.size() - end_key_pos); |
| 978 | size_t begin_values_pos = remains.find_first_not_of(key_value_delimiters); |
| 979 | if (begin_values_pos == string::npos) { |
| 980 | VLOG(1) << "cannot parse value from line: " << line; |
| 981 | return false; // no value |
| 982 | } |
| 983 | string values_string(remains, |
| 984 | begin_values_pos, |
| 985 | remains.size() - begin_values_pos); |
| 986 | |
| 987 | // construct the values vector |
| 988 | if (value_value_delimiters.empty()) { // one value |
| 989 | values->push_back(values_string); |
| 990 | } else { // multiple values |
| 991 | SplitStringUsing(values_string, value_value_delimiters.c_str(), values); |
| 992 | if (values->size() < 1) { |
| 993 | VLOG(1) << "cannot parse value from line: " << line; |
| 994 | return false; // no value |
| 995 | } |
| 996 | } |
| 997 | return true; |
| 998 | } |
| 999 | |
| 1000 | bool SplitStringIntoKeyValuePairs(const string& line, |
| 1001 | const string& key_value_delimiters, |
no test coverage detected