Check if a string is a member of a list of strings and optionally ignore case or ignore underscores
| 364 | |
| 365 | /// Check if a string is a member of a list of strings and optionally ignore case or ignore underscores |
| 366 | inline std::ptrdiff_t find_member(std::string name, const std::vector<std::string> names, bool ignore_case = false, |
| 367 | bool ignore_underscore = false) { |
| 368 | auto it = std::end(names); |
| 369 | if (ignore_case) { |
| 370 | if (ignore_underscore) { |
| 371 | name = detail::to_lower(detail::remove_underscore(name)); |
| 372 | it = std::find_if(std::begin(names), std::end(names), [&name](std::string local_name) { |
| 373 | return detail::to_lower(detail::remove_underscore(local_name)) == name; |
| 374 | }); |
| 375 | } else { |
| 376 | name = detail::to_lower(name); |
| 377 | it = std::find_if(std::begin(names), std::end(names), |
| 378 | [&name](std::string local_name) { return detail::to_lower(local_name) == name; }); |
| 379 | } |
| 380 | |
| 381 | } else if (ignore_underscore) { |
| 382 | name = detail::remove_underscore(name); |
| 383 | it = std::find_if(std::begin(names), std::end(names), |
| 384 | [&name](std::string local_name) { return detail::remove_underscore(local_name) == name; }); |
| 385 | } else { |
| 386 | it = std::find(std::begin(names), std::end(names), name); |
| 387 | } |
| 388 | |
| 389 | return (it != std::end(names)) ? (it - std::begin(names)) : (-1); |
| 390 | } |
| 391 | |
| 392 | /// Find a trigger string and call a modify callable function that takes the current string and starting position of the |
| 393 | /// trigger and returns the position in the string to search for the next trigger string |
no test coverage detected