| 102 | } |
| 103 | |
| 104 | bool AppendStringKeyValue(StringPiece input, |
| 105 | char delimiter, |
| 106 | StringPairs* result) { |
| 107 | // Always append a new item regardless of success (it might be empty). The |
| 108 | // below code will copy the strings directly into the result pair. |
| 109 | result->resize(result->size() + 1); |
| 110 | auto& result_pair = result->back(); |
| 111 | |
| 112 | // Find the delimiter. |
| 113 | size_t end_key_pos = input.find_first_of(delimiter); |
| 114 | if (end_key_pos == std::string::npos) { |
| 115 | DVLOG(1) << "cannot find delimiter in: " << input; |
| 116 | return false; // No delimiter. |
| 117 | } |
| 118 | input.substr(0, end_key_pos).CopyToString(&result_pair.first); |
| 119 | |
| 120 | // Find the value string. |
| 121 | StringPiece remains = input.substr(end_key_pos, input.size() - end_key_pos); |
| 122 | size_t begin_value_pos = remains.find_first_not_of(delimiter); |
| 123 | if (begin_value_pos == StringPiece::npos) { |
| 124 | DVLOG(1) << "cannot parse value from input: " << input; |
| 125 | return false; // No value. |
| 126 | } |
| 127 | remains.substr(begin_value_pos, remains.size() - begin_value_pos) |
| 128 | .CopyToString(&result_pair.second); |
| 129 | |
| 130 | return true; |
| 131 | } |
| 132 | |
| 133 | template <typename Str, typename OutputStringType> |
| 134 | void SplitStringUsingSubstrT(BasicStringPiece<Str> input, |
no test coverage detected