Loading of recent character list simplified by using wxStringTokenizer

This commit is contained in:
Simon Rozman 2017-03-31 14:02:37 +02:00
parent ace7551281
commit 92374e57a8
2 changed files with 7 additions and 21 deletions

View File

@ -42,9 +42,10 @@
#include <wx/msgdlg.h> #include <wx/msgdlg.h>
#include <wx/persist.h> #include <wx/persist.h>
#include <wx/persist/toplevel.h> #include <wx/persist/toplevel.h>
#include <wx/socket.h>
#include <wx/tokenzr.h>
#include <wx/utils.h> #include <wx/utils.h>
#include <wx/valtext.h> #include <wx/valtext.h>
#include <wx/socket.h>
#include <WinStd/MSI.h> #include <WinStd/MSI.h>

View File

@ -840,26 +840,11 @@ bool wxPersistentZRColaCharSelect::Restore()
if (RestoreValue(wxT("recentChars2"), &str)) { if (RestoreValue(wxT("recentChars2"), &str)) {
// Native format found. // Native format found.
wxArrayString val; wxArrayString val;
wxString chr; for (wxStringTokenizer tok(str, wxT("|")); tok.HasMoreTokens(); ) {
wchar_t c = 0; wxString chr;
for (size_t i = 0, n = str.Length();; i++) { for (wxStringTokenizer tok_chr(tok.GetNextToken(), wxT("+")); tok_chr.HasMoreTokens(); )
if (i >= n) { chr += (wchar_t)_tcstoul(tok_chr.GetNextToken().c_str(), NULL, 16);
if (c) { chr += c; c = 0; } val.Add(chr);
if (!chr.IsEmpty()) { val.Add(chr); chr.Clear(); }
break;
} else {
wxStringCharType r = str[i];
if (wxT('0') <= r && r <= wxT('9')) c = (c << 4) | (r - wxT('0') );
else if (wxT('A') <= r && r <= wxT('F')) c = (c << 4) | (r - wxT('A') + 10);
else if (wxT('a') <= r && r <= wxT('f')) c = (c << 4) | (r - wxT('a') + 10);
else if (r == wxT('+')) {
if (c) { chr += c; c = 0; }
} else if (r == wxT('|')) {
if (c) { chr += c; c = 0; }
if (!chr.IsEmpty()) { val.Add(chr); chr.Clear(); }
} else
break;
}
} }
wnd->m_gridRecent->SetCharacters(val); wnd->m_gridRecent->SetCharacters(val);
} else if (RestoreValue(wxT("recentChars"), &str)) { } else if (RestoreValue(wxT("recentChars"), &str)) {