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

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

[Wesnoth-cvs-commits] wesnoth/src help.cpp serialization/string_utils...


From: Philippe Plantier
Subject: [Wesnoth-cvs-commits] wesnoth/src help.cpp serialization/string_utils...
Date: Sun, 24 Apr 2005 07:58:05 -0400

CVSROOT:        /cvsroot/wesnoth
Module name:    wesnoth
Branch:         
Changes by:     Philippe Plantier <address@hidden>      05/04/24 11:58:04

Modified files:
        src            : help.cpp 
        src/serialization: string_utils.cpp string_utils.hpp 

Log message:
        * Removed the capitalization functions from help.cpp, and put them in
        string_utils.cpp
        
        * Made them use toupper on MacOSX, instead of towupper

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/help.cpp.diff?tr1=1.91&tr2=1.92&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/serialization/string_utils.cpp.diff?tr1=1.19&tr2=1.20&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/serialization/string_utils.hpp.diff?tr1=1.12&tr2=1.13&r1=text&r2=text

Patches:
Index: wesnoth/src/help.cpp
diff -u wesnoth/src/help.cpp:1.91 wesnoth/src/help.cpp:1.92
--- wesnoth/src/help.cpp:1.91   Sat Apr 16 19:43:47 2005
+++ wesnoth/src/help.cpp        Sun Apr 24 11:58:04 2005
@@ -483,9 +483,6 @@
 /// Return a lowercase copy of s.
 std::string to_lower(const std::string &s);
 
-/// Return a copy of s with the first letter capitalized.
-std::string cap(const std::string &s);
-
 /// Prepend all chars with meaning inside attributes with a backslash.
 std::string escape(const std::string &s);
 
@@ -980,7 +977,7 @@
                                if (special != "") {
                                        if (checked_specials.find(special) == 
checked_specials.end()) {
                                                std::string lang_special = 
gettext(special.c_str());
-                                               lang_special = 
cap(lang_special);
+                                               lang_special = 
utils::capitalize(lang_special);
                                                std::string description
                                                        = 
string_table["weapon_special_" + special + "_description"];
                                                const size_t colon_pos = 
description.find(':');
@@ -1018,7 +1015,7 @@
                                 it != type.abilities().end(); it++) {
                                if (checked_abilities.find(*it) == 
checked_abilities.end()) {
                                        const std::string id = "ability_" + *it;
-                                       std::string lang_ability = 
cap(string_table[id]);
+                                       std::string lang_ability = 
utils::capitalize(string_table[id]);
                                        std::string description = 
string_table[*it + "_description"];
                                        const size_t colon_pos = 
description.find(':');
                                        if (colon_pos != std::string::npos) {
@@ -1115,7 +1112,7 @@
                std::vector<attack_type> attacks = type_.attacks();
                if (!attacks.empty()) {
                        // Print headers for the table.
-                       ss << "\n\n<header>text='" << escape(cap(_("attacks")))
+                       ss << "\n\n<header>text='" << 
escape(utils::capitalize(_("attacks")))
                           << "'</header>\n\n";
                        table_spec table;
 
@@ -1123,7 +1120,7 @@
                        // Dummy element, icons are below.
                        first_row.push_back(item("", 0));
                        first_row.push_back(item(bold(_("Name")),
-                                                
font::line_width(cap(_("Name")),
+                                                
font::line_width(utils::capitalize(_("Name")),
                                                                  
normal_font_size,
                                                                  
TTF_STYLE_BOLD)));
                        first_row.push_back(item(bold(_("Type")),
@@ -2603,17 +2600,6 @@
        return lower_string;
 }
 
-std::string cap(const std::string &s)
-{
-       if (s.size() > 0) {
-               utils::utf8_iterator itor(s);
-               std::string res = utils::wchar_to_string(towupper(*itor));
-               res.append(itor.substr().second, s.end());
-               return res;
-       }
-       return s;
-}
-       
 std::string escape(const std::string &s)
 {
        std::string res = s;
Index: wesnoth/src/serialization/string_utils.cpp
diff -u wesnoth/src/serialization/string_utils.cpp:1.19 
wesnoth/src/serialization/string_utils.cpp:1.20
--- wesnoth/src/serialization/string_utils.cpp:1.19     Wed Apr 13 20:51:32 2005
+++ wesnoth/src/serialization/string_utils.cpp  Sun Apr 24 11:58:04 2005
@@ -1,4 +1,4 @@
-/* $Id: string_utils.cpp,v 1.19 2005/04/13 20:51:32 ydirson Exp $ */
+/* $Id: string_utils.cpp,v 1.20 2005/04/24 11:58:04 gruikya Exp $ */
 /*
    Copyright (C) 2003 by David White <address@hidden>
    Copyright (C) 2005 by Guillaume Melquiond <address@hidden>
@@ -483,7 +483,8 @@
        }
 }
 
-std::string wchar_to_string(const wchar_t c) {
+std::string wchar_to_string(const wchar_t c) 
+{
        wide_string s;
        s.push_back(c);
        return wstring_to_string(s);
@@ -553,9 +554,75 @@
        return dst;
 }
 
+utf8_string capitalize(const utf8_string& s)
+{
+       if(s.size() > 0) {
+               utf8_iterator itor(s);
+#ifdef __APPLE__
+               // FIXME: Should we support towupper on recent OSX platforms?
+               wchar_t uchar = *itor;
+               if(uchar < 256)
+                       uchar = toupper(uchar);
+               std::string res = utils::wchar_to_string(uchar);
+#else
+               std::string res = utils::wchar_to_string(towupper(*itor));
+#endif
+               res.append(itor.substr().second, s.end());
+               return res;
+       }
+       return s;
+}
+
+utf8_string uppercase(const utf8_string& s)
+{
+       if(s.size() > 0) {
+               utf8_iterator itor(s);
+               std::string res;
+
+               for(;itor != utf8_iterator::end(s); ++itor) {
+#ifdef __APPLE__
+                       // FIXME: Should we support towupper on recent OSX 
platforms?
+                       wchar_t uchar = *itor;
+                       if(uchar < 256)
+                               uchar = toupper(uchar);
+                       res += utils::wchar_to_string(uchar);
+#else
+                       res += utils::wchar_to_string(towupper(*itor));
+#endif
+               }
+
+               return res;
+       }
+       return s;
+}
+
+utf8_string lowercase(const utf8_string& s)
+{
+       if(s.size() > 0) {
+               utf8_iterator itor(s);
+               std::string res;
+
+               for(;itor != utf8_iterator::end(s); ++itor) {
+#ifdef __APPLE__
+                       // FIXME: Should we support towupper on recent OSX 
platforms?
+                       wchar_t uchar = *itor;
+                       if(uchar < 256)
+                               uchar = tolower(uchar);
+                       res += utils::wchar_to_string(uchar);
+#else
+                       res += utils::wchar_to_string(towlower(*itor));
+#endif
+               }
+
+               res.append(itor.substr().second, s.end());
+               return res;
+       }
+       return s;
+}
+
 }
 
-std::string vgettext (const char *msgid, const utils::string_map& symbols)
+std::string vgettext(const char *msgid, const utils::string_map& symbols)
 {
        const std::string orig(_(msgid));
        const std::string msg = utils::interpolate_variables_into_string(orig, 
&symbols);
Index: wesnoth/src/serialization/string_utils.hpp
diff -u wesnoth/src/serialization/string_utils.hpp:1.12 
wesnoth/src/serialization/string_utils.hpp:1.13
--- wesnoth/src/serialization/string_utils.hpp:1.12     Tue Apr 12 22:03:42 2005
+++ wesnoth/src/serialization/string_utils.hpp  Sun Apr 24 11:58:04 2005
@@ -1,4 +1,4 @@
-/* $Id: string_utils.hpp,v 1.12 2005/04/12 22:03:42 ydirson Exp $ */
+/* $Id: string_utils.hpp,v 1.13 2005/04/24 11:58:04 gruikya Exp $ */
 /*
    Copyright (C) 2003 by David White <address@hidden>
    Copyright (C) 2005 by Guillaume Melquiond <address@hidden>
@@ -105,6 +105,13 @@
 ucs2_string utf8_string_to_ucs2_string(const utf8_string& src);
 utf8_string ucs2_string_to_utf8_string(const ucs2_string& src);
 
+/** Returns a version of the string with the first letter capitalized */
+utf8_string capitalize(const utf8_string&);
+/** Returns an uppercased version of the string */
+utf8_string uppercase(const utf8_string&);
+/** Returns a lowercased version of the string */
+utf8_string lowercase(const utf8_string&);
+
 }
 
 // handy wrapper around interpolate_variables_into_string and gettext




reply via email to

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