From d71fa6fb2e2421b9d8deb826d60d5d8636665d91 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Thu, 27 Jan 2000 16:47:57 +0000 Subject: [PATCH] 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 --- samples/console/console.cpp | 55 +++++++++++++++++++++++++++++++++++-- src/common/string.cpp | 2 +- 2 files changed, 53 insertions(+), 4 deletions(-) diff --git a/samples/console/console.cpp b/samples/console/console.cpp index 80d7eb5be0..287019242b 100644 --- a/samples/console/console.cpp +++ b/samples/console/console.cpp @@ -32,11 +32,11 @@ //#define TEST_ARRAYS //#define TEST_CMDLINE //#define TEST_DIR -#define TEST_EXECUTE +//#define TEST_EXECUTE //#define TEST_LOG //#define TEST_LONGLONG //#define TEST_MIME -//#define TEST_STRINGS +#define TEST_STRINGS //#define TEST_THREADS //#define TEST_TIME @@ -1778,6 +1778,54 @@ static void TestStringFormat() 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 // ---------------------------------------------------------------------------- @@ -1840,8 +1888,9 @@ int main(int argc, char **argv) if ( 0 ) { TestStringSub(); + TestStringFormat(); } - TestStringFormat(); + TestStringFind(); #endif // TEST_STRINGS #ifdef TEST_ARRAYS diff --git a/src/common/string.cpp b/src/common/string.cpp index df8587fe66..efe9a4e186 100644 --- a/src/common/string.cpp +++ b/src/common/string.cpp @@ -1534,7 +1534,7 @@ size_t wxString::find(const wxString& str, size_t nStart) const #if !defined(__VISUALC__) || defined(__WIN32__) 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 -- 2.45.2