MCPcopy Create free account
hub / github.com/devsisters/libquic / AppendStringKeyValue

Function AppendStringKeyValue

src/base/strings/string_split.cc:104–131  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

102}
103
104bool 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
133template <typename Str, typename OutputStringType>
134void SplitStringUsingSubstrT(BasicStringPiece<Str> input,

Callers 1

Calls 7

find_first_ofMethod · 0.80
CopyToStringMethod · 0.80
substrMethod · 0.80
find_first_not_ofMethod · 0.80
resizeMethod · 0.45
sizeMethod · 0.45
backMethod · 0.45

Tested by

no test coverage detected