Diffstat (limited to 'noncore/apps/tinykate/libkate/qt3back/qregexp3.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/apps/tinykate/libkate/qt3back/qregexp3.cpp | 80 |
1 files changed, 43 insertions, 37 deletions
diff --git a/noncore/apps/tinykate/libkate/qt3back/qregexp3.cpp b/noncore/apps/tinykate/libkate/qt3back/qregexp3.cpp index a2c680f..78635b2 100644 --- a/noncore/apps/tinykate/libkate/qt3back/qregexp3.cpp +++ b/noncore/apps/tinykate/libkate/qt3back/qregexp3.cpp @@ -17,62 +17,68 @@ ** 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. ** **********************************************************************/ #if QT_VERSION >=300 #error QRegExp3 is now in QT 3 use QRegExp instead #endif -#include "qarray.h" -#include "qbitarray.h" -#include "qcache.h" -#include "qintdict.h" -#include "qmap.h" #if QT_VERSION < 300 #include "./qregexp3.h" #else #include "qregexp.h" #endif -#include "qstring.h" -#include "qtl.h" -#include "qvector.h" +/* OPIE */ +#include <opie2/odebug.h> + +/* QT */ +#include <qarray.h> +#include <qbitarray.h> +#include <qcache.h> +#include <qintdict.h> +#include <qmap.h> +#include <qstring.h> +#include <qtl.h> +#include <qvector.h> + +/* STD */ #include <limits.h> /* WARNING! Be sure to read qregexp.tex before modifying this file. */ /*! \class QRegExp3 qregexp.h \brief The QRegExp class provides pattern matching using regular expressions. \ingroup tools \ingroup misc \ingroup shared Regular expressions, "regexps", provide a way to find patterns within text. This is useful in many contexts, for example: <ol> <li>\e Validation. A regexp can be used to check whether a piece of text meets some criteria, e.g. is an integer or contains no whitespace. <li>\e Searching. Regexps provide a much more powerful means of @@ -1410,92 +1416,92 @@ void QRegExpEngine::heuristicallyChooseHeuristic() ( goodLateStart - goodEarlyStart ); /* Less magic formula: We pick a couple of characters at random, and check whether they are good or bad. */ int badCharScore = 0; int step = QMAX( 1, NumBadChars / 32 ); for ( i = 1; i < NumBadChars; i += step ) { if ( occ1[i] == NoOccurrence ) badCharScore += minl; else badCharScore += occ1[i]; } badCharScore /= minl; useGoodStringHeuristic = ( goodStringScore > badCharScore ); } #endif #if defined(QT_DEBUG) void QRegExpEngine::dump() const { int i, j; - qDebug( "Case %ssensitive engine", cs ? "" : "in" ); - qDebug( " States" ); + odebug << "Case " << (cs ? "" : "in") << "sensitive engine" << oendl; + odebug << " States" << oendl; for ( i = 0; i < ns; i++ ) { - qDebug( " %d%s", i, - i == InitialState ? " (initial)" : - i == FinalState ? " (final)" : "" ); + odebug << " " << i + << (i == InitialState ? " (initial)" : i == FinalState ? " (final)" : "") << oendl; + #ifndef QT_NO_REGEXP_CAPTURE - qDebug( " in atom %d", s[i]->atom ); + odebug << " in atom " << s[i]->atom << oendl; #endif int m = s[i]->match; if ( (m & CharClassBit) != 0 ) { - qDebug( " match character class %d", m ^ CharClassBit ); + odebug << " match character class " << (m ^ CharClassBit) << oendl; #ifndef QT_NO_REGEXP_CCLASS cl[m ^ CharClassBit]->dump(); #else - qDebug( " negative character class" ); + odebug << " negative character class" << oendl; #endif } else if ( (m & BackRefBit) != 0 ) { - qDebug( " match back-reference %d", m ^ BackRefBit ); + odebug << " match back-reference " << (m ^ BackRefBit) << oendl; } else if ( m >= 0x20 && m <= 0x7e ) { - qDebug( " match 0x%.4x (%c)", m, m ); + odebug << " match " << QString().sprintf( "0x%.4x", m) << " (" << m << ")" << oendl; + } else { - qDebug( " match 0x%.4x", m ); + odebug << " match " << QString().sprintf( "0x%.4x", m) << oendl; } for ( j = 0; j < (int) s[i]->outs.size(); j++ ) { int next = s[i]->outs[j]; - qDebug( " -> %d", next ); + odebug << " -> " << next << oendl; if ( s[i]->reenter != 0 && s[i]->reenter->contains(next) ) - qDebug( " [reenter %d]", (*s[i]->reenter)[next] ); + odebug << " [reenter " << (*s[i]->reenter)[next] << "]" << oendl; if ( s[i]->anchors != 0 && at(*s[i]->anchors, next) != 0 ) - qDebug( " [anchors 0x%.8x]", (*s[i]->anchors)[next] ); + odebug << " [anchors " << QString().sprintf( "0x%.8x]", (*s[i]->anchors)[next] ) << oendl; } } #ifndef QT_NO_REGEXP_CAPTURE if ( nf > 0 ) { - qDebug( " Atom Parent Capture" ); + odebug << " Atom Parent Capture" << oendl; for ( i = 0; i < nf; i++ ) - qDebug( " %6d %6d %6d", i, f[i].parent, f[i].capture ); + odebug << QString().sprintf(" %6d %6d %6d", i, f[i].parent, f[i].capture ) << oendl; } #endif #ifndef QT_NO_REGEXP_ANCHOR_ALT for ( i = 0; i < (int) aa.size(); i++ ) - qDebug( " Anchor alternation 0x%.8x: 0x%.8x 0x%.9x", i, aa[i].a, - aa[i].b ); + odebug << QString().sprintf(" Anchor alternation 0x%.8x: 0x%.8x 0x%.9x", i, aa[i].a, aa[i].b ) << oendl; #endif } #endif void QRegExpEngine::setup( bool caseSensitive ) { #ifndef QT_NO_REGEXP_OPTIM if ( engCount++ == 0 ) { noOccurrences = new QArray<int>( NumBadChars ); firstOccurrenceAtZero = new QArray<int>( NumBadChars ); noOccurrences->fill( NoOccurrence ); firstOccurrenceAtZero->fill( 0 ); } #endif s.setAutoDelete( TRUE ); s.resize( 32 ); ns = 0; #ifndef QT_NO_REGEXP_CAPTURE f.resize( 32 ); nf = 0; cf = -1; #endif realncap = 0; ncap = 0; @@ -2175,55 +2181,55 @@ void QRegExpEngine::CharClass::addRange( ushort from, ushort to ) } #endif } bool QRegExpEngine::CharClass::in( QChar ch ) const { #ifndef QT_NO_REGEXP_OPTIM if ( occ1[BadChar(ch)] == NoOccurrence ) return n; #endif if ( c != 0 && (c & (1 << (int) ch.category())) != 0 ) return !n; for ( int i = 0; i < (int) r.size(); i++ ) { if ( ch.unicode() >= r[i].from && ch.unicode() <= r[i].to ) return !n; } return n; } #if defined(QT_DEBUG) void QRegExpEngine::CharClass::dump() const { int i; - qDebug( " %stive character class", n ? "nega" : "posi" ); + odebug << " " << (n ? "nega" : "posi") << "tive character class" << oendl; #ifndef QT_NO_REGEXP_CCLASS if ( c != 0 ) - qDebug( " categories 0x%.8x", c ); + odebug << QString().sprintf(" categories 0x%.8x", c ) << oendl; #endif for ( i = 0; i < (int) r.size(); i++ ) - qDebug( " 0x%.4x through 0x%.4x", r[i].from, r[i].to ); + odebug << QString().sprintf(" 0x%.4x through 0x%.4x", r[i].from, r[i].to ) << oendl; } #endif #endif QRegExpEngine::Box::Box( QRegExpEngine *engine ) : eng( engine ), skipanchors( 0 ) #ifndef QT_NO_REGEXP_OPTIM , earlyStart( 0 ), lateStart( 0 ), maxl( 0 ), occ1( *noOccurrences ) #endif { minl = 0; } QRegExpEngine::Box& QRegExpEngine::Box::operator=( const Box& b ) { eng = b.eng; ls = b.ls; rs = b.rs; lanchors = b.lanchors; ranchors = b.ranchors; skipanchors = b.skipanchors; #ifndef QT_NO_REGEXP_OPTIM earlyStart = b.earlyStart; lateStart = b.lateStart; @@ -2425,64 +2431,64 @@ void QRegExpEngine::Box::setupHeuristics() /* A regular expression such as 112|1 has occ1['2'] = 2 and minl = 1 at this point. An entry of occ1 has to be at most minl or infinity for the rest of the algorithm to go well. We waited until here before normalizing these cases (instead of doing it in Box::orx()) because sometimes things improve by themselves; consider (112|1)34. */ for ( int i = 0; i < NumBadChars; i++ ) { if ( occ1[i] != NoOccurrence && occ1[i] >= minl ) occ1[i] = minl; } eng->setupBadCharHeuristic( minl, occ1 ); eng->heuristicallyChooseHeuristic(); } #endif #if defined(QT_DEBUG) void QRegExpEngine::Box::dump() const { int i; - qDebug( "Box of at least %d character%s", minl, minl == 1 ? "" : "s" ); - qDebug( " Left states:" ); + odebug << "Box of at least " << minl << " character" << (minl == 1 ? "" : "s") << oendl; + odebug << " Left states:" << oendl; for ( i = 0; i < (int) ls.size(); i++ ) { if ( at(lanchors, ls[i]) == 0 ) - qDebug( " %d", ls[i] ); + odebug << " " << ls[i] << oendl; else - qDebug( " %d [anchors 0x%.8x]", ls[i], lanchors[ls[i]] ); + odebug << " " << ls[i] << QString().sprintf(" [anchors 0x%.8x]", lanchors[ls[i]]) << oendl; } - qDebug( " Right states:" ); + odebug << " Right states:" << oendl; for ( i = 0; i < (int) rs.size(); i++ ) { if ( at(ranchors, ls[i]) == 0 ) - qDebug( " %d", rs[i] ); + odebug << " " << rs[i] << oendl; else - qDebug( " %d [anchors 0x%.8x]", rs[i], ranchors[rs[i]] ); + odebug << " " << rs[i] << QString().sprintf(" [anchors 0x%.8x]", ranchors[rs[i]]) << oendl; } - qDebug( " Skip anchors: 0x%.8x", skipanchors ); + odebug << QString().sprintf(" Skip anchors: 0x%.8x", skipanchors) << oendl; } #endif void QRegExpEngine::Box::addAnchorsToEngine( const Box& to ) const { for ( int i = 0; i < (int) to.ls.size(); i++ ) { for ( int j = 0; j < (int) rs.size(); j++ ) { int a = eng->anchorConcatenation( at(ranchors, rs[j]), at(to.lanchors, to.ls[i]) ); eng->addAnchors( rs[j], to.ls[i], a ); } } } int QRegExpEngine::getChar() { return ( yyPos == yyLen ) ? EOS : yyIn[yyPos++].unicode(); } int QRegExpEngine::getEscape() { #ifndef QT_NO_REGEXP_ESCAPE const char tab[] = "afnrtv"; // no b, as \b means word boundary const char backTab[] = "\a\f\n\r\t\v"; |