From c1fb3c0005971590e8cf7a195274a8945a71345d Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Tue, 12 Mar 2024 10:22:58 +0100 Subject: [PATCH] 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. --- include/argparse/argparse.hpp | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/include/argparse/argparse.hpp b/include/argparse/argparse.hpp index c41cdb1..c93c876 100644 --- a/include/argparse/argparse.hpp +++ b/include/argparse/argparse.hpp @@ -58,6 +58,18 @@ SOFTWARE. #include #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 details { // namespace for helper methods @@ -347,9 +359,10 @@ template struct parse_number { namespace { template inline const auto generic_strtod = nullptr; -template <> inline const auto generic_strtod = strtof; -template <> inline const auto generic_strtod = strtod; -template <> inline const auto generic_strtod = strtold; +template <> inline const auto generic_strtod = ARGPARSE_CUSTOM_STRTOF; +template <> inline const auto generic_strtod = ARGPARSE_CUSTOM_STRTOD; +template <> +inline const auto generic_strtod = ARGPARSE_CUSTOM_STRTOLD; } // namespace