According to the docs, I should be able to use the "bracket expression" alpha. I thought it would be done like wxString::Matches("[:alpha:]"), but apparently I am mistaken.
Here is the code I am testing with:
Code: Select all
#include <iostream>
#include <wx/string.h>
using namespace std;
bool isAlphaOnly(wxChar c) {
if (!wxString(c).Matches("[:alpha:]")) return false;
return true;
}
bool isAlphaOnly(wxString s) {
cout << "Checking string \"" << s.c_str() << "\":\t";
for (wxChar c : s) {
if (!isAlphaOnly(c)) {
return false;
}
}
return true;
}
string toString(bool b) {
if (b) return "true";
else return "false";
}
int main(int argc, char** argv) {
wxString s1 = "HellowxWidets";
wxString s2 = "Hello wxWidgets";
wxString s3 = "HellowxWidgets!";
wxString s4 = "Hello8wxWidgets";
cout << "\nAlpha only:\n";
cout << toString(isAlphaOnly(s1)) << " (should be 'true')\n";
cout << toString(isAlphaOnly(s2)) << " (should be 'false')\n";
cout << toString(isAlphaOnly(s3)) << " (should be 'false')\n";
cout << toString(isAlphaOnly(s4)) << " (should be 'false')\n";
return 0;
}
--- Edit ---
Or maybe bracket expressions only work with the wxRegEx class?