wesnoth-cvs-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Wesnoth-cvs-commits] wesnoth/src actions.cpp animated.hpp serializat...


From: Guillaume Melquiond
Subject: [Wesnoth-cvs-commits] wesnoth/src actions.cpp animated.hpp serializat...
Date: Sun, 20 Feb 2005 15:46:49 -0500

CVSROOT:        /cvsroot/wesnoth
Module name:    wesnoth
Branch:         
Changes by:     Guillaume Melquiond <address@hidden>    05/02/20 20:46:48

Modified files:
        src            : actions.cpp animated.hpp 
        src/serialization: string_utils.cpp 

Log message:
        Slowly going away from big config.cpp

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/actions.cpp.diff?tr1=1.190&tr2=1.191&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/animated.hpp.diff?tr1=1.4&tr2=1.5&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/serialization/string_utils.cpp.diff?tr1=1.1&tr2=1.2&r1=text&r2=text

Patches:
Index: wesnoth/src/actions.cpp
diff -u wesnoth/src/actions.cpp:1.190 wesnoth/src/actions.cpp:1.191
--- wesnoth/src/actions.cpp:1.190       Wed Feb  9 23:32:01 2005
+++ wesnoth/src/actions.cpp     Sun Feb 20 20:46:47 2005
@@ -1,4 +1,4 @@
-/* $Id: actions.cpp,v 1.190 2005/02/09 23:32:01 ydirson Exp $ */
+/* $Id: actions.cpp,v 1.191 2005/02/20 20:46:47 silene Exp $ */
 /*
    Copyright (C) 2003 by David White <address@hidden>
    Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net
@@ -33,6 +33,7 @@
 #include "unit_display.hpp"
 #include "util.hpp"
 #include "wassert.hpp"
+#include "serialization/string_utils.hpp"
 #include "widgets/menu.hpp"
 
 #include <cmath>
@@ -1764,7 +1765,7 @@
                                        msg << '\n' << _("(press $hotkey to 
continue)");
                                }
                        }
-                       const std::string message = 
config::interpolate_variables_into_string(msg.str(),&symbols);
+                       const std::string message = 
utils::interpolate_variables_into_string(msg.str(), &symbols);
 
                        
font::add_floating_label(message,font::SIZE_XLARGE,font::BAD_COLOUR,
                                                 
disp->map_area().w/2,disp->map_area().h/3,
Index: wesnoth/src/animated.hpp
diff -u wesnoth/src/animated.hpp:1.4 wesnoth/src/animated.hpp:1.5
--- wesnoth/src/animated.hpp:1.4        Wed Aug 25 02:59:50 2004
+++ wesnoth/src/animated.hpp    Sun Feb 20 20:46:47 2005
@@ -1,4 +1,4 @@
-/* $Id: animated.hpp,v 1.4 2004/08/25 02:59:50 Sirp Exp $ */
+/* $Id: animated.hpp,v 1.5 2005/02/20 20:46:47 silene Exp $ */
 /*
    Copyright (C) 2004 by Philippe Plantier <address@hidden>
    Part of the Battle for Wesnoth Project http://www.wesnoth.org
@@ -17,8 +17,8 @@
 #include <string>
 #include <vector>
 #include "SDL.h"
-#include "config.hpp"
 #include "util.hpp"
+#include "serialization/string_utils.hpp"
 
 template<typename T>
 class void_value
@@ -46,9 +46,6 @@
 
        animated(const std::string &cfg, const string_initializer& 
init=string_initializer());
 
-       // //if T can be constructed from a config&, you may use this 
constructor
-       //animated(const config& cfg, const std::string& tag);
-
        // Adds a void frame
        void add_frame(int start);
 
@@ -142,13 +139,13 @@
        start_ticks_(0),
        acceleration_(1)
 {
-       std::vector<std::string> items = config::split(cfg);
+       std::vector<std::string> items = utils::split(cfg);
 
        int current_time = 0;
 
        std::vector<std::string>::const_iterator itor = items.begin();
        for(; itor != items.end(); ++itor) {
-               const std::vector<std::string>& items = config::split(*itor, 
':');
+               const std::vector<std::string>& items = utils::split(*itor, 
':');
                std::string str;
                int time;
 
Index: wesnoth/src/serialization/string_utils.cpp
diff -u wesnoth/src/serialization/string_utils.cpp:1.1 
wesnoth/src/serialization/string_utils.cpp:1.2
--- wesnoth/src/serialization/string_utils.cpp:1.1      Sun Feb 20 19:22:31 2005
+++ wesnoth/src/serialization/string_utils.cpp  Sun Feb 20 20:46:48 2005
@@ -1,4 +1,4 @@
-/* $Id: string_utils.cpp,v 1.1 2005/02/20 19:22:31 silene Exp $ */
+/* $Id: string_utils.cpp,v 1.2 2005/02/20 20:46:48 silene Exp $ */
 /*
    Copyright (C) 2003 by David White <address@hidden>
    Copyright (C) 2005 by Guillaume Melquiond <address@hidden>
@@ -16,6 +16,42 @@
 
 #include "serialization/string_utils.hpp"
 
+namespace game_events {
+std::string const &get_variable_const(std::string const &varname);
+}
+
+namespace {
+
+bool not_id(char c)
+{
+       return !isdigit(c) && !isalpha(c) && c != '.' && c != '_';
+}
+
+void do_interpolation(std::string &res, size_t npos, utils::string_map const 
*m)
+{
+       const std::string::iterator i = std::find(res.begin() + npos, 
res.end(), '$');
+       if (i == res.end() || i + 1 == res.end())
+               return;
+
+       npos = i - res.begin();
+
+       const std::string::iterator end = std::find_if(i + 1, res.end(), 
not_id);
+
+       const std::string key(i + 1, end);
+       res.erase(i, end);
+
+       if (m != NULL) {
+               const utils::string_map::const_iterator itor = m->find(key);
+               if (itor != m->end())
+                       res.insert(npos,itor->second);
+       } else
+               res.insert(npos, game_events::get_variable_const(key));
+
+       do_interpolation(res,npos,m);
+}
+
+}
+
 namespace utils {
 
 bool isnewline(char c)
@@ -89,6 +125,17 @@
        return res;
 }
 
+std::string interpolate_variables_into_string(std::string const &str, 
string_map const *symbols)
+{
+       std::string res = str;
+       do_interpolation(res, 0, symbols);
+
+       //remove any pipes in the string, as they are used simply to seperate 
variables
+       res.erase(std::remove(res.begin(),res.end(),'|'),res.end());
+
+       return res;
+}
+
 
 
 }




reply via email to

[Prev in Thread] Current Thread [Next in Thread]