+
+// Match 'matchText' against 'matchAgainst', optionally constraining to
+// whole-word only.
+bool ctMatchString(const wxString& matchAgainst, const wxString& matchText, bool wholeWordOnly)
+{
+ // Fast operation if not matching against whole words only
+ if (!wholeWordOnly)
+ return (matchAgainst.Find(matchText) != wxNOT_FOUND);
+
+ wxString left(matchAgainst);
+ bool success = false;
+ int matchTextLen = (int) matchText.Length();
+ while (!success && !matchAgainst.IsEmpty())
+ {
+ int pos = left.Find(matchText);
+ if (pos == wxNOT_FOUND)
+ return false;
+
+ bool firstCharOK = false;
+ bool lastCharOK = false;
+ if (pos == 0 || !wxIsalnum(left[(size_t) (pos-1)]))
+ firstCharOK = true;
+
+ if (((pos + matchTextLen) == (int) left.Length()) || !wxIsalnum(left[(size_t) (pos + matchTextLen)]))
+ lastCharOK = true;
+
+ if (firstCharOK && lastCharOK)
+ success = true;
+
+ left = left.Mid(pos+1);
+ }
+ return success;
+}