Extracts the flag name from a potential token. This function only looks for a '=', to split the flag name from the value for long-form flags. Returns the name of the flag, prefixed with the hyphen(s).
| 38 | // This function only looks for a '=', to split the flag name from the value for |
| 39 | // long-form flags. Returns the name of the flag, prefixed with the hyphen(s). |
| 40 | inline std::string get_flag_name(const std::string& flag, bool is_short_flag) { |
| 41 | if (is_short_flag) { |
| 42 | return flag; |
| 43 | } |
| 44 | |
| 45 | size_t equal_index = flag.find('='); |
| 46 | if (equal_index == std::string::npos) { |
| 47 | return flag; |
| 48 | } |
| 49 | return flag.substr(0, equal_index); |
| 50 | } |
| 51 | |
| 52 | // Parse a boolean flag. Returns `true` if the parsing succeeded, `false` |
| 53 | // otherwise. |