diff --git a/include/wx/wxcrt.h b/include/wx/wxcrt.h index 97686b0221..ab9752db22 100644 --- a/include/wx/wxcrt.h +++ b/include/wx/wxcrt.h @@ -844,16 +844,6 @@ template<> struct wxStrtoxCharType return NULL; } }; -#ifdef wxHAS_NULLPTR_T -template<> struct wxStrtoxCharType -{ - typedef const char* Type; - static char** AsPointer(std::nullptr_t) - { - return nullptr; - } -}; -#endif template inline double wxStrtod(const wxString& nptr, T endptr) @@ -877,6 +867,25 @@ template inline double wxStrtod(const wxCStrData& nptr, T endptr) { return wxStrtod(nptr.AsString(), endptr); } +#ifdef wxHAS_NULLPTR_T + +inline double wxStrtod(const wxString& nptr, nullptr_t) + { return wxStrtod(nptr.wx_str(), static_cast(NULL)); }; +inline double wxStrtod(const wxCStrData& nptr, nullptr_t) + { return wxStrtod(nptr.AsString(), static_cast(NULL)); }; + +#define WX_STRTOX_DEFINE_NULLPTR_OVERLOADS(rettype, name) \ + inline rettype name(const wxString& nptr, nullptr_t, int base) \ + { return name(nptr.wx_str(), static_cast(NULL), \ + base); }; \ + inline rettype name(const wxCStrData& nptr, nullptr_t, int base) \ + { return name(nptr.AsString(), static_cast(NULL), \ + base); }; + +#else // !wxHAS_NULLPTR_T +#define WX_STRTOX_DEFINE_NULLPTR_OVERLOADS(rettype, name) +#endif // wxHAS_NULLPTR_T/!wxHAS_NULLPTR_T + #define WX_STRTOX_FUNC(rettype, name, implA, implW) \ /* see wxStrtod() above for explanation of this code: */ \ @@ -902,7 +911,8 @@ inline double wxStrtod(const wxCStrData& nptr, T endptr) } \ template \ inline rettype name(const wxCStrData& nptr, T endptr, int base) \ - { return name(nptr.AsString(), endptr, base); } + { return name(nptr.AsString(), endptr, base); } \ + WX_STRTOX_DEFINE_NULLPTR_OVERLOADS(rettype, name) WX_STRTOX_FUNC(long, wxStrtol, wxCRT_StrtolA, wxCRT_StrtolW) WX_STRTOX_FUNC(unsigned long, wxStrtoul, wxCRT_StrtoulA, wxCRT_StrtoulW) diff --git a/tests/strings/crt.cpp b/tests/strings/crt.cpp index 6d728f3cb8..170159b130 100644 --- a/tests/strings/crt.cpp +++ b/tests/strings/crt.cpp @@ -234,10 +234,11 @@ TEST_CASE("CRT::Strnlen", "[crt][strnlen]") CHECK( wxStrnlen(L"1234" L"\0" L"5678", 12) == 4 ); } -TEST_CASE("CRT::Strtod", "[crt][strtod]") +TEST_CASE("CRT::Strtox", "[crt][strtod][strtol]") { const wxString s = "123@"; const double d = 123.0; + const long l = 123; SECTION("char") { @@ -245,6 +246,10 @@ TEST_CASE("CRT::Strtod", "[crt][strtod]") CHECK( wxStrtod(s, &end) == d ); REQUIRE( end ); CHECK( *end == '@' ); + + CHECK( wxStrtol(s, &end, 10) == l ); + REQUIRE( end ); + CHECK( *end == '@' ); } SECTION("wchar_t") @@ -253,6 +258,10 @@ TEST_CASE("CRT::Strtod", "[crt][strtod]") CHECK( wxStrtod(s, &end) == d ); REQUIRE( end ); CHECK( *end == L'@' ); + + CHECK( wxStrtol(s, &end, 10) == l ); + REQUIRE( end ); + CHECK( *end == L'@' ); } SECTION("other") @@ -260,6 +269,7 @@ TEST_CASE("CRT::Strtod", "[crt][strtod]") CHECK( wxStrtod(s, 0) == d ); #ifdef wxHAS_NULLPTR_T CHECK( wxStrtod(s, nullptr) == d ); + CHECK( wxStrtol(s, nullptr, 10) == l ); #endif } }