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

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

[Wesnoth-cvs-commits] wesnoth/src tstring.cpp tstring.hpp


From: Guillaume Melquiond
Subject: [Wesnoth-cvs-commits] wesnoth/src tstring.cpp tstring.hpp
Date: Sat, 14 May 2005 04:56:14 -0400

CVSROOT:        /cvsroot/wesnoth
Module name:    wesnoth
Branch:         
Changes by:     Guillaume Melquiond <address@hidden>    05/05/14 08:56:14

Modified files:
        src            : tstring.cpp tstring.hpp 

Log message:
        Remove code duplication between + and +=. Detect when untranslatable 
parts are concatened, so that the useless yet costly break is removed.

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/tstring.cpp.diff?tr1=1.9&tr2=1.10&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/tstring.hpp.diff?tr1=1.7&tr2=1.8&r1=text&r2=text

Patches:
Index: wesnoth/src/tstring.cpp
diff -u wesnoth/src/tstring.cpp:1.9 wesnoth/src/tstring.cpp:1.10
--- wesnoth/src/tstring.cpp:1.9 Tue May 10 22:15:57 2005
+++ wesnoth/src/tstring.cpp     Sat May 14 08:56:13 2005
@@ -1,6 +1,7 @@
-/* $Id: tstring.cpp,v 1.9 2005/05/10 22:15:57 Sirp Exp $ */
+/* $Id: tstring.cpp,v 1.10 2005/05/14 08:56:13 silene Exp $ */
 /*
    Copyright (C) 2004 by Philippe Plantier <address@hidden>
+   Copyright (C) 2005 by Guillaume Melquiond <address@hidden>
    Part of the Battle for Wesnoth Project http://www.wesnoth.org
 
    This program is free software; you can redistribute it and/or modify
@@ -177,6 +178,7 @@
 
 t_string::t_string(const t_string& string) :
        translatable_(string.translatable_),
+       last_untranslatable_(string.last_untranslatable_),
        value_(string.value_),
        translated_value_(string.translated_value_)
 {
@@ -190,6 +192,7 @@
 
 t_string::t_string(const std::string& string, const std::string& textdomain) :
        translatable_(true),
+       last_untranslatable_(false),
        value_(1, ID_TRANSLATABLE_PART)
 {
        std::map<std::string, unsigned int>::const_iterator idi = 
textdomain_to_id.find(textdomain);
@@ -214,10 +217,6 @@
 {
 }
 
-t_string::~t_string()
-{
-}
-
 t_string t_string::from_serialized(const std::string& string)
 {
        t_string orig(string);
@@ -270,6 +269,7 @@
 {
        value_ = string.value_;
        translatable_ = string.translatable_;
+       last_untranslatable_ = string.last_untranslatable_;
        translated_value_ = string.translated_value_;
 
        return *this;
@@ -310,86 +310,53 @@
 
 t_string t_string::operator+(const t_string& string) const
 {
-       t_string res;
-
-       if(translatable_ || string.translatable_) {
-               res.translatable_ = true;
-               if(translatable_) {
-                       res.value_ += value_;
-               } else {
-                       if (!value_.empty()) {
-                               res.value_ += UNTRANSLATABLE_PART;
-                               res.value_ += value_;
-                       }
-               }
-               if(string.translatable_) {
-                       res.value_ += string.value_;
-               } else {
-                       if (!string.empty()) {
-                               res.value_ += UNTRANSLATABLE_PART;
-                               res.value_ += string.value_;
-                       }
-               }
-       } else {
-               res.value_ = value_ + string.value_;
-       }
-
+       t_string res(*this);
+       res += string;
        return res;
 }
 
 t_string t_string::operator+(const std::string& string) const
 {
-       t_string res;
-
-       if(translatable_) {
-               res.translatable_ = true;
-               res.value_ = value_;
-               if (!string.empty()) {
-                       res.value_ += UNTRANSLATABLE_PART;
-                       res.value_ += string;
-               }
-       } else {
-               res.value_ = value_ + string;
-       }
-
+       t_string res(*this);
+       res += string;
        return res;
 }
 
 t_string t_string::operator+(const char* string) const
 {
-       t_string res;
-
-       if(translatable_) {
-               res.translatable_ = true;
-               res.value_ = value_;
-               if (string[0] != 0) {
-                       res.value_ += UNTRANSLATABLE_PART;
-                       res.value_ += string;
-               }
-       } else {
-               res.value_ = value_ + string;
-       }
-
+       t_string res(*this);
+       res += string;
        return res;
 }
 
 t_string& t_string::operator+=(const t_string& string)
 {
+       if (string.value_.empty())
+               return *this;
+       if (value_.empty()) {
+               *this = string;
+               return *this;
+       }
+
        if(translatable_ || string.translatable_) {
                if(!translatable_) {
-                       if (!value_.empty()) {
-                               value_ = UNTRANSLATABLE_PART + value_;
-                       }
+                       value_ = UNTRANSLATABLE_PART + value_;
                        translatable_ = true;
+                       last_untranslatable_ = true;
                } else
                        translated_value_ = "";
                if(string.translatable_) {
-                       value_ += string.value_;
+                       if (last_untranslatable_ && string.value_[0] == 
UNTRANSLATABLE_PART)
+                               value_.append(string.value_, 1, 
string.value_.size() - 1);
+                       else
+                               value_ += string.value_;
+                       last_untranslatable_ = string.last_untranslatable_;
                } else {
-                       if (!string.value_.empty()) {
+                       if (!last_untranslatable_) {
                                value_ += UNTRANSLATABLE_PART;
-                               value_ += string.value_;
+                               last_untranslatable_ = true;
                        }
+                       value_ += string.value_;
                }
        } else {
                value_ += string.value_;
@@ -400,12 +367,20 @@
 
 t_string& t_string::operator+=(const std::string& string)
 {
+       if (string.empty())
+               return *this;
+       if (value_.empty()) {
+               *this = string;
+               return *this;
+       }
+
        if(translatable_) {
-               if (!string.empty()) {
+               if (!last_untranslatable_) {
                        value_ += UNTRANSLATABLE_PART;
-                       value_ += string;
-               } else
-                       translated_value_ = "";
+                       last_untranslatable_ = true;
+               }
+               value_ += string;
+               translated_value_ = "";
        } else {
                value_ += string;
        }
@@ -415,12 +390,20 @@
 
 t_string& t_string::operator+=(const char* string) 
 {
+       if (string[0] == 0)
+               return *this;
+       if (value_.empty()) {
+               *this = string;
+               return *this;
+       }
+
        if(translatable_) {
-               if (string[0] != 0) {
+               if (!last_untranslatable_) {
                        value_ += UNTRANSLATABLE_PART;
-                       value_ += string;
-               } else
-                       translated_value_ = "";
+                       last_untranslatable_ = true;
+               }
+               value_ += string;
+               translated_value_ = "";
        } else {
                value_ += string;
        }
Index: wesnoth/src/tstring.hpp
diff -u wesnoth/src/tstring.hpp:1.7 wesnoth/src/tstring.hpp:1.8
--- wesnoth/src/tstring.hpp:1.7 Tue May 10 22:15:57 2005
+++ wesnoth/src/tstring.hpp     Sat May 14 08:56:13 2005
@@ -1,4 +1,4 @@
-/* $Id: tstring.hpp,v 1.7 2005/05/10 22:15:57 Sirp Exp $ */
+/* $Id: tstring.hpp,v 1.8 2005/05/14 08:56:13 silene Exp $ */
 /*
    Copyright (C) 2004 by Philippe Plantier <address@hidden>
    Part of the Battle for Wesnoth Project http://www.wesnoth.org
@@ -49,7 +49,6 @@
        t_string(const std::string& string);
        t_string(const std::string& string, const std::string& textdomain);
        t_string(const char* string);
-       ~t_string();
 
        static t_string from_serialized(const std::string& string);
        std::string to_serialized() const;
@@ -86,7 +85,7 @@
 
        static void add_textdomain(const std::string& name, const std::string& 
path);
 private:
-       bool translatable_;
+       bool translatable_, last_untranslatable_;
        std::string value_;
        mutable std::string translated_value_;
 };




reply via email to

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