MCPcopy Create free account
hub / github.com/cppcheck-opensource/cppcheck / splitString

Function splitString

lib/clangimport.cpp:126–204  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

124
125
126static std::vector<std::string> splitString(const std::string &line)
127{
128 std::vector<std::string> ret;
129 std::string::size_type pos1 = line.find_first_not_of(' ');
130 while (pos1 < line.size()) {
131 std::string::size_type pos2;
132 if (std::strchr("*()", line[pos1])) {
133 ret.push_back(line.substr(pos1,1));
134 pos1 = line.find_first_not_of(' ', pos1 + 1);
135 continue;
136 }
137 if (line[pos1] == '<')
138 pos2 = line.find('>', pos1);
139 else if (line[pos1] == '\"')
140 pos2 = line.find('\"', pos1+1);
141 else if (line[pos1] == '\'') {
142 pos2 = line.find('\'', pos1+1);
143 if (pos2 < static_cast<int>(line.size()) - 3 && line.compare(pos2, 3, "\':\'", 0, 3) == 0)
144 pos2 = line.find('\'', pos2 + 3);
145 } else {
146 pos2 = pos1;
147 while (pos2 < line.size() && (line[pos2] == '_' || line[pos2] == ':' || std::isalnum(static_cast<unsigned char>(line[pos2]))))
148 ++pos2;
149 if (pos2 > pos1 && pos2 < line.size() && line[pos2] == '<' && std::isalpha(line[pos1])) {
150 int tlevel = 1;
151 while (++pos2 < line.size() && tlevel > 0) {
152 if (line[pos2] == '<')
153 ++tlevel;
154 else if (line[pos2] == '>')
155 --tlevel;
156 }
157 if (tlevel == 0 && pos2 < line.size() && line[pos2] == ' ') {
158 ret.push_back(line.substr(pos1, pos2-pos1));
159 pos1 = pos2 + 1;
160 continue;
161 }
162 }
163
164 pos2 = line.find(' ', pos1) - 1;
165 if ((std::isalpha(line[pos1]) || line[pos1] == '_') &&
166 line.find("::", pos1) < pos2 &&
167 line.find("::", pos1) < line.find('<', pos1)) {
168 pos2 = line.find("::", pos1);
169 ret.push_back(line.substr(pos1, pos2-pos1));
170 ret.emplace_back("::");
171 pos1 = pos2 + 2;
172 continue;
173 }
174 if ((std::isalpha(line[pos1]) || line[pos1] == '_') &&
175 line.find('<', pos1) < pos2 &&
176 line.find("<<",pos1) != line.find('<',pos1) &&
177 line.find('>', pos1) != std::string::npos &&
178 line.find('>', pos1) > pos2) {
179 int level = 0;
180 for (pos2 = pos1; pos2 < line.size(); ++pos2) {
181 if (line[pos2] == '<')
182 ++level;
183 else if (line[pos2] == '>') {

Callers 2

AstNodeMethod · 0.70
addTypeTokensMethod · 0.70

Calls 5

isalnumFunction · 0.85
sizeMethod · 0.45
push_backMethod · 0.45
findMethod · 0.45
compareMethod · 0.45

Tested by

no test coverage detected