]> git.saurik.com Git - wxWidgets.git/commitdiff
wxString::find() now works again (was completely broken)
authorVadim Zeitlin <vadim@wxwidgets.org>
Thu, 27 Jan 2000 16:47:57 +0000 (16:47 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Thu, 27 Jan 2000 16:47:57 +0000 (16:47 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@5712 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

samples/console/console.cpp
src/common/string.cpp

index 80d7eb5be058f252bd2a154889ed667ac28ca4d1..287019242bf29dae82e37d956ec7f67c2c7538d3 100644 (file)
 //#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
index df8587fe66e93496c4a4d57cb4118ecea2ebf9e5..efe9a4e186e499c31a0f979635b2013d1cc907d5 100644 (file)
@@ -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