Define wxStrtox() overloads taking nullptr

Instead of specializing wxStrtoxCharType and then testing whether endptr
is null, just define separate, and simpler, overloads of wxStrtox()
functions taking nullptr_t -- we can avoid the unnecessary test
completely in this case, as nullptr is, by definition, always null
anyhow.

Also add a test of using wxStrtol() with nullptr too.

This should fix the build with older gcc and MSVS versions.
This commit is contained in:
Vadim Zeitlin
2020-02-05 03:52:51 +01:00
parent 1650ea7030
commit 00cdab77c5
2 changed files with 32 additions and 12 deletions

View File

@@ -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
}
}