Update of /cvsroot/facturalux/lite/src/qt/src/codecs In directory sc8-pr-cvs5.sourceforge.net:/tmp/cvs-serv32137/src/qt/src/codecs Modified Files: qbig5codec.cpp qbig5codec.h qeucjpcodec.cpp qeucjpcodec.h qeuckrcodec.cpp qeuckrcodec.h qfontcncodec.cpp qfontcodecs_p.h qfonthkcodec.cpp qfontjpcodec.cpp qfontkrcodec.cpp qfontlaocodec.cpp qfonttwcodec.cpp qgb18030codec.h qgbkcodec.h qjiscodec.cpp qjiscodec.h qjpunicode.cpp qjpunicode.h qrtlcodec.cpp qrtlcodec.h qsjiscodec.cpp qsjiscodec.h qtextcodec.cpp qtextcodec.h qtextcodecfactory.h qtextcodecinterface_p.h qtextcodecplugin.cpp qtextcodecplugin.h qtsciicodec.cpp qtsciicodec.h qutfcodec.cpp qutfcodec.h Log Message: Version 2.1 cerrada Index: qtextcodec.cpp =================================================================== RCS file: /cvsroot/facturalux/lite/src/qt/src/codecs/qtextcodec.cpp,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** qtextcodec.cpp 17 Feb 2006 11:32:54 -0000 1.11 --- qtextcodec.cpp 21 Aug 2006 20:06:31 -0000 1.12 *************** *** 576,579 **** --- 576,581 ---- int heuristicContentMatch(const char* chars, int len) const; + + QTextDecoder* makeDecoder() const; }; *************** *** 636,639 **** --- 638,699 ---- } + class QWindowsLocalDecoder: public QTextDecoder + { + const QWindowsLocalCodec* codec; + int nbuf; + uchar buf[4]; // hopefully this will be enough + public: + QWindowsLocalDecoder(const QWindowsLocalCodec *c) : codec(c), nbuf(0) + { + } + + QString toUnicode(const char* chars, int len) + { + if (len != 1 && nbuf == 0) + return codec->toUnicode(chars, len); + if (len == 1) { + char c[sizeof buf + 2]; + memcpy(c, buf, nbuf); + c[nbuf] = *chars; + c[nbuf+1] = 0; + + // try to decode this: + QString retval = codec->toUnicode(c, -1); + if ( retval.isEmpty() ) { + // it didn't return anything; we probably stopped mid-way in a multi-byte + // character + buf[nbuf++] = *chars; + if (nbuf + 1 == sizeof buf) { + qWarning("QWindowsLocalDecoder: exceeded max internal buffer size"); + nbuf = 0; + } + } + else + nbuf = 0; // decoded successfully + + return retval; + } + + if (len == -1) + len = (int)strlen(chars); + + // Ugh! We need to allocate memory + char *s = new char[nbuf + len + 1]; + memcpy(s, buf, nbuf); + memcpy(s + nbuf, chars, len); + s[nbuf + len] = 0; + + QString retval = codec->toUnicode(s, -1); + nbuf = 0; + delete[] s; + return retval; + } + }; + + QTextDecoder* QWindowsLocalCodec::makeDecoder() const + { + return new QWindowsLocalDecoder(this); + } + #else *************** *** 2703,2706 **** --- 2763,2777 ---- } + static QTextCodec *checkForCodec(const char *name) { + QTextCodec *c = QTextCodec::codecForName(name); + if (!c) { + const char *at = strchr(name, '@'); + if (at) { + QCString n(name, at - name + 1); + c = QTextCodec::codecForName(n.data()); + } + } + return c; + } /* the next two functions are implicitely thread safe, *************** *** 2713,2720 **** #else ! #if defined (_XOPEN_UNIX) && !defined(Q_OS_QNX6) && !defined(Q_OS_OSF) char *charset = nl_langinfo (CODESET); if ( charset ) ! localeMapper = QTextCodec::codecForName( charset ); #endif --- 2784,2791 ---- #else ! #if defined (_XOPEN_UNIX) && !defined(Q_OS_QNX6) && !defined(Q_OS_OSF) && !defined(Q_OS_MAC) char *charset = nl_langinfo (CODESET); if ( charset ) ! localeMapper = QTextCodec::codecForName( charset ); #endif *************** *** 2755,2775 **** char * codeset = ctype ? strchr( ctype, '.' ) : 0; if ( codeset && *codeset == '.' ) ! localeMapper = QTextCodec::codecForName( codeset + 1 ); // 2. CODESET from lang if it contains a .CODESET part codeset = lang ? strchr( lang, '.' ) : 0; ! if ( !localeMapper && codeset && *codeset == '.' ) ! localeMapper = QTextCodec::codecForName( codeset + 1 ); // 3. ctype (maybe the locale is named "ISO-8859-1" or something) if ( !localeMapper && ctype && *ctype != 0 && strcmp (ctype, "C") != 0 ) ! localeMapper = QTextCodec::codecForName( ctype ); // 4. locale (ditto) if ( !localeMapper && lang && *lang != 0 ) ! localeMapper = QTextCodec::codecForName( lang ); // 5. "@euro" ! if ( ctype && strstr( ctype, "@euro" ) || lang && strstr( lang, "@euro" ) ) localeMapper = QTextCodec::codecForName( "ISO 8859-15" ); --- 2826,2846 ---- char * codeset = ctype ? strchr( ctype, '.' ) : 0; if ( codeset && *codeset == '.' ) ! localeMapper = checkForCodec( codeset + 1 ); // 2. CODESET from lang if it contains a .CODESET part codeset = lang ? strchr( lang, '.' ) : 0; ! if ( !localeMapper && codeset && *codeset == '.' ) ! localeMapper = checkForCodec( codeset + 1 ); // 3. ctype (maybe the locale is named "ISO-8859-1" or something) if ( !localeMapper && ctype && *ctype != 0 && strcmp (ctype, "C") != 0 ) ! localeMapper = checkForCodec( ctype ); // 4. locale (ditto) if ( !localeMapper && lang && *lang != 0 ) ! localeMapper = checkForCodec( lang ); // 5. "@euro" ! if ( !localeMapper && ctype && strstr( ctype, "@euro" ) || lang && strstr( lang, "@euro" ) ) localeMapper = QTextCodec::codecForName( "ISO 8859-15" ); |