GTK: Remove the StringTokenizer class and move the functionality to tools.cpp

git-svn-id: https://svn.code.sf.net/p/vbam/code/trunk@990 a31d4220-a93d-0410-bf67-fe4944624d44
This commit is contained in:
bgk 2011-02-22 18:04:08 +00:00
parent c2e60fb564
commit c40af7cc74
6 changed files with 26 additions and 85 deletions

View File

@ -260,7 +260,6 @@ SET(SRC_GTK
src/gtk/screenarea.cpp src/gtk/screenarea.cpp
src/gtk/screenarea-cairo.cpp src/gtk/screenarea-cairo.cpp
src/gtk/screenarea-opengl.cpp src/gtk/screenarea-opengl.cpp
src/gtk/stringtokenizer.cpp
src/gtk/tools.cpp src/gtk/tools.cpp
src/gtk/window.cpp src/gtk/window.cpp
src/sdl/inputSDL.cpp src/sdl/inputSDL.cpp

View File

@ -17,11 +17,11 @@
// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "cheatlist.h" #include "cheatlist.h"
#include "tools.h"
#include <gtkmm/stock.h> #include <gtkmm/stock.h>
#include "intl.h" #include "intl.h"
#include "stringtokenizer.h"
#include <vector> #include <vector>
namespace VBA namespace VBA
@ -128,7 +128,7 @@ void CheatListDialog::vOnCheatAdd()
std::vector<Glib::ustring> tokens; std::vector<Glib::ustring> tokens;
Glib::RefPtr<Gtk::TextBuffer> code_buffer = poDialog->vGetCode(); Glib::RefPtr<Gtk::TextBuffer> code_buffer = poDialog->vGetCode();
StringTokenizer::tokenize(code_buffer->get_text(), tokens); vTokenize(code_buffer->get_text(), tokens);
for (std::vector<Glib::ustring>::iterator it = tokens.begin(); for (std::vector<Glib::ustring>::iterator it = tokens.begin();
it != tokens.end(); it != tokens.end();
@ -152,7 +152,7 @@ void CheatListDialog::vOnCheatAdd()
Glib::ustring sCode; Glib::ustring sCode;
Glib::ustring sPart = ""; Glib::ustring sPart = "";
StringTokenizer::tokenize(code_buffer->get_text(), tokens); vTokenize(code_buffer->get_text(), tokens);
for (std::vector<Glib::ustring>::iterator it = tokens.begin(); for (std::vector<Glib::ustring>::iterator it = tokens.begin();
it != tokens.end(); it != tokens.end();

View File

@ -1,44 +0,0 @@
// VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator.
// Copyright (C) 1999-2003 Forgotten
// Copyright (C) 2004 Forgotten and the VBA development team
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2, or(at your option)
// any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software Foundation,
// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "stringtokenizer.h"
namespace VBA
{
void StringTokenizer::tokenize(Glib::ustring source, std::vector<Glib::ustring>& tokens)
{
Glib::ustring delimiters = " \t\n\r";
// Skip delimiters at beginning.
Glib::ustring::size_type lastPos = source.find_first_not_of(delimiters, 0);
// Find first "non-delimiter".
Glib::ustring::size_type pos = source.find_first_of(delimiters, lastPos);
while (Glib::ustring::npos != pos || std:: string::npos != lastPos)
{
// Found a token, add it to the vector.
tokens.push_back(source.substr(lastPos, pos - lastPos));
// Skip delimiters. Note the "not_of"
lastPos = source.find_first_not_of(delimiters, pos);
// Find next "non-delimiter"
pos = source.find_first_of(delimiters, lastPos);
}
}
} // VBA namespace

View File

@ -1,37 +0,0 @@
// -*- C++ -*-
// VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator.
// Copyright (C) 1999-2003 Forgotten
// Copyright (C) 2004 Forgotten and the VBA development team
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2, or(at your option)
// any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software Foundation,
// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#ifndef __VBA_STRINGTOKENIZER_H__
#define __VBA_STRINGTOKENIZER_H__
#include <glibmm/ustring.h>
#include <vector>
namespace VBA
{
class StringTokenizer
{
public:
static void tokenize(Glib::ustring source, std::vector<Glib::ustring>& tokens);
};
} // VBA namespace
#endif

View File

@ -62,4 +62,24 @@ bool bHasSuffix(const Glib::ustring & _rsString,
return false; return false;
} }
void vTokenize(Glib::ustring source, std::vector<Glib::ustring>& tokens)
{
Glib::ustring delimiters = " \t\n\r";
// Skip delimiters at beginning.
Glib::ustring::size_type lastPos = source.find_first_not_of(delimiters, 0);
// Find first "non-delimiter".
Glib::ustring::size_type pos = source.find_first_of(delimiters, lastPos);
while (Glib::ustring::npos != pos || std:: string::npos != lastPos)
{
// Found a token, add it to the vector.
tokens.push_back(source.substr(lastPos, pos - lastPos));
// Skip delimiters. Note the "not_of"
lastPos = source.find_first_not_of(delimiters, pos);
// Find next "non-delimiter"
pos = source.find_first_of(delimiters, lastPos);
}
}
} // namespace VBA } // namespace VBA

View File

@ -21,6 +21,7 @@
#define __VBA_TOOLS_H__ #define __VBA_TOOLS_H__
#include <string> #include <string>
#include <vector>
#include <glibmm/ustring.h> #include <glibmm/ustring.h>
namespace VBA namespace VBA
@ -35,6 +36,8 @@ Glib::ustring sCutSuffix(const Glib::ustring & _rsString,
bool bHasSuffix(const Glib::ustring & _rsString, bool bHasSuffix(const Glib::ustring & _rsString,
const Glib::ustring & _rsSuffix, const Glib::ustring & _rsSuffix,
bool _bCaseSensitive = true); bool _bCaseSensitive = true);
void vTokenize(Glib::ustring source, std::vector<Glib::ustring>& tokens);
} }