From b2b8cf2f50a449720874f43445e23d75b77dcc43 Mon Sep 17 00:00:00 2001 From: chrisps Date: Fri, 30 Sep 2022 07:00:07 -0700 Subject: [PATCH] Use selectany on msvc versions --- include/cxxopts.hpp | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/include/cxxopts.hpp b/include/cxxopts.hpp index 33851e1..5a57448 100644 --- a/include/cxxopts.hpp +++ b/include/cxxopts.hpp @@ -50,6 +50,13 @@ THE SOFTWARE. # define CXXOPTS_NO_REGEX true # endif #endif +#if defined(_MSC_VER) +#define CXXOPTS_LINKONCE_CONST __declspec(selectany) +#define CXXOPTS_LINKONCE __declspec(selectany) +#else +#define CXXOPTS_LINKONCE_CONST const +#define CXXOPTS_LINKONCE +#endif #ifndef CXXOPTS_NO_REGEX # include @@ -325,11 +332,11 @@ namespace cxxopts { namespace { #ifdef _WIN32 -const std::string LQUOTE("\'"); -const std::string RQUOTE("\'"); +CXXOPTS_LINKONCE_CONST std::string LQUOTE("\'"); +CXXOPTS_LINKONCE_CONST std::string RQUOTE("\'"); #else -const std::string LQUOTE("‘"); -const std::string RQUOTE("’"); +CXXOPTS_LINKONCE_CONST std::string LQUOTE("‘"); +CXXOPTS_LINKONCE_CONST std::string RQUOTE("’"); #endif } // namespace @@ -744,18 +751,22 @@ inline ArguDesc ParseArgument(const char *arg, bool &matched) #else // CXXOPTS_NO_REGEX namespace { - +CXXOPTS_LINKONCE std::basic_regex integer_pattern ("(-)?(0x)?([0-9a-zA-Z]+)|((0x)?0)"); +CXXOPTS_LINKONCE std::basic_regex truthy_pattern ("(t|T)(rue)?|1"); +CXXOPTS_LINKONCE std::basic_regex falsy_pattern ("(f|F)(alse)?|0"); - +CXXOPTS_LINKONCE std::basic_regex option_matcher ("--([[:alnum:]][-_[:alnum:]\\.]+)(=(.*))?|-([[:alnum:]].*)"); +CXXOPTS_LINKONCE std::basic_regex option_specifier ("([[:alnum:]][-_[:alnum:]\\.]*)(,[ ]*[[:alnum:]][-_[:alnum:]]*)*"); +CXXOPTS_LINKONCE std::basic_regex option_specifier_separator(", *"); } // namespace