mirror of
https://github.com/KeqingMoe/argparse.git
synced 2025-07-04 07:04:39 +00:00
Add ways to substitute strtof/strtod/strtold with custom functions
The standard strtof/strtod/strtold are by default locale-aware. There are a number of situations where we'd rather want to be able to use locale-independent parsing functions. This can be done by setting the ARGPARSE_CUSTOM_STRTOF/ARGPARSE_CUSTOM_STRTOD/ARGPARSE_CUSTOM_STRTOLD macros to the appropriate value.
This commit is contained in:
parent
20f0196321
commit
c1fb3c0005
@ -58,6 +58,18 @@ SOFTWARE.
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef ARGPARSE_CUSTOM_STRTOF
|
||||||
|
#define ARGPARSE_CUSTOM_STRTOF strtof
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef ARGPARSE_CUSTOM_STRTOD
|
||||||
|
#define ARGPARSE_CUSTOM_STRTOD strtod
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef ARGPARSE_CUSTOM_STRTOLD
|
||||||
|
#define ARGPARSE_CUSTOM_STRTOLD strtold
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace argparse {
|
namespace argparse {
|
||||||
|
|
||||||
namespace details { // namespace for helper methods
|
namespace details { // namespace for helper methods
|
||||||
@ -347,9 +359,10 @@ template <class T> struct parse_number<T> {
|
|||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
template <class T> inline const auto generic_strtod = nullptr;
|
template <class T> inline const auto generic_strtod = nullptr;
|
||||||
template <> inline const auto generic_strtod<float> = strtof;
|
template <> inline const auto generic_strtod<float> = ARGPARSE_CUSTOM_STRTOF;
|
||||||
template <> inline const auto generic_strtod<double> = strtod;
|
template <> inline const auto generic_strtod<double> = ARGPARSE_CUSTOM_STRTOD;
|
||||||
template <> inline const auto generic_strtod<long double> = strtold;
|
template <>
|
||||||
|
inline const auto generic_strtod<long double> = ARGPARSE_CUSTOM_STRTOLD;
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user