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"]).
| 250 | // like: "(int a, const float b)", returns a vector containing the name |
| 251 | // of each argument (e.g. ["a", "b"]). |
| 252 | inline 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 | |
| 291 | struct signature_argument_inserter |
| 292 | { |
no test coverage detected