MCPcopy Create free account
hub / github.com/apache/brpc / SplitStringAlongWhitespaceT

Function SplitStringAlongWhitespaceT

src/butil/strings/string_split.cc:89–127  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

87
88template<typename STR>
89void SplitStringAlongWhitespaceT(const STR& str, std::vector<STR>* result) {
90 result->clear();
91 const size_t length = str.length();
92 if (!length)
93 return;
94
95 bool last_was_ws = false;
96 size_t last_non_ws_start = 0;
97 for (size_t i = 0; i < length; ++i) {
98 switch (str[i]) {
99 // HTML 5 defines whitespace as: space, tab, LF, line tab, FF, or CR.
100 case L' ':
101 case L'\t':
102 case L'\xA':
103 case L'\xB':
104 case L'\xC':
105 case L'\xD':
106 if (!last_was_ws) {
107 if (i > 0) {
108 result->push_back(
109 str.substr(last_non_ws_start, i - last_non_ws_start));
110 }
111 last_was_ws = true;
112 }
113 break;
114
115 default: // Not a space character.
116 if (last_was_ws) {
117 last_was_ws = false;
118 last_non_ws_start = i;
119 }
120 break;
121 }
122 }
123 if (!last_was_ws) {
124 result->push_back(
125 str.substr(last_non_ws_start, length - last_non_ws_start));
126 }
127}
128
129} // namespace
130

Callers 1

Calls 4

substrMethod · 0.80
clearMethod · 0.45
lengthMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected