why not allow directly utf8 encoded dvb texts? ;)
[enigma2.git] / lib / base / estring.cpp
index 22b65698d2916ace5c2a5f36dab717fe6f1df944..014f6e7d89c33deb1ee933f5c63b89692a9aac95 100644 (file)
@@ -1,12 +1,10 @@
 #include <string>
 #include <ctype.h>
 #include <limits.h>
-#include <lib/base/elock.h>
 #include <lib/base/eerror.h>
+#include <lib/base/encoding.h>
 #include <lib/base/estring.h>
 
-static pthread_mutex_t lock=PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP;
-
 std::string getNum(int val, int sys)
 {
 //     Returns a string that contain the value val as string
@@ -331,31 +329,26 @@ std::string convertDVBUTF8(const unsigned char *data, int len, int table, int ts
 
        int i=0, t=0;
 
-#if 0  // FIXME
        if ( tsidonid )
-       {
-               std::map<int, int>::iterator it =
-                       std::string::TransponderDefaultMapping.find(tsidonid);
-               if ( it != std::string::TransponderDefaultMapping.end() )
-                       table = it->second;
-       }
-#endif
+               encodingHandler.getTransponderDefaultMapping(tsidonid, table);
 
        switch(data[0])
        {
-               case 1 ... 12:
+               case 1 ... 11:
                        table=data[i++]+4;
-//                     eDebug("(1..12)text encoded in ISO-8859-%d",table);
+//                     eDebug("(1..11)text encoded in ISO-8859-%d",table);
                        break;
                case 0x10:
                {
 //                     eDebug("(0x10)text encoded in ISO-8859-%d",n);
-                       int n=(data[++i]<<8)|(data[++i]);
+                       int n=(data[++i]<<8);
+                       n |= (data[++i]);
                        ++i;
                        switch(n)
                        {
                                case 12:
                                        eDebug("unsup. ISO8859-12 enc.", n);
+                                       break;
                                default:
                                        table=n;
                                        break;
@@ -378,25 +371,29 @@ std::string convertDVBUTF8(const unsigned char *data, int len, int table, int ts
                        ++i;
                        eDebug("unsup. Big5 subset of ISO/IEC 10646-1 enc.");
                        break;
+               case 0x15: // UTF-8 encoding of ISO/IEC 10646-1
+                       return std::string((char*)data+1, len-1);
                case 0x0:
-               case 0xD ... 0xF:
-               case 0x15 ... 0x1F:
+               case 0xC ... 0xF:
+               case 0x16 ... 0x1F:
+               default:
                        eDebug("reserved %d", data[0]);
                        ++i;
                        break;
        }
 
+       bool useTwoCharMapping =
+               tsidonid && encodingHandler.getTransponderUseTwoCharMapping(tsidonid);
+
        unsigned char res[2048];
        while (i < len)
        {
                unsigned long code=0;
 
-#if 0  // FIXME
-               if ( i+1 < len && tsidonid &&
-                       std::string::TransponderUseTwoCharMapping.find(tsidonid) != std::string::TransponderUseTwoCharMapping.end() &&
+               if ( useTwoCharMapping && i+1 < len &&
                        (code=doVideoTexSuppl(data[i], data[i+1])) )
                        i+=2;
-#endif
+
                if (!code)
                        code=recode(data[i++], table);
                if (!code)
@@ -529,7 +526,7 @@ std::string convertLatin1UTF8(const std::string &string)
 
        while (i < len)
        {
-               unsigned long code=string[i++];
+               unsigned long code=(unsigned char)string[i++];
                                // Unicode->UTF8 encoding
                if (code < 0x80) // identity latin <-> utf8 mapping
                        res[t++]=char(code);
@@ -595,13 +592,13 @@ std::string removeDVBChars(const std::string &s)
        
        int len = s.length();
        
-       for(int i = 0; i < len-1; i++)
+       for(int i = 0; i < len; i++)
        {
                unsigned char c1 = s[i];
                unsigned int c;
                
                        /* UTF8? decode (but only simple) */
-               if(c1 > 0x80)
+               if((c1 > 0x80) && (i < len-1))
                {
                        unsigned char c2 = s[i + 1];
                        c = ((c1&0x3F)<<6) + (c2&0x3F);