gnash-commit
[Top][All Lists]
Advanced

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

[Gnash-commit] gnash/libbase utf8.cpp utf8.h


From: Benjamin Wolsey
Subject: [Gnash-commit] gnash/libbase utf8.cpp utf8.h
Date: Wed, 06 Feb 2008 15:21:34 +0000

CVSROOT:        /sources/gnash
Module name:    gnash
Changes by:     Benjamin Wolsey <bwy>   08/02/06 15:21:34

Modified files:
        libbase        : utf8.cpp utf8.h 

Log message:
        Need these too.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/gnash/libbase/utf8.cpp?cvsroot=gnash&r1=1.8&r2=1.9
http://cvs.savannah.gnu.org/viewcvs/gnash/libbase/utf8.h?cvsroot=gnash&r1=1.6&r2=1.7

Patches:
Index: utf8.cpp
===================================================================
RCS file: /sources/gnash/gnash/libbase/utf8.cpp,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -b -r1.8 -r1.9
--- utf8.cpp    5 Feb 2008 12:01:51 -0000       1.8
+++ utf8.cpp    6 Feb 2008 15:21:34 -0000       1.9
@@ -24,14 +24,28 @@
 #include "utf8.h"
 
 std::wstring
-utf8::decodeCanonicalString(const std::string& str)
+utf8::decodeCanonicalString(const std::string& str, int version)
 {
+       
        std::wstring wstr = L"";
        
        std::string::const_iterator it = str.begin();
-       while (boost::uint32_t code = utf8::decodeNextUnicodeCharacter(it))
+       
+       if (version > 5)
+       {
+               while (boost::uint32_t code = decodeNextUnicodeCharacter(it))
        {
-               wstr.push_back((wchar_t) code);
+                       wstr.push_back(static_cast<wchar_t>(code));
+               }
+       }
+       else
+       {
+               while (it != str.end())
+               {
+                       // This mangles UTF-8 (UCS4) strings, but is what is
+                       // wanted for SWF5.
+                       wstr.push_back(static_cast<unsigned char>(*it++));
+               }
        }
        
        return wstr;
@@ -39,21 +53,33 @@
 }
 
 std::string
-utf8::encodeCanonicalString(const std::wstring& wstr)
+utf8::encodeCanonicalString(const std::wstring& wstr, int version)
 {
+
        std::string str = "";
        
        std::wstring::const_iterator it = wstr.begin();
        while ( it != wstr.end())
        {
-               str.append(utf8::encodeUnicodeCharacter(*it++));
+               if (version > 5) str.append(encodeUnicodeCharacter(*it++));
+               else str.append(encodeLatin1Character(*it++));
        }
        
        return str;
 
 }
 
-boost::uint32_t        
utf8::decodeNextUnicodeCharacter(std::string::const_iterator& it)
+std::string
+utf8::encodeLatin1Character(boost::uint32_t ucsCharacter)
+{
+       std::string text = "";
+       text.push_back(static_cast<unsigned char>(ucsCharacter));
+       return text;
+}
+
+
+boost::uint32_t
+utf8::decodeNextUnicodeCharacter(std::string::const_iterator& it)
 {
        boost::uint32_t uc;
 

Index: utf8.h
===================================================================
RCS file: /sources/gnash/gnash/libbase/utf8.h,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -b -r1.6 -r1.7
--- utf8.h      5 Feb 2008 12:01:52 -0000       1.6
+++ utf8.h      6 Feb 2008 15:21:34 -0000       1.7
@@ -30,10 +30,10 @@
 {
        // Converts a UTF-8 encoded std::string with multibyte characters into
        // a std::wstring.
-       DSOEXPORT std::wstring decodeCanonicalString(const std::string& str);
+       DSOEXPORT std::wstring decodeCanonicalString(const std::string& str, 
int version);
 
        // Converts a std::wstring into a UTF-8 encoded std::string.
-       DSOEXPORT std::string encodeCanonicalString(const std::wstring& wstr);
+       DSOEXPORT std::string encodeCanonicalString(const std::wstring& wstr, 
int version);
 
        // Return the next Unicode character in the UTF-8 encoded
        // string.  Invalid UTF-8 sequences produce a U+FFFD character
@@ -49,6 +49,8 @@
        // May write up to 6 bytes, so make sure there's room in the
        // buffer!
        std::string encodeUnicodeCharacter(boost::uint32_t ucs_character);
+       
+       std::string encodeLatin1Character(boost::uint32_t ucsCharacter);
 }
 
 




reply via email to

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