diff options
author | dimitri <dimitri@afe2bf4a-e733-0410-8a33-86f594647bc7> | 2010-06-15 11:11:10 (GMT) |
---|---|---|
committer | dimitri <dimitri@afe2bf4a-e733-0410-8a33-86f594647bc7> | 2010-06-15 11:11:10 (GMT) |
commit | 1cbd7d2faa8d543f521b144a8120c3a1ba2f832f (patch) | |
tree | b47b3252c432a415bf772add061e451f5782d6c7 /qtools | |
parent | 6d2875bda7b5416f2e8c72ec8677b7164de86187 (diff) | |
download | Doxygen-1cbd7d2faa8d543f521b144a8120c3a1ba2f832f.zip Doxygen-1cbd7d2faa8d543f521b144a8120c3a1ba2f832f.tar.gz Doxygen-1cbd7d2faa8d543f521b144a8120c3a1ba2f832f.tar.bz2 |
Release-1.7.0
Diffstat (limited to 'qtools')
-rw-r--r-- | qtools/qdir_win32.cpp | 149 | ||||
-rw-r--r-- | qtools/qfile_win32.cpp | 53 | ||||
-rw-r--r-- | qtools/qfileinfo_win32.cpp | 22 | ||||
-rw-r--r-- | qtools/qstring.cpp | 109 | ||||
-rw-r--r-- | qtools/qstring.h | 2 | ||||
-rw-r--r-- | qtools/qtextcodec.cpp | 36 | ||||
-rw-r--r-- | qtools/qtools.pro.in | 7 | ||||
-rw-r--r-- | qtools/qutfcodec.cpp | 276 | ||||
-rw-r--r-- | qtools/qutfcodec.h | 71 | ||||
-rw-r--r-- | qtools/scstring.h | 1 |
10 files changed, 659 insertions, 67 deletions
diff --git a/qtools/qdir_win32.cpp b/qtools/qdir_win32.cpp index 33c8cec..f1515a1 100644 --- a/qtools/qdir_win32.cpp +++ b/qtools/qdir_win32.cpp @@ -59,6 +59,24 @@ extern int qt_cmp_si( const void *, const void * ); } #endif +static QString p_getenv( QString name ) +{ + DWORD len = GetEnvironmentVariableW( ( LPCWSTR ) qt_winTchar ( name, TRUE ), NULL, 0 ); + if ( len == 0 ) + return QString::null; + /* ansi: we allocate too much memory, but this shouldn't be the problem here ... */ + LPWSTR buf = (LPWSTR)new WCHAR[ len ]; + len = GetEnvironmentVariableW ( ( LPCWSTR ) qt_winTchar ( name, TRUE ), buf, len ); + if ( len == 0 ) + { + delete[] buf; + return QString::null; + } + QString ret = qt_winQString ( buf ); + delete[] buf; + return ret; +} + void QDir::slashify( QString& n ) { @@ -71,12 +89,21 @@ void QDir::slashify( QString& n ) QString QDir::homeDirPath() { - QString d; - d = QFile::decodeName(getenv("HOME")); - slashify( d ); - if ( d.isNull() ) - d = rootDirPath(); - return d; + QString d = p_getenv ( "HOME" ); + if ( d.isNull () ) { + d = p_getenv ( "USERPROFILE" ); + if ( d.isNull () ) { + QString homeDrive = p_getenv ( "HOMEDRIVE" ); + QString homePath = p_getenv ( "HOMEPATH" ); + if ( !homeDrive.isNull () && !homePath.isNull () ) { + d = homeDrive + homePath; + } else { + d = rootDirPath (); + } + } + } + slashify( d ); + return d; } QString QDir::canonicalPath() const @@ -99,27 +126,38 @@ QString QDir::canonicalPath() const bool QDir::mkdir( const QString &dirName, bool acceptAbsPath ) const { #if defined(__CYGWIN32_) - return MKDIR( QFile::encodeName(filePath(dirName,acceptAbsPath)), 0777 ) - == 0; + return MKDIR( QFile::encodeName(filePath(dirName,acceptAbsPath)), 0777 ) == 0; #else - return MKDIR( QFile::encodeName(filePath(dirName,acceptAbsPath)) ) == 0; - + return _wmkdir( ( LPCWSTR ) filePath( dirName, acceptAbsPath ).ucs2() ) == 0; #endif } bool QDir::rmdir( const QString &dirName, bool acceptAbsPath ) const { +#if defined(__CYGWIN32_) return RMDIR( QFile::encodeName(filePath(dirName,acceptAbsPath)) ) == 0; +#else + return _wrmdir( ( LPCWSTR ) filePath( dirName, acceptAbsPath ).ucs2() ) == 0; +#endif } bool QDir::isReadable() const { + QString path = dPath; + if ( ( path[ 0 ] == '\\' ) || ( path[ 0 ] == '/' ) ) + path = rootDirPath() + path; +#if defined(__CYGWIN32_) return ACCESS( QFile::encodeName(dPath), R_OK ) == 0; +#else + return ( _waccess( (wchar_t*) path.ucs2(), R_OK ) == 0 ); +#endif } bool QDir::isRoot() const { - return dPath == QString::fromLatin1("/"); + QString path = dPath; + slashify( path ); + return path == rootDirPath (); } bool QDir::rename( const QString &name, const QString &newName, @@ -133,21 +171,33 @@ bool QDir::rename( const QString &name, const QString &newName, } QString fn1 = filePath( name, acceptAbsPaths ); QString fn2 = filePath( newName, acceptAbsPaths ); +#if defined(__CYGWIN32_) return ::rename( QFile::encodeName(fn1), QFile::encodeName(fn2) ) == 0; +#else + return MoveFileW( ( LPCWSTR ) fn1.ucs2(), ( LPCWSTR ) fn2.ucs2() ) != 0; +#endif } bool QDir::setCurrent( const QString &path ) { +#if defined(__CYGWIN32_) int r; r = CHDIR( QFile::encodeName(path) ); return r >= 0; +#else + if ( !QDir( path ).exists() ) + return false; + return ( SetCurrentDirectoryW( ( LPCWSTR ) path.ucs2() ) >= 0 ); +#endif } QString QDir::currentDirPath() { QString result; +#if defined(__CYGWIN32_) + STATBUF st; if ( STAT( ".", &st ) == 0 ) { char currentName[PATH_MAX]; @@ -162,25 +212,47 @@ QString QDir::currentDirPath() qWarning( "QDir::currentDirPath: stat(\".\") failed" ); #endif } + +#else + + DWORD size = 0; + WCHAR currentName[ PATH_MAX ]; + size = ::GetCurrentDirectoryW( PATH_MAX, currentName ); + if ( size != 0 ) { + if ( size > PATH_MAX ) { + WCHAR * newCurrentName = new WCHAR[ size ]; + if ( ::GetCurrentDirectoryW( PATH_MAX, newCurrentName ) != 0 ) + result = QString::fromUcs2( ( ushort* ) newCurrentName ); + delete [] newCurrentName; + } else { + result = QString::fromUcs2( ( ushort* ) currentName ); + } + } + + if ( result.length() >= 2 && result[ 1 ] == ':' ) + result[ 0 ] = result.at( 0 ).upper(); // Force uppercase drive letters. +#endif slashify( result ); return result; } QString QDir::rootDirPath() { - QString d = QString::fromLatin1( "/" ); - return d; + QString d = p_getenv ( "SystemDrive" ); + if ( d.isNull () ) + d = QString::fromLatin1( "c:" ); // not "c:\\" ! + slashify ( d ); + return d; } bool QDir::isRelativePath( const QString &path ) { - int len = path.length(); - if ( len == 0 ) - return TRUE; - int i = 0; - if ( isalpha(path[0]) && path[1] == ':' ) // drive, e.g. a: - i = 2; - return path[i] != '/' && path[i] != '\\'; + if ( path.isEmpty() ) + return TRUE; + int p = 0; + if ( path[ 0 ].isLetter() && path[ 1 ] == ':' ) + p = 2; // we have checked the first 2. + return ( ( path[ p ] != '/' ) && ( path[ p ] != '\\' ) ); } #undef IS_SUBDIR @@ -249,7 +321,7 @@ bool QDir::readDirEntries( const QString &nameFilter, int plen = p.length(); #if defined(_OS_WIN32_) HANDLE ff; - WIN32_FIND_DATA finfo; + WIN32_FIND_DATAW finfo; #else long ff; _finddata_t finfo; @@ -266,7 +338,11 @@ bool QDir::readDirEntries( const QString &nameFilter, p += '/'; p += "*.*"; +#if defined(__CYGWIN32_) ff = FF_GETFIRST( p.data(), &finfo ); +#else + ff = FindFirstFileW ( ( LPCWSTR ) p.ucs2(), &finfo ); +#endif if ( ff == FF_ERROR ) { #if defined(DEBUG) @@ -282,18 +358,20 @@ bool QDir::readDirEntries( const QString &nameFilter, first = FALSE; else { -#if defined(_OS_WIN32_) - if ( !FF_GETNEXT(ff,&finfo) ) - break; -#else +#if defined(__CYGWIN32_) if ( FF_GETNEXT(ff,&finfo) == -1 ) break; +#else + //if ( !FF_GETNEXT(ff,&finfo) ) + // break; + if (!FindNextFileW(ff, &finfo )) + break; #endif } -#if defined(_OS_WIN32_) - int attrib = finfo.dwFileAttributes; -#else +#if defined(__CYGWIN32_) int attrib = finfo.attrib; +#else + int attrib = finfo.dwFileAttributes; #endif bool isDir = (attrib & IS_SUBDIR) != 0; bool isFile = !isDir; @@ -305,12 +383,13 @@ bool QDir::readDirEntries( const QString &nameFilter, bool isHidden = (attrib & IS_HIDDEN) != 0; bool isSystem = (attrib & IS_SYSTEM) != 0; -#if defined(_OS_WIN32_) - const char *fname = finfo.cFileName; -#else +#if defined(__CYGWIN32_) const char *fname = finfo.name; +#else + //const char *fname = finfo.cFileName; + QString fname = QString::fromUcs2( ( const unsigned short* ) finfo.cFileName); #endif - if ( wc.match(fname) == -1 && !(allDirs && isDir) ) + if ( wc.match(fname.utf8()) == -1 && !(allDirs && isDir) ) continue; QString name = fname; @@ -341,10 +420,10 @@ bool QDir::readDirEntries( const QString &nameFilter, fiList->append( new QFileInfo( fi ) ); } } -#if defined(_OS_WIN32_) - FindClose( ff ); -#else +#if defined(__CYGWIN32_) _findclose( ff ); +#else + FindClose( ff ); #endif // Sort... diff --git a/qtools/qfile_win32.cpp b/qtools/qfile_win32.cpp index 0cc91de..80ad628 100644 --- a/qtools/qfile_win32.cpp +++ b/qtools/qfile_win32.cpp @@ -34,11 +34,26 @@ # define OPEN_ASYNC O_NDELAY #endif +static void reslashify( QString& n ) +{ + for ( int i=0; i<(int)n.length(); i++ ) + { + if ( n[i] == '/' ) + n[i] = '\\'; + } +} + bool qt_file_access( const QString& fn, int t ) { if ( fn.isEmpty() ) return FALSE; +#if defined(__CYGWIN32_) return ACCESS( QFile::encodeName(fn), t ) == 0; +#else + QString str = fn; + reslashify(str); + return ( _waccess( (wchar_t*) str.ucs2(), t ) == 0 ); +#endif } /*! @@ -54,8 +69,14 @@ bool QFile::remove( const QString &fileName ) #endif return FALSE; } - return ::remove( QFile::encodeName(fileName) ) == 0; +#if defined(__CYGWIN32_) // unlink more common in UNIX + return ::remove( QFile::encodeName(fileName) ) == 0; +#else + QString str = fileName; + reslashify(str); + return ( _wunlink( (wchar_t*) str.ucs2() ) == 0 ); +#endif } #if defined(O_NONBLOCK) @@ -166,7 +187,15 @@ bool QFile::open( int m ) if ( isAsynchronous() ) oflags |= OPEN_ASYNC; #endif + + +#if defined(__CYGWIN32_) fd = OPEN( QFile::encodeName(fn), oflags, 0666 ); +#else + QString str = fn; + reslashify(str); + fd = _wopen( (wchar_t*) str.ucs2(), oflags, 0666 ); +#endif if ( fd != -1 ) { // open successful FSTAT( fd, &st ); // get the stat for later usage @@ -201,7 +230,14 @@ bool QFile::open( int m ) strcat( perm2, "b" ); while (1) { // At most twice +#if defined(__CYGWIN32_) fh = fopen( QFile::encodeName(fn), perm2 ); +#else + QString str = fn; + QString prm( perm2 ); + reslashify(str); + fh = _wfopen( (wchar_t*) str.ucs2(), (wchar_t*) prm.ucs2() ); +#endif if ( !fh && try_create ) { perm2[0] = 'w'; // try "w+" instead of "r+" @@ -372,10 +408,23 @@ uint QFile::size() const STATBUF st; if ( isOpen() ) { FSTAT( fh ? FILENO(fh) : fd, &st ); + return st.st_size; } else { +#if defined(__CYGWIN32_) STAT( QFile::encodeName(fn), &st ); +#else + QString str = fn; + reslashify(str); +#ifdef QT_LARGEFILE_SUPPORT + if ( _wstati64( (wchar_t*) str.ucs2(), &st ) != -1 ) { +#else + if ( _wstat( (wchar_t*) str.ucs2(), &st ) != -1 ) { +#endif +#endif + return st.st_size; + } } - return st.st_size; + return 0; } /*! diff --git a/qtools/qfileinfo_win32.cpp b/qtools/qfileinfo_win32.cpp index bfcc6ac..8f83107 100644 --- a/qtools/qfileinfo_win32.cpp +++ b/qtools/qfileinfo_win32.cpp @@ -25,6 +25,15 @@ #include "qdatetime.h" #include "qdir.h" +static void reslashify( QString& n ) +{ + for ( int i=0; i<(int)n.length(); i++ ) + { + if ( n[i] == '/' ) + n[i] = '\\'; + } +} + void QFileInfo::slashify( QString& n ) { for ( int i=0; i<(int)n.length(); i++ ) @@ -246,6 +255,7 @@ void QFileInfo::doStat() const STATBUF *b = &that->fic->st; that->fic->isSymLink = FALSE; +#if defined(__CYGWIN32_) int r; r = STAT( QFile::encodeName(fn), b ); @@ -254,6 +264,18 @@ void QFileInfo::doStat() const delete that->fic; that->fic = 0; } +#else + QString file = fn; + reslashify(file); +#ifdef QT_LARGEFILE_SUPPORT + if ( _wstati64( (wchar_t*) file.ucs2(), b ) == -1 ) { +#else + if ( _wstat( (wchar_t*) file.ucs2(), b ) == -1 ) { +#endif + delete that->fic; + that->fic = 0; + } +#endif } /*! diff --git a/qtools/qstring.cpp b/qtools/qstring.cpp index b582445..5d50060 100644 --- a/qtools/qstring.cpp +++ b/qtools/qstring.cpp @@ -12065,6 +12065,69 @@ char* QString::unicodeToAscii(const QChar *uc, uint l) return result; } +static uint computeNewMax( uint len ) +{ + if (len >= 0x80000000) + return len; + + uint newMax = 4; + while ( newMax < len ) + newMax *= 2; + // try to save some memory + if ( newMax >= 1024 * 1024 && len <= newMax - (newMax >> 2) ) + newMax -= newMax >> 2; + return newMax; +} + +/*! + Returns the QString as a zero terminated array of unsigned shorts + if the string is not null; otherwise returns zero. + + The result remains valid so long as one unmodified + copy of the source string exists. + */ +const unsigned short *QString::ucs2() const +{ + if ( ! d->unicode ) + return 0; + unsigned int len = d->len; + if ( d->maxl < len + 1 ) { + // detach, grow or shrink + uint newMax = computeNewMax( len + 1 ); + QChar* nd = QT_ALLOC_QCHAR_VEC( newMax ); + if ( nd ) { + if ( d->unicode ) + memcpy( nd, d->unicode, sizeof(QChar)*len ); + ((QString *)this)->deref(); + ((QString *)this)->d = new QStringData( nd, len, newMax ); + } + } + d->unicode[len] = 0; + return (unsigned short *) d->unicode; +} + +/*! + Constructs a string that is a deep copy of \a str, interpreted as a + UCS2 encoded, zero terminated, Unicode string. + + If \a str is 0, then a null string is created. + \sa isNull() + */ +QString QString::fromUcs2( const unsigned short *str ) +{ + if ( !str ) { + return QString::null; + } else { + int length = 0; + while ( str[length] != 0 ) + length++; + QChar* uc = QT_ALLOC_QCHAR_VEC( length ); + memcpy( uc, str, length*sizeof(QChar) ); + return QString( new QStringData( uc, length, length ), TRUE ); + } +} + + /***************************************************************************** QString member functions *****************************************************************************/ @@ -12214,10 +12277,14 @@ QString::QString( const QByteArray& ba ) QString::QString( const QCString& ba ) { - Q2HELPER(stat_construct_ba++) - uint l; - QChar *uc = internalAsciiToUnicode(ba,&l); - d = new QStringData(uc,l,l); + //Q2HELPER(stat_construct_ba++) + //uint l; + //QChar *uc = internalAsciiToUnicode(ba,&l); + //d = new QStringData(uc,l,l); + Q2HELPER(stat_fast_copy++) + QString s = QString::fromUtf8(ba.data(),ba.length()); + d = s.d; + d->ref(); } /*! @@ -12265,11 +12332,15 @@ QString::QString( const QChar* unicode, uint length ) QString::QString( const char *str ) { - Q2HELPER(stat_construct_charstar++) - uint l; - QChar *uc = internalAsciiToUnicode(str,&l); - Q2HELPER(stat_construct_charstar_size+=l) - d = new QStringData(uc,l,l); + //Q2HELPER(stat_construct_charstar++) + //uint l; + //QChar *uc = internalAsciiToUnicode(str,&l); + //Q2HELPER(stat_construct_charstar_size+=l) + //d = new QStringData(uc,l,l); + Q2HELPER(stat_fast_copy++) + QString s = QString::fromUtf8(str); + d = s.d; + d->ref(); } @@ -14329,7 +14400,25 @@ const char* QString::latin1() const } Q2HELPER(stat_get_ascii++) Q2HELPER(stat_get_ascii_size+=d->len) - d->ascii = unicodeToAscii( d->unicode, d->len ); + static QTextCodec* codec = QTextCodec::codecForMib(106); + if (codec) // we use utf8 coding also for latin1 if possible + { + QCString utf8str(codec->fromUnicode(*this)); + d->ascii = new char[utf8str.length()+1]; + if (utf8str.isEmpty()) + { + d->ascii[0]='\0'; // make empty string + } + else // copy string + { + qstrcpy(d->ascii,utf8str.data()); + } + } + else // fall back to latin1 + { + d->ascii = unicodeToAscii( d->unicode, d->len ); + } + QCString utf8str(utf8()); d->dirtyascii = 0; return d->ascii; } diff --git a/qtools/qstring.h b/qtools/qstring.h index c64d756..4357809 100644 --- a/qtools/qstring.h +++ b/qtools/qstring.h @@ -501,6 +501,8 @@ public: const char* ascii() const; const char* latin1() const; static QString fromLatin1(const char*, int len=-1); + const unsigned short *ucs2() const; + static QString fromUcs2( const unsigned short *ucs2 ); #ifndef QT_NO_TEXTCODEC QCString utf8() const; static QString fromUtf8(const char*, int len=-1); diff --git a/qtools/qtextcodec.cpp b/qtools/qtextcodec.cpp index fbbc1f9..4eb8ba5 100644 --- a/qtools/qtextcodec.cpp +++ b/qtools/qtextcodec.cpp @@ -41,14 +41,14 @@ #include "qlist.h" #ifndef QT_NO_CODECS #include "qutfcodec.h" -#include "qgbkcodec.h" -#include "qeucjpcodec.h" -#include "qjiscodec.h" -#include "qsjiscodec.h" -#include "qeuckrcodec.h" -#include "qbig5codec.h" -#include "qrtlcodec.h" -#include "qtsciicodec.h" +//#include "qgbkcodec.h" +//#include "qeucjpcodec.h" +//#include "qjiscodec.h" +//#include "qsjiscodec.h" +//#include "qeuckrcodec.h" +//#include "qbig5codec.h" +//#include "qrtlcodec.h" +//#include "qtsciicodec.h" #endif #include "qfile.h" @@ -1006,7 +1006,7 @@ public: break; else if (incmap) { char* cursor = line; - int byte,unicode=-1; + int byte=0,unicode=-1; ushort* mb_unicode=0; const int maxmb=8; // more -> we'll need to improve datastructures char mb[maxmb+1]; @@ -2054,17 +2054,17 @@ static void setupBuiltinCodecs() (void)new QSimpleTextCodec( i ); } while( unicodevalues[i++].mib != LAST_MIB ); - (void)new QEucJpCodec; - (void)new QSjisCodec; - (void)new QJisCodec; - (void)new QEucKrCodec; - (void)new QGbkCodec; - (void)new QBig5Codec; + //(void)new QEucJpCodec; + //(void)new QSjisCodec; + //(void)new QJisCodec; + //(void)new QEucKrCodec; + //(void)new QGbkCodec; + //(void)new QBig5Codec; (void)new QUtf8Codec; (void)new QUtf16Codec; - (void)new QHebrewCodec; - (void)new QArabicCodec; - (void)new QTsciiCodec; + //(void)new QHebrewCodec; + //(void)new QArabicCodec; + //(void)new QTsciiCodec; #endif // QT_NO_CODECS } diff --git a/qtools/qtools.pro.in b/qtools/qtools.pro.in index f0a1ffa..3eabed9 100644 --- a/qtools/qtools.pro.in +++ b/qtools/qtools.pro.in @@ -49,6 +49,7 @@ HEADERS = qarray.h \ qthread_p.h \ qmutex.h \ qmutex_p.h \ + qutfcodec.h \ qwaitcondition.h SOURCES = qbuffer.cpp \ @@ -75,7 +76,8 @@ SOURCES = qbuffer.cpp \ qxml.cpp \ qmap.cpp \ qthread.cpp \ - qmutex.cpp + qmutex.cpp \ + qutfcodec.cpp unix:SOURCES += qfile_unix.cpp \ qdir_unix.cpp \ @@ -92,7 +94,8 @@ win32:SOURCES += qfile_win32.cpp \ qwaitcondition_win32.cpp INCLUDEPATH = . -TMAKE_CXXFLAGS += -DQT_NO_CODECS -DQT_LITE_UNICODE +#TMAKE_CXXFLAGS += -DQT_NO_CODECS -DQT_LITE_UNICODE +TMAKE_CXXFLAGS += -DQT_LITE_UNICODE win32:TMAKE_CXXFLAGS += -DQT_NODLL win32-g++:TMAKE_CXXFLAGS += -D__CYGWIN__ -DALL_STATIC OBJECTS_DIR = ../objects diff --git a/qtools/qutfcodec.cpp b/qtools/qutfcodec.cpp new file mode 100644 index 0000000..f64812c --- /dev/null +++ b/qtools/qutfcodec.cpp @@ -0,0 +1,276 @@ +/**************************************************************************** +** +** +** Implementation of QEucCodec class +** +** Created : 981015 +** +** Copyright (C)1998-2000 Trolltech AS. All rights reserved. +** +** This file is part of the tools module of the Qt GUI Toolkit. +** +** This file may be distributed under the terms of the Q Public License +** as defined by Trolltech AS of Norway and appearing in the file +** LICENSE.QPL included in the packaging of this file. +** +** This file may be distributed and/or modified under the terms of the +** GNU General Public License version 2 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. +** +** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition +** licenses may use this file in accordance with the Qt Commercial License +** Agreement provided with the Software. +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for +** information about Qt Commercial License Agreements. +** See http://www.trolltech.com/qpl/ for QPL licensing information. +** See http://www.trolltech.com/gpl/ for GPL licensing information. +** +** Contact info@trolltech.com if any conditions of this licensing are +** not clear to you. +** +**********************************************************************/ + +#include "qutfcodec.h" + +#ifndef QT_NO_TEXTCODEC + +int QUtf8Codec::mibEnum() const +{ + return 106; +} + +QCString QUtf8Codec::fromUnicode(const QString& uc, int& len_in_out) const +{ + int l = QMIN((int)uc.length(),len_in_out); + int rlen = l*3+1; + QCString rstr(rlen); + uchar* cursor = (uchar*)rstr.data(); + for (int i=0; i<l; i++) { + QChar ch = uc[i]; + if ( !ch.row() && ch.cell() < 0x80 ) { + *cursor++ = ch.cell(); + } else { + uchar b = (ch.row() << 2) | (ch.cell() >> 6); + if ( ch.row() < 0x08 ) { + *cursor++ = 0xc0 | b; + } else { + *cursor++ = 0xe0 | (ch.row() >> 4); + *cursor++ = 0x80 | (b&0x3f); + } + *cursor++ = 0x80 | (ch.cell()&0x3f); + } + } + len_in_out = cursor - (uchar*)rstr.data(); + rstr.truncate(len_in_out); + return rstr; +} + +const char* QUtf8Codec::name() const +{ + return "UTF-8"; +} + +int QUtf8Codec::heuristicContentMatch(const char* chars, int len) const +{ + int score = 0; + for (int i=0; i<len; i++) { + uchar ch = chars[i]; + // No nulls allowed. + if ( !ch ) + return -1; + if ( ch < 128 ) { + // Inconclusive + score++; + } else if ( (ch&0xe0) == 0xc0 ) { + if ( i < len-1 ) { + uchar c2 = chars[++i]; + if ( (c2&0xc0) != 0x80 ) + return -1; + score+=3; + } + } else if ( (ch&0xf0) == 0xe0 ) { + if ( i < len-1 ) { + uchar c2 = chars[++i]; + if ( (c2&0xc0) != 0x80 ) { + return -1; +#if 0 + if ( i < len-1 ) { + uchar c3 = chars[++i]; + if ( (c3&0xc0) != 0x80 ) + return -1; + score+=3; + } +#endif + } + score+=2; + } + } + } + return score; +} + + + + +class QUtf8Decoder : public QTextDecoder { + ushort uc; + int need; +public: + QUtf8Decoder() : need(0) + { + } + + QString toUnicode(const char* chars, int len) + { + QString result; + for (int i=0; i<len; i++) { + uchar ch = chars[i]; + if (need) { + if ( (ch&0xc0) == 0x80 ) { + uc = (uc << 6) | (ch & 0x3f); + need--; + if ( !need ) { + result += QChar(uc); + } + } else { + // error + result += QChar::replacement; + need = 0; + } + } else { + if ( ch < 128 ) { + result += QChar(ch); + } else if ( (ch&0xe0) == 0xc0 ) { + uc = ch &0x1f; + need = 1; + } else if ( (ch&0xf0) == 0xe0 ) { + uc = ch &0x0f; + need = 2; + } + } + } + return result; + } +}; + +QTextDecoder* QUtf8Codec::makeDecoder() const +{ + return new QUtf8Decoder; +} + + + + + + +int QUtf16Codec::mibEnum() const +{ + return 1000; +} + +const char* QUtf16Codec::name() const +{ + return "ISO-10646-UCS-2"; +} + +int QUtf16Codec::heuristicContentMatch(const char* chars, int len) const +{ + uchar* uchars = (uchar*)chars; + if ( len >= 2 && (uchars[0] == 0xff && uchars[1] == 0xfe || + uchars[1] == 0xff && uchars[0] == 0xfe) ) + return len; + else + return 0; +} + + + + +class QUtf16Encoder : public QTextEncoder { + bool headerdone; +public: + QUtf16Encoder() : headerdone(FALSE) + { + } + + QCString fromUnicode(const QString& uc, int& len_in_out) + { + if ( headerdone ) { + len_in_out = uc.length()*sizeof(QChar); + QCString d(len_in_out); + memcpy(d.data(),uc.unicode(),len_in_out); + return d; + } else { + headerdone = TRUE; + len_in_out = (1+uc.length())*sizeof(QChar); + QCString d(len_in_out); + memcpy(d.data(),&QChar::byteOrderMark,sizeof(QChar)); + memcpy(d.data()+sizeof(QChar),uc.unicode(),uc.length()*sizeof(QChar)); + return d; + } + } +}; + +class QUtf16Decoder : public QTextDecoder { + uchar buf; + bool half; + bool swap; + bool headerdone; + +public: + QUtf16Decoder() : half(FALSE), swap(FALSE), headerdone(FALSE) + { + } + + QString toUnicode(const char* chars, int len) + { + QString r; + + while ( len-- ) { + if ( half ) { + QChar ch; + if ( swap ) { + ch.row() = *chars++; + ch.cell() = buf; + } else { + ch.row() = buf; + ch.cell() = *chars++; + } + if ( !headerdone ) { + if ( ch == QChar::byteOrderSwapped ) { + swap = !swap; + } else if ( ch == QChar::byteOrderMark ) { + // Ignore ZWNBSP + } else { + r += ch; + } + headerdone = TRUE; + } else + r += ch; + half = FALSE; + } else { + buf = *chars++; + half = TRUE; + } + } + + return r; + } +}; + +QTextDecoder* QUtf16Codec::makeDecoder() const +{ + return new QUtf16Decoder; +} + +QTextEncoder* QUtf16Codec::makeEncoder() const +{ + return new QUtf16Encoder; +} + +#endif // QT_NO_TEXTCODEC diff --git a/qtools/qutfcodec.h b/qtools/qutfcodec.h new file mode 100644 index 0000000..af864be --- /dev/null +++ b/qtools/qutfcodec.h @@ -0,0 +1,71 @@ +/**************************************************************************** +** +** +** Definition of QEucCodec class +** +** Created : 981015 +** +** Copyright (C) 1998-2000 Trolltech AS. All rights reserved. +** +** This file is part of the tools module of the Qt GUI Toolkit. +** +** This file may be distributed under the terms of the Q Public License +** as defined by Trolltech AS of Norway and appearing in the file +** LICENSE.QPL included in the packaging of this file. +** +** This file may be distributed and/or modified under the terms of the +** GNU General Public License version 2 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. +** +** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition +** licenses may use this file in accordance with the Qt Commercial License +** Agreement provided with the Software. +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for +** information about Qt Commercial License Agreements. +** See http://www.trolltech.com/qpl/ for QPL licensing information. +** See http://www.trolltech.com/gpl/ for GPL licensing information. +** +** Contact info@trolltech.com if any conditions of this licensing are +** not clear to you. +** +**********************************************************************/ + +#ifndef QUTFCODEC_H +#define QUTFCODEC_H + +#ifndef QT_H +#include "qtextcodec.h" +#endif // QT_H + +#ifndef QT_NO_TEXTCODEC + +class Q_EXPORT QUtf8Codec : public QTextCodec { +public: + virtual int mibEnum() const; + const char* name() const; + + QTextDecoder* makeDecoder() const; + + QCString fromUnicode(const QString& uc, int& len_in_out) const; + + int heuristicContentMatch(const char* chars, int len) const; +}; + +class Q_EXPORT QUtf16Codec : public QTextCodec { +public: + virtual int mibEnum() const; + const char* name() const; + + QTextDecoder* makeDecoder() const; + QTextEncoder* makeEncoder() const; + + int heuristicContentMatch(const char* chars, int len) const; +}; + +#endif //QT_NO_TEXTCODEC +#endif // QUTFCODEC_H diff --git a/qtools/scstring.h b/qtools/scstring.h index 08de44b..a9b462c 100644 --- a/qtools/scstring.h +++ b/qtools/scstring.h @@ -58,6 +58,7 @@ public: int find( char c, int index=0, bool cs=TRUE ) const; int find( const char *str, int index=0, bool cs=TRUE ) const; int find( const QRegExp &, int index=0 ) const; + int find( const QCString &str, int index, bool cs ) const; int findRev( char c, int index=-1, bool cs=TRUE) const; int findRev( const char *str, int index=-1, bool cs=TRUE) const; int findRev( const QRegExp &, int index=-1 ) const; |