From: Ingo Ruhnke Date: Thu, 19 Nov 2009 23:15:48 +0000 (+0000) Subject: Added StringUtil class, some small cleanup in World X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=1446819b1295a5460898978afdff839514f12bce;p=supertux.git Added StringUtil class, some small cleanup in World SVN-Revision: 6060 --- diff --git a/src/supertux/menu/contrib_menu.cpp b/src/supertux/menu/contrib_menu.cpp index ada2e116f..8652ed06d 100644 --- a/src/supertux/menu/contrib_menu.cpp +++ b/src/supertux/menu/contrib_menu.cpp @@ -49,7 +49,7 @@ ContribMenu::ContribMenu() world->load(*it + "/info"); if (!world->hide_from_contribs) { - add_entry(i++, world->title); + add_entry(i++, world->get_title()); m_contrib_worlds.push_back(world.release()); } } diff --git a/src/supertux/menu/contrib_world_menu.cpp b/src/supertux/menu/contrib_world_menu.cpp index f7205f07e..bed2e9f26 100644 --- a/src/supertux/menu/contrib_world_menu.cpp +++ b/src/supertux/menu/contrib_world_menu.cpp @@ -27,7 +27,7 @@ ContribWorldMenu::ContribWorldMenu(const World& current_world) : m_current_world(current_world) { - add_label(m_current_world.title); + add_label(m_current_world.get_title()); add_hl(); for (unsigned int i = 0; i < m_current_world.get_num_levels(); ++i) diff --git a/src/supertux/world.cpp b/src/supertux/world.cpp index 02ac4a9d0..3b75fdf66 100644 --- a/src/supertux/world.cpp +++ b/src/supertux/world.cpp @@ -25,16 +25,9 @@ #include "supertux/world.hpp" #include "util/file_system.hpp" #include "util/reader.hpp" +#include "util/string_util.hpp" #include "worldmap/worldmap.hpp" -static bool has_suffix(const std::string& data, const std::string& suffix) -{ - if (data.length() >= suffix.length()) - return data.compare(data.length() - suffix.length(), suffix.length(), suffix) == 0; - else - return false; -} - World* World::current_ = NULL; World::World() : @@ -116,7 +109,7 @@ World::load(const std::string& filename) } for(const char* const* filename = files; *filename != 0; ++filename) { - if(has_suffix(*filename, ".stl")) { + if(StringUtil::has_suffix(*filename, ".stl")) { levels.push_back(path + *filename); } } @@ -254,4 +247,10 @@ World::get_basedir() const return basedir; } +const std::string& +World::get_title() const +{ + return title; +} + /* EOF */ diff --git a/src/supertux/world.hpp b/src/supertux/world.hpp index 9ea04c47c..8ab62629f 100644 --- a/src/supertux/world.hpp +++ b/src/supertux/world.hpp @@ -24,6 +24,15 @@ class World { public: + static World* current() + { + return current_; + } + +private: + static World* current_; + +public: World(); ~World(); @@ -33,15 +42,11 @@ public: void save_state(); void load_state(); - const std::string& get_level_filename(unsigned int i) const; unsigned int get_num_levels() const; + const std::string& get_level_filename(unsigned int i) const; const std::string& get_basedir() const; - - static World* current() - { - return current_; - } + const std::string& get_title() const; void run(); @@ -52,9 +57,6 @@ private: /// squirrel table that saves persistent state (about the world) HSQOBJECT state_table; HSQOBJECT world_thread; - static World* current_; - -public: std::string title; std::string description; diff --git a/src/util/string_util.cpp b/src/util/string_util.cpp new file mode 100644 index 000000000..b68193006 --- /dev/null +++ b/src/util/string_util.cpp @@ -0,0 +1,32 @@ +// SuperTux +// Copyright (C) 2009 Ingo Ruhnke +// +// 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 3 of the License, 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, see . + +#include "string_util.hpp" + +bool +StringUtil::has_suffix(const std::string& data, const std::string& suffix) +{ + if (data.length() >= suffix.length()) + { + return data.compare(data.length() - suffix.length(), suffix.length(), suffix) == 0; + } + else + { + return false; + } +} + +/* EOF */ diff --git a/src/util/string_util.hpp b/src/util/string_util.hpp new file mode 100644 index 000000000..d5f9ae13c --- /dev/null +++ b/src/util/string_util.hpp @@ -0,0 +1,30 @@ +// SuperTux +// Copyright (C) 2009 Ingo Ruhnke +// +// 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 3 of the License, 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, see . + +#ifndef HEADER_SUPERTUX_UTIL_STRING_UTIL_HPP +#define HEADER_SUPERTUX_UTIL_STRING_UTIL_HPP + +#include + +class StringUtil +{ +public: + static bool has_suffix(const std::string& data, const std::string& suffix); +}; + +#endif + +/* EOF */