wxString::find() now works again (was completely broken)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@5712 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -32,11 +32,11 @@
|
|||||||
//#define TEST_ARRAYS
|
//#define TEST_ARRAYS
|
||||||
//#define TEST_CMDLINE
|
//#define TEST_CMDLINE
|
||||||
//#define TEST_DIR
|
//#define TEST_DIR
|
||||||
#define TEST_EXECUTE
|
//#define TEST_EXECUTE
|
||||||
//#define TEST_LOG
|
//#define TEST_LOG
|
||||||
//#define TEST_LONGLONG
|
//#define TEST_LONGLONG
|
||||||
//#define TEST_MIME
|
//#define TEST_MIME
|
||||||
//#define TEST_STRINGS
|
#define TEST_STRINGS
|
||||||
//#define TEST_THREADS
|
//#define TEST_THREADS
|
||||||
//#define TEST_TIME
|
//#define TEST_TIME
|
||||||
|
|
||||||
@@ -1778,6 +1778,54 @@ static void TestStringFormat()
|
|||||||
puts("");
|
puts("");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// returns "not found" for npos, value for all others
|
||||||
|
static wxString PosToString(size_t res)
|
||||||
|
{
|
||||||
|
wxString s = res == wxString::npos ? wxString(_T("not found"))
|
||||||
|
: wxString::Format(_T("%u"), res);
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void TestStringFind()
|
||||||
|
{
|
||||||
|
puts("*** Testing wxString find() functions ***");
|
||||||
|
|
||||||
|
static const wxChar *strToFind = _T("ell");
|
||||||
|
static const struct StringFindTest
|
||||||
|
{
|
||||||
|
const wxChar *str;
|
||||||
|
size_t start,
|
||||||
|
result; // of searching "ell" in str
|
||||||
|
} findTestData[] =
|
||||||
|
{
|
||||||
|
{ _T("Well, hello world"), 0, 1 },
|
||||||
|
{ _T("Well, hello world"), 6, 7 },
|
||||||
|
{ _T("Well, hello world"), 9, wxString::npos },
|
||||||
|
};
|
||||||
|
|
||||||
|
for ( size_t n = 0; n < WXSIZEOF(findTestData); n++ )
|
||||||
|
{
|
||||||
|
const StringFindTest& ft = findTestData[n];
|
||||||
|
size_t res = wxString(ft.str).find(strToFind, ft.start);
|
||||||
|
|
||||||
|
printf(_T("Index of '%s' in '%s' starting from %u is %s "),
|
||||||
|
strToFind, ft.str, ft.start, PosToString(res).c_str());
|
||||||
|
|
||||||
|
size_t resTrue = ft.result;
|
||||||
|
if ( res == resTrue )
|
||||||
|
{
|
||||||
|
puts(_T("(ok)"));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
printf(_T("(ERROR: should be %s)\n"),
|
||||||
|
PosToString(resTrue).c_str());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
puts("");
|
||||||
|
}
|
||||||
|
|
||||||
#endif // TEST_STRINGS
|
#endif // TEST_STRINGS
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
@@ -1840,8 +1888,9 @@ int main(int argc, char **argv)
|
|||||||
if ( 0 )
|
if ( 0 )
|
||||||
{
|
{
|
||||||
TestStringSub();
|
TestStringSub();
|
||||||
}
|
|
||||||
TestStringFormat();
|
TestStringFormat();
|
||||||
|
}
|
||||||
|
TestStringFind();
|
||||||
#endif // TEST_STRINGS
|
#endif // TEST_STRINGS
|
||||||
|
|
||||||
#ifdef TEST_ARRAYS
|
#ifdef TEST_ARRAYS
|
||||||
|
@@ -1534,7 +1534,7 @@ size_t wxString::find(const wxString& str, size_t nStart) const
|
|||||||
#if !defined(__VISUALC__) || defined(__WIN32__)
|
#if !defined(__VISUALC__) || defined(__WIN32__)
|
||||||
size_t wxString::find(const wxChar* sz, size_t nStart, size_t n) const
|
size_t wxString::find(const wxChar* sz, size_t nStart, size_t n) const
|
||||||
{
|
{
|
||||||
return find(wxString(sz, n == npos ? 0 : n), nStart);
|
return find(wxString(sz, n), nStart);
|
||||||
}
|
}
|
||||||
#endif // VC++ 1.5
|
#endif // VC++ 1.5
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user