Using String instead of std::string in some places can cause regex::match syntax errors.

This commit is contained in:
RonxBulld 2021-04-25 01:12:56 +08:00
parent 6e0870addd
commit fc167a0972

View File

@ -533,18 +533,18 @@ namespace cxxopts
{ {
struct IntegerDesc struct IntegerDesc
{ {
String negative = ""; std::string negative = "";
String base = ""; std::string base = "";
String value = ""; std::string value = "";
}; };
struct ArguDesc { struct ArguDesc {
String arg_name = ""; std::string arg_name = "";
bool grouping = false; bool grouping = false;
bool set_value = false; bool set_value = false;
String value = ""; std::string value = "";
}; };
#ifdef NO_REGEX #ifdef NO_REGEX
inline IntegerDesc SplitInteger(const String &text) inline IntegerDesc SplitInteger(const std::string &text)
{ {
if (text.empty()) if (text.empty())
{ {
@ -573,7 +573,7 @@ namespace cxxopts
return desc; return desc;
} }
inline bool IsTrueText(const String &text) inline bool IsTrueText(const std::string &text)
{ {
const char *pdata = text.c_str(); const char *pdata = text.c_str();
if (*pdata == 't' || *pdata == 'T') if (*pdata == 't' || *pdata == 'T')
@ -591,7 +591,7 @@ namespace cxxopts
return false; return false;
} }
inline bool IsFalseText(const String &text) inline bool IsFalseText(const std::string &text)
{ {
const char *pdata = text.c_str(); const char *pdata = text.c_str();
if (*pdata == 'f' || *pdata == 'F') if (*pdata == 'f' || *pdata == 'F')
@ -609,9 +609,9 @@ namespace cxxopts
return false; return false;
} }
inline std::pair<String, String> SplitSwitchDef(const String &text) inline std::pair<std::string, std::string> SplitSwitchDef(const std::string &text)
{ {
String short_sw, long_sw; std::string short_sw, long_sw;
const char *pdata = text.c_str(); const char *pdata = text.c_str();
if (isalnum(*pdata) && *(pdata + 1) == ',') { if (isalnum(*pdata) && *(pdata + 1) == ',') {
short_sw = String(1, *pdata); short_sw = String(1, *pdata);
@ -702,7 +702,7 @@ namespace cxxopts
} // namespace } // namespace
inline IntegerDesc SplitInteger(const String &text) inline IntegerDesc SplitInteger(const std::string &text)
{ {
std::smatch match; std::smatch match;
std::regex_match(text, match, integer_pattern); std::regex_match(text, match, integer_pattern);
@ -727,21 +727,21 @@ namespace cxxopts
return desc; return desc;
} }
inline bool IsTrueText(const String &text) inline bool IsTrueText(const std::string &text)
{ {
std::smatch result; std::smatch result;
std::regex_match(text, result, truthy_pattern); std::regex_match(text, result, truthy_pattern);
return !result.empty(); return !result.empty();
} }
inline bool IsFalseText(const String &text) inline bool IsFalseText(const std::string &text)
{ {
std::smatch result; std::smatch result;
std::regex_match(text, result, falsy_pattern); std::regex_match(text, result, falsy_pattern);
return !result.empty(); return !result.empty();
} }
inline std::pair<String, String> SplitSwitchDef(const String &text) inline std::pair<std::string, std::string> SplitSwitchDef(const std::string &text)
{ {
std::match_results<const char*> result; std::match_results<const char*> result;
std::regex_match(text.c_str(), result, option_specifier); std::regex_match(text.c_str(), result, option_specifier);
@ -750,10 +750,10 @@ namespace cxxopts
throw_or_mimic<invalid_option_format_error>(text); throw_or_mimic<invalid_option_format_error>(text);
} }
const String& short_sw = result[2]; const std::string& short_sw = result[2];
const String& long_sw = result[3]; const std::string& long_sw = result[3];
return std::pair<String, String>(short_sw, long_sw); return std::pair<std::string, std::string>(short_sw, long_sw);
} }
inline ArguDesc ParseArgument(const char *arg, bool &matched) inline ArguDesc ParseArgument(const char *arg, bool &matched)
@ -852,9 +852,9 @@ namespace cxxopts
using US = typename std::make_unsigned<T>::type; using US = typename std::make_unsigned<T>::type;
constexpr bool is_signed = std::numeric_limits<T>::is_signed; constexpr bool is_signed = std::numeric_limits<T>::is_signed;
const bool negative = int_desc.negative.length() > 0; const bool negative = int_desc.negative.length() > 0;
const uint8_t base = int_desc.base.length() > 0 ? 16 : 10; const uint8_t base = int_desc.base.length() > 0 ? 16 : 10;
const String & value_match = int_desc.value; const std::string & value_match = int_desc.value;
US result = 0; US result = 0;
@ -2023,7 +2023,7 @@ OptionAdder::operator()
std::string arg_help std::string arg_help
) )
{ {
String short_sw, long_sw; std::string short_sw, long_sw;
std::tie(short_sw, long_sw) = values::parser_tool::SplitSwitchDef(opts); std::tie(short_sw, long_sw) = values::parser_tool::SplitSwitchDef(opts);
if (!short_sw.length() && !long_sw.length()) if (!short_sw.length() && !long_sw.length())
@ -2037,8 +2037,8 @@ OptionAdder::operator()
auto option_names = [] auto option_names = []
( (
const String &short_, const std::string &short_,
const String &long_ const std::string &long_
) )
{ {
if (long_.length() == 1) if (long_.length() == 1)