MCPcopy Create free account
hub / github.com/boostorg/compute / parse_argument_names

Function parse_argument_names

include/boost/compute/function.hpp:252–289  ·  view source on GitHub ↗

given a string containing the arguments declaration for a function like: "(int a, const float b)", returns a vector containing the name of each argument (e.g. ["a", "b"]).

Source from the content-addressed store, hash-verified

250// like: "(int a, const float b)", returns a vector containing the name
251// of each argument (e.g. ["a", "b"]).
252inline std::vector<std::string> parse_argument_names(const char *arguments)
253{
254 BOOST_ASSERT_MSG(
255 arguments[0] == '(' && arguments[std::strlen(arguments)-1] == ')',
256 "Arguments should start and end with parentheses"
257 );
258
259 std::vector<std::string> args;
260
261 size_t last_space = 0;
262 size_t skip_comma = 0;
263 for(size_t i = 1; i < std::strlen(arguments) - 2; i++){
264 const char c = arguments[i];
265
266 if(c == ' '){
267 last_space = i;
268 }
269 else if(c == ',' && !skip_comma){
270 std::string name(
271 arguments + last_space + 1, i - last_space - 1
272 );
273 args.push_back(name);
274 }
275 else if(c == '<'){
276 skip_comma++;
277 }
278 else if(c == '>'){
279 skip_comma--;
280 }
281 }
282
283 std::string last_argument(
284 arguments + last_space + 1, std::strlen(arguments) - last_space - 2
285 );
286 args.push_back(last_argument);
287
288 return args;
289}
290
291struct signature_argument_inserter
292{

Callers 1

Calls 1

push_backMethod · 0.80

Tested by

no test coverage detected