From be551a1b3c324dc96750cf992b6a5784e2b92ec7 Mon Sep 17 00:00:00 2001 From: Pjotr Prins Date: Sat, 25 Aug 2018 11:32:46 +0000 Subject: Number format checking in strict mode. Also fixes #149 --- src/debug.h | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/debug.h') diff --git a/src/debug.h b/src/debug.h index ced8e72..b08d75d 100644 --- a/src/debug.h +++ b/src/debug.h @@ -147,6 +147,12 @@ inline void __enforce_fail(const char *__assertion, const char *__file, ? __ASSERT_VOID_CAST(0) \ : __enforce_fail((msg).c_str(), __FILE__, __LINE__, __SHOW_FUNC)) +#define enforce_is_int(s) \ + enforce_str(std::regex_match(s, std::regex("^[-+]?[0-9]+$")),s + " not an integer") + +#define enforce_is_float(s) \ + enforce_str(std::regex_match(s, std::regex("^[-+]?[0-9]*\\.?[0-9]+([eE][-+]?[0-9]+)?$")),s + " not a float") + // Helpers to create a unique varname per MACRO #define COMBINE1(X, Y) X##Y #define COMBINE(X, Y) COMBINE1(X, Y) -- cgit v1.2.3