Source Code (Use browser search to find items of interest.)

Class Index

qt'QRegExp (./qt-2.1.0/src/tools/qregexp.h:34)

class Q_EXPORT QRegExp
{
public:
    QRegExp();
    QRegExp( const QString &, bool caseSensitive=TRUE, bool wildcard=FALSE );
    QRegExp( const QRegExp & );
   ~QRegExp();
    QRegExp    &operator=( const QRegExp & );
    QRegExp    &operator=( const QString &pattern );

    bool	operator==( const QRegExp & )  const;
    bool	operator!=( const QRegExp &r ) const
					{ return !(this->operator==(r)); }

    bool	isEmpty()	const	{ return rxdata == 0; }
    bool	isValid()	const	{ return error == 0; }

    bool	caseSensitive() const	{ return cs; }
    void	setCaseSensitive( bool );

    bool	wildcard()	const	{ return wc; }
    void	setWildcard( bool );

    QString	pattern()	const	{ return rxstring; }

    int		match( const QString &str, int index=0, int *len=0,
		       bool indexIsStart = TRUE ) const;

protected:
    void	compile();
    const QChar *matchstr( uint *, const QChar *, uint, const QChar * ) const;

private:
    QString	rxstring;			// regular expression pattern
    uint	*rxdata;			// compiled regexp pattern
    int		error;				// error status
    bool	cs;				// case sensitive
    bool	wc;				// wildcard
};


qt'QRegExp::QRegExp() (./qt-2.1.0/src/tools/qregexp.cpp:160)

QRegExp::QRegExp()
{
    rxdata = 0;
    cs = TRUE;
    wc = FALSE;
    error = PatOk;
}

/*!
  Constructs a regular expression.

  \arg \e pattern is the regular expression pattern string.
  \arg \e caseSensitive specifies whether or not to use case sensitive
  matching.
  \arg \e wildcard specifies whether the pattern string should be used for
  wildcard matching (also called globbing expression), normally used for
  matching file names.

  \sa setWildcard()
*/


qt'QRegExp::QRegExp() (./qt-2.1.0/src/tools/qregexp.cpp:181)

QRegExp::QRegExp( const QString &pattern, bool caseSensitive, bool wildcard )
{
    rxstring = pattern;
    rxdata = 0;
    cs = caseSensitive;
    wc = wildcard;
    compile();
}

/*!
  Constructs a regular expression which is a copy of \e r.
  \sa operator=(const QRegExp&)
*/


qt'QRegExp::QRegExp() (./qt-2.1.0/src/tools/qregexp.cpp:195)

QRegExp::QRegExp( const QRegExp &r )
{
    rxstring = r.pattern();
    rxdata = 0;
    cs = r.caseSensitive();
    wc = r.wildcard();
    compile();
}

/*!
  Destructs the regular expression and cleans up its internal data.
*/


qt'QRegExp::~QRegExp() (./qt-2.1.0/src/tools/qregexp.cpp:208)

QRegExp::~QRegExp()
{
    if ( rxdata )                      // Avoid purify complaints
	delete [] rxdata;
}

/*!
  Copies the regexp \e r and returns a reference to this regexp.
  The case sensitivity and wildcard options are copied, as well.
*/


qt'QRegExp::setWildcard() (./qt-2.1.0/src/tools/qregexp.cpp:293)

void QRegExp::setWildcard( bool wildcard )
{
    if ( wildcard != wc ) {
	wc = wildcard;
	compile();
    }
}

/*!
  \fn bool QRegExp::caseSensitive() const

  Returns TRUE if case sensitivity is enabled, otherwise FALSE.	 The
  default is TRUE.

  \sa setCaseSensitive()
*/

/*!
  Enables or disables case sensitive matching.

  In case sensitive mode, "a.e" matches "axe" but not "Axe".

  See also: caseSensitive()
*/


qt'QRegExp::setCaseSensitive() (./qt-2.1.0/src/tools/qregexp.cpp:318)

void QRegExp::setCaseSensitive( bool enable )
{
    if ( cs != enable ) {
	cs = enable;
	compile();
    }
}


/*!
  \fn QString QRegExp::pattern() const
  Returns the pattern string of the regexp.
*/



qt'QRegExp::matchstr() (./qt-2.1.0/src/tools/qregexp.cpp:595)

const QChar *QRegExp::matchstr( uint *rxd, const QChar *str, uint strlength,
				const QChar *bol ) const
{
    int len = matchstring( rxd, str, strlength, bol, cs );
    if ( len < 0 )
	return 0;
    return str + len;
}

/*!
  Attempts to match in \e str, starting from position \e index.
  Returns the position of the match, or -1 if there was no match.

  If \e len is not a null pointer, the length of the match is stored in
  \e *len.

  If \e indexIsStart is TRUE (the default), the position \e index in
  the string will match the start-of-input primitive (^) in the
  regexp, if present. Otherwise, position 0 in \e str will match.

  Example:
  \code
    QRegExp r("[0-9]*\\.[0-9]+");		// matches floating point
    int len;
    r.match("pi = 3.1416", 0, &len);		// returns 5, len == 6
  \endcode
*/


qt'QRegExp::match() (./qt-2.1.0/src/tools/qregexp.cpp:623)

int QRegExp::match( const QString &str, int index, int *len,
		    bool indexIsStart ) const
{
    if ( !isValid() || isEmpty() )
	return -1;
    if ( str.length() < (uint)index )
	return -1;
    const QChar *start = str.unicode();
    const QChar *p = start + index;
    uint pl = str.length() - index;
    uint *d  = rxdata;
    int ep = -1;

    if ( *d == BOL ) {				// match from beginning of line
	ep = matchstring( d, p, pl, indexIsStart ? p : start, cs );
    } else {
	if ( *d & CHR ) {
	    QChar c( *d );
	    if ( !cs && !c.row() ) {		// case sensitive, # only 8bit
		while ( pl && ( p->row() || tolower(p->cell()) != c.cell() ) ) {
		    p++;
		    pl--;
		}
	    } else {				// case insensitive
		while ( pl && *p != c ) {
		    p++;
		    pl--;
		}
	    }
	}
	while( 1 ) {				// regular match
	    ep = matchstring( d, p, pl, indexIsStart ? start+index : start, cs );
	    if ( ep >= 0 )
		break;
	    if ( !pl )
		break;
	    p++;
	    pl--;
	}
    }
    if ( len )
	*len = ep >= 0 ? ep : 0;      // No match -> 0, for historical reasons
    return ep >= 0 ? (int)(p - start) : -1;		// return index;
}


//
// Translate wildcard pattern to standard regexp pattern.
// Ex:	 *.cpp	==> ^.*\.cpp$
//


qt'QRegExp::compile() (./qt-2.1.0/src/tools/qregexp.cpp:881)

void QRegExp::compile()
{
    if ( rxdata ) {				// delete old data
	delete [] rxdata;
	rxdata = 0;
    }
    if ( rxstring.isEmpty() ) {			// no regexp pattern set
	error = PatNull;
	return;
    }

    error = PatOk;				// assume pattern is ok

    QString pattern;
    if ( wc )
	pattern = wc2rx(rxstring);
    else
	pattern = rxstring;
    const QChar *start = pattern.unicode();	// pattern pointer
    const QChar *p = start;			// pattern pointer
    uint pl = pattern.length();
    uint *d = rxarray;				// data pointer
    uint *prev_d = 0;