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

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

[Wesnoth-cvs-commits] wesnoth/src/serialization string_utils.hpp stri...


From: Jon Daniel
Subject: [Wesnoth-cvs-commits] wesnoth/src/serialization string_utils.hpp stri...
Date: Fri, 11 Mar 2005 23:42:59 -0500

CVSROOT:        /cvsroot/wesnoth
Module name:    wesnoth
Branch:         
Changes by:     Jon Daniel <address@hidden>     05/03/12 04:42:59

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

Log message:
        added ucs2_string_to_utf8_string and utf8_string_to_ucs2_string 
functions

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

Patches:
Index: wesnoth/src/serialization/string_utils.cpp
diff -u wesnoth/src/serialization/string_utils.cpp:1.9 
wesnoth/src/serialization/string_utils.cpp:1.10
--- wesnoth/src/serialization/string_utils.cpp:1.9      Thu Mar 10 20:59:20 2005
+++ wesnoth/src/serialization/string_utils.cpp  Sat Mar 12 04:42:59 2005
@@ -1,4 +1,4 @@
-/* $Id: string_utils.cpp,v 1.9 2005/03/10 20:59:20 ydirson Exp $ */
+/* $Id: string_utils.cpp,v 1.10 2005/03/12 04:42:59 j_daniel Exp $ */
 /*
    Copyright (C) 2003 by David White <address@hidden>
    Copyright (C) 2005 by Guillaume Melquiond <address@hidden>
@@ -490,4 +490,46 @@
        return res;
 }
 
+ucs2_string utf8_string_to_ucs2_string(const utf8_string& src)
+{
+       ucs2_string res;
+       try {
+               utf8_iterator i1(src);
+               const utf8_iterator i2(utf8_iterator::end(src));
+               while(i1 != i2) {
+                       push_back(res, *i1);
+                       ++i1;
+               }
+       }
+       catch(invalid_utf8_exception e) {
+               ERR_GENERAL << "Invalid UTF-8 string: \"" << src << "\"\n";
+               return res;
+       }
+       return res;
+}
+
+utf8_string ucs2_string_to_utf8_string(const ucs2_string& src)
+{
+       utf8_string dst;
+       dst.reserve(src.size());
+       ucs2_string::const_iterator itor = src.begin();
+       for(;itor != src.end(); ++itor) {
+               if(*itor < 0x0080) {
+                       dst.push_back(*itor);
+                       continue;
+               }
+               if(0x0080 <= *itor < 0x0800) {
+                       dst.push_back((*itor >> 6) | 0xC0);
+                       dst.push_back((*itor & 0x003F) | 0x80);
+                       continue;
+               }
+               if((0x0800 <= *itor < 0xD800) || (0xDFFF < *itor < 0xFFFE)) {
+                       dst.push_back((*itor >> 12) | 0xE0);
+                       dst.push_back(((*itor >> 6) & 0x003F) | 0x80);
+                       dst.push_back((*itor & 0x003F) | 0x80);
+               }
+       }
+       return dst;
+}
+
 }
Index: wesnoth/src/serialization/string_utils.hpp
diff -u wesnoth/src/serialization/string_utils.hpp:1.6 
wesnoth/src/serialization/string_utils.hpp:1.7
--- wesnoth/src/serialization/string_utils.hpp:1.6      Sun Mar  6 01:55:38 2005
+++ wesnoth/src/serialization/string_utils.hpp  Sat Mar 12 04:42:59 2005
@@ -1,4 +1,4 @@
-/* $Id: string_utils.hpp,v 1.6 2005/03/06 01:55:38 j_daniel Exp $ */
+/* $Id: string_utils.hpp,v 1.7 2005/03/12 04:42:59 j_daniel Exp $ */
 /*
    Copyright (C) 2003 by David White <address@hidden>
    Copyright (C) 2005 by Guillaume Melquiond <address@hidden>
@@ -90,6 +90,8 @@
 std::string wstring_to_string(const wide_string &);
 wide_string string_to_wstring(const std::string &);
 std::string wchar_to_string(const wchar_t);
+ucs2_string utf8_string_to_ucs2_string(const utf8_string& src);
+utf8_string ucs2_string_to_utf8_string(const ucs2_string& src);
 
 }
 




reply via email to

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