Output the extracted number from wxString::ToXXX() even if it returns false.

After the changes in r50710 wxString numeric conversion functions didn't
update their output parameter any more if the conversion failed because not
entire string was converted. This was incompatible with the old behaviour
which some existing code did rely on, so restore it and now always return the
number which was extracted from the beginning of the string if we found
anything at all, even if the function returns false.

Add unit test for the correct behaviour and updated the documentation.

Closes #11126.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@61786 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2009-08-30 17:25:19 +00:00
parent 4329eae943
commit 69d31e3130
3 changed files with 38 additions and 16 deletions

View File

@@ -602,6 +602,17 @@ void StringTestCase::ToLong()
if ( ld.IsOk() )
CPPUNIT_ASSERT_EQUAL( ld.LValue(), l );
}
// special case: check that the output is not modified if the parsing
// failed completely
l = 17;
CPPUNIT_ASSERT( !wxString("foo").ToLong(&l) );
CPPUNIT_ASSERT_EQUAL( 17, l );
// also check that it is modified if we did parse something successfully in
// the beginning of the string
CPPUNIT_ASSERT( !wxString("9 cats").ToLong(&l) );
CPPUNIT_ASSERT_EQUAL( 9, l );
}
void StringTestCase::ToULong()