Macros | Functions | Variables
qregexp.cpp File Reference
#include "qregexp.h"
#include <ctype.h>
#include <stdlib.h>

Go to the source code of this file.

Macros

#define GEN(x)   *d++ = (x)
 

Functions

static bool iswordchar (int x)
 
static bool matchcharclass (uint *rxd, char c)
 
static int matchstring (uint *rxd, const char *str, uint strlength, const char *bol, bool cs)
 
static QCString wc2rx (const QCString &pattern)
 
static uint char_val (const char **str, uint *strlength)
 

Variables

const uint END = 0x00000000
 
const uint PWS = 0x10010000
 
const uint PDG = 0x10020000
 
const uint CCL = 0x20010000
 
const uint CCN = 0x20020000
 
const uint CHR = 0x40000000
 
const uint BOL = 0x80010000
 
const uint EOL = 0x80020000
 
const uint BOW = 0x80030000
 
const uint EOW = 0x80040000
 
const uint ANY = 0x80050000
 
const uint CLO = 0x80070000
 
const uint OPT = 0x80080000
 
const uint MCC = 0x20000000
 
const uint MCD = 0xffff0000
 
const uint MVL = 0x0000ffff
 
const int PatOk = 0
 
const int PatNull = 1
 
const int PatSyntax = 2
 
const int PatOverflow = 4
 
static const int maxlen = 1024
 
static uint rxarray [maxlen]
 

Macro Definition Documentation

#define GEN (   x)    *d++ = (x)

Function Documentation

static uint char_val ( const char **  str,
uint strlength 
)
static

Definition at line 749 of file qregexp.cpp.

750 {
751  const char *p = *str;
752  uint pl = *strlength;
753  uint len = 1;
754  uint v = 0;
755  if ( (char)*p == '\\' ) { // escaped code
756  p++;
757  pl--;
758  if ( !pl ) { // it is just a '\'
759  (*str)++;
760  (*strlength)--;
761  return '\\';
762  }
763  len++; // length at least 2
764  int i;
765  char c;
766  char ch = tolower((char)*p);
767  switch ( ch ) {
768  case 'b': v = '\b'; break; // bell
769  case 'f': v = '\f'; break; // form feed
770  case 'n': v = '\n'; break; // newline
771  case 'r': v = '\r'; break; // return
772  case 't': v = '\t'; break; // tab
773  case 's': v = PWS; break; // whitespace charclass
774  case 'd': v = PDG; break; // digit charclass
775  case '<': v = BOW; break; // word beginning matcher
776  case '>': v = EOW; break; // word ending matcher
777 
778  case 'x': { // hex code
779  p++;
780  pl--;
781  for ( i = 0; (i < 4) && pl; i++ ) { //up to 4 hex digits
782  c = tolower((char)*p);
783  bool a = ( c >= 'a' && c <= 'f' );
784  if ( (c >= '0' && c <= '9') || a ) {
785  v <<= 4;
786  v += a ? 10 + c - 'a' : c - '0';
787  len++;
788  }
789  else {
790  break;
791  }
792  p++;
793  pl--;
794  }
795  }
796  break;
797 
798  default: {
799  if ( ch >= '0' && ch <= '7' ) { //octal code
800  len--;
801  for ( i = 0; (i < 3) && pl; i++ ) { // up to 3 oct digits
802  c = (char)*p;
803  if ( c >= '0' && c <= '7' ) {
804  v <<= 3;
805  v += c - '0';
806  len++;
807  }
808  else {
809  break;
810  }
811  p++;
812  pl--;
813  }
814  }
815  else { // not an octal number
816  v = (uint)*p; //(((uint)(p->row())) << 8) | ((uint)p->cell());
817  }
818  }
819  }
820  } else {
821  v = (uint)*p; //(((uint)(p->row())) << 8) | ((uint)p->cell());
822  }
823  *str += len;
824  *strlength -= len;
825  return v;
826 }
const uint PWS
Definition: qregexp.cpp:139
const uint PDG
Definition: qregexp.cpp:140
const uint BOW
Definition: qregexp.cpp:146
const double a
p
Definition: test.py:223
unsigned uint
Definition: qglobal.h:351
static QCString str
const uint EOW
Definition: qregexp.cpp:147
static bool iswordchar ( int  x)
inlinestatic

Definition at line 356 of file qregexp.cpp.

357 {
358  return isalnum(x) || x == '_'; //# Only 8-bit support
359 }
list x
Definition: train.py:276
static bool matchcharclass ( uint rxd,
char  c 
)
static

Definition at line 367 of file qregexp.cpp.

368 {
369  uint *d = rxd;
370  uint clcode = *d & MCD;
371  bool neg = clcode == CCN;
372  if ( clcode != CCL && clcode != CCN)
373  qWarning("QRegExp: Internal error, please report to qt-bugs@trolltech.com");
374  uint numFields = *d & MVL;
375  uint cval = (unsigned char)c; //(((uint)(c.row())) << 8) | ((uint)c.cell());
376  bool found = FALSE;
377  for ( int i = 0; i < (int)numFields; i++ ) {
378  d++;
379  if ( *d == PWS && isspace(c) ) {
380  found = TRUE;
381  break;
382  }
383  if ( *d == PDG && isdigit(c) ) {
384  found = TRUE;
385  break;
386  }
387  else {
388  uint from = ( *d & MCD ) >> 16;
389  uint to = *d & MVL;
390  if ( (cval >= from) && (cval <= to) ) {
391  found = TRUE;
392  break;
393  }
394  }
395  }
396  return neg ? !found : found;
397 }
const uint PWS
Definition: qregexp.cpp:139
const bool FALSE
Definition: qglobal.h:370
void qWarning(const char *msg,...)
Definition: qglobal.cpp:409
const uint MVL
Definition: qregexp.cpp:154
const uint PDG
Definition: qregexp.cpp:140
const uint CCN
Definition: qregexp.cpp:142
const uint MCD
Definition: qregexp.cpp:153
const uint CCL
Definition: qregexp.cpp:141
unsigned uint
Definition: qglobal.h:351
const bool TRUE
Definition: qglobal.h:371
static int matchstring ( uint rxd,
const char *  str,
uint  strlength,
const char *  bol,
bool  cs 
)
static

p->row() &&

Definition at line 405 of file qregexp.cpp.

407 {
408  const char *p = str;
409  const char *start = p;
410  uint pl = strlength;
411  uint *d = rxd;
412 
413  //### in all cases here: handle pl == 0! (don't read past strlen)
414  while ( *d ) {
415  if ( *d & CHR ) { // match char
416  if ( !pl )
417  return -1;
418  char c = *d;
419  if ( !cs /*&& !c.row()*/ ) { // case insensitive, #Only 8bit
420  if ( tolower(*p) != c )
421  return -1;
422  p++;
423  pl--;
424  } else { // case insensitive
425  if ( *p != c )
426  return -1;
427  p++;
428  pl--;
429  }
430  d++;
431  }
432  else if ( *d & MCC ) { // match char class
433  if ( !pl )
434  return -1;
435  if ( !matchcharclass( d, *p ) )
436  return -1;
437  p++;
438  pl--;
439  d += (*d & MVL) + 1;
440  }
441  else switch ( *d++ ) {
442  case PWS: // match whitespace
443  if ( !pl || !isspace(*p) )
444  return -1;
445  p++;
446  pl--;
447  break;
448  case PDG: // match digits
449  if ( !pl || !isdigit(*p) )
450  return -1;
451  p++;
452  pl--;
453  break;
454  case ANY: // match anything
455  if ( !pl )
456  return -1;
457  p++;
458  pl--;
459  break;
460  case BOL: // match beginning of line
461  if ( p != bol )
462  return -1;
463  break;
464  case EOL: // match end of line
465  if ( pl )
466  return -1;
467  break;
468  case BOW: // match beginning of word
469  if ( !iswordchar(*p) || (p > bol && iswordchar(*(p-1)) ) )
470  return -1;
471  break;
472  case EOW: // match end of word
473  if ( iswordchar(*p) || p == bol || !iswordchar(*(p-1)) )
474  return -1;
475  break;
476  case CLO: // Kleene closure
477  {
478  const char *first_p = p;
479  if ( *d & CHR ) { // match char
480  char c = *d;
481  if ( !cs /*&& !c.row()*/ ) { // case insensitive, #only 8bit
482  while ( pl /*&& !p->row()*/ && tolower(*p)==c ) {
483  p++;
484  pl--;
485  }
486  }
487  else { // case sensitive
488  while ( pl && *p == c ) {
489  p++;
490  pl--;
491  }
492  }
493  d++;
494  }
495  else if ( *d & MCC ) { // match char class
496  while( pl && matchcharclass( d, *p ) ) {
497  p++;
498  pl--;
499  }
500  d += (*d & MVL) + 1;
501  }
502  else if ( *d == PWS ) {
503  while ( pl && isspace(*p) ) {
504  p++;
505  pl--;
506  }
507  d++;
508  }
509  else if ( *d == PDG ) {
510  while ( pl && isdigit(*p) ) {
511  p++;
512  pl--;
513  }
514  d++;
515  }
516  else if ( *d == ANY ) {
517  p += pl;
518  pl = 0;
519  d++;
520  }
521  else {
522  return -1; // error
523  }
524  d++; // skip CLO's END
525  while ( p >= first_p ) { // go backwards
526  int end = matchstring( d, p, pl, bol, cs );
527  if ( end >= 0 )
528  return ( (int)(p - start) ) + end;
529  if ( !p )
530  return -1;
531  --p;
532  ++pl;
533  }
534  }
535  return -1;
536  case OPT: // optional closure
537  {
538  const char *first_p = p;
539  if ( *d & CHR ) { // match char
540  char c = *d;
541  if ( !cs /*&& !c.row()*/ ) { // case insensitive, #only 8bit
542  if ( pl && /*!p->row() &&*/ tolower(*p) == c ) {
543  p++;
544  pl--;
545  }
546  }
547  else { // case sensitive
548  if ( pl && *p == c ) {
549  p++;
550  pl--;
551  }
552  }
553  d++;
554  }
555  else if ( *d & MCC ) { // match char class
556  if ( pl && matchcharclass( d, *p ) ) {
557  p++;
558  pl--;
559  }
560  d += (*d & MVL) + 1;
561  }
562  else if ( *d == PWS ) {
563  if ( pl && isspace(*p) ) {
564  p++;
565  pl--;
566  }
567  d++;
568  }
569  else if ( *d == PDG ) {
570  if ( pl && isdigit(*p) ) {
571  p++;
572  pl--;
573  }
574  d++;
575  }
576  else if ( *d == ANY ) {
577  if ( pl ) {
578  p++;
579  pl--;
580  }
581  d++;
582  }
583  else {
584  return -1; // error
585  }
586  d++; // skip OPT's END
587  while ( p >= first_p ) { // go backwards
588  int end = matchstring( d, p, pl, bol, cs );
589  if ( end >= 0 )
590  return ( (int)(p - start) ) + end;
591  if ( !p )
592  return -1;
593  --p;
594  ++pl;
595  }
596  }
597  return -1;
598 
599  default: // error
600  return -1;
601  }
602  }
603  return (int)(p - start);
604 }
end
while True: pbar.update(maxval-len(onlies[E][S])) #print iS, "/", len(onlies[E][S]) found = False for...
static int matchstring(uint *rxd, const char *str, uint strlength, const char *bol, bool cs)
Definition: qregexp.cpp:405
const uint CLO
Definition: qregexp.cpp:149
const uint PWS
Definition: qregexp.cpp:139
const uint BOL
Definition: qregexp.cpp:144
static bool matchcharclass(uint *rxd, char c)
Definition: qregexp.cpp:367
const uint MVL
Definition: qregexp.cpp:154
const uint EOL
Definition: qregexp.cpp:145
const uint PDG
Definition: qregexp.cpp:140
const uint BOW
Definition: qregexp.cpp:146
const uint CHR
Definition: qregexp.cpp:143
static bool iswordchar(int x)
Definition: qregexp.cpp:356
p
Definition: test.py:223
const uint MCC
Definition: qregexp.cpp:152
const uint ANY
Definition: qregexp.cpp:148
const char * cs
unsigned uint
Definition: qglobal.h:351
static QCString str
const uint EOW
Definition: qregexp.cpp:147
const uint OPT
Definition: qregexp.cpp:150
static QCString wc2rx ( const QCString pattern)
static

Definition at line 707 of file qregexp.cpp.

708 {
709  int patlen = (int)pattern.length();
710  QCString wcpattern("^");
711 
712  char c;
713  for( int i = 0; i < patlen; i++ ) {
714  c = pattern[i];
715  switch ( (char)c ) {
716  case '*': // '*' ==> '.*'
717  wcpattern += '.';
718  break;
719  case '?': // '?' ==> '.'
720  c = '.';
721  break;
722  case '.': // quote special regexp chars
723  case '+':
724  case '\\':
725  case '$':
726  case '^':
727  wcpattern += '\\';
728  break;
729  case '[':
730  if ( (char)pattern[i+1] == '^' ) { // don't quote '^' after '['
731  wcpattern += '[';
732  c = pattern[i+1];
733  i++;
734  }
735  break;
736  }
737  wcpattern += c;
738 
739  }
740  wcpattern += '$';
741  return wcpattern; // return new regexp pattern
742 }
uint length() const
Definition: qcstring.h:195

Variable Documentation

const uint ANY = 0x80050000

Definition at line 148 of file qregexp.cpp.

const uint BOL = 0x80010000

Definition at line 144 of file qregexp.cpp.

const uint BOW = 0x80030000

Definition at line 146 of file qregexp.cpp.

const uint CCL = 0x20010000

Definition at line 141 of file qregexp.cpp.

const uint CCN = 0x20020000

Definition at line 142 of file qregexp.cpp.

const uint CHR = 0x40000000

Definition at line 143 of file qregexp.cpp.

const uint CLO = 0x80070000

Definition at line 149 of file qregexp.cpp.

const uint END = 0x00000000

Definition at line 138 of file qregexp.cpp.

const uint EOL = 0x80020000

Definition at line 145 of file qregexp.cpp.

const uint EOW = 0x80040000

Definition at line 147 of file qregexp.cpp.

const int maxlen = 1024
static

Definition at line 904 of file qregexp.cpp.

const uint MCC = 0x20000000

Definition at line 152 of file qregexp.cpp.

const uint MCD = 0xffff0000

Definition at line 153 of file qregexp.cpp.

const uint MVL = 0x0000ffff

Definition at line 154 of file qregexp.cpp.

const uint OPT = 0x80080000

Definition at line 150 of file qregexp.cpp.

const int PatNull = 1

Definition at line 161 of file qregexp.cpp.

const int PatOk = 0

Definition at line 160 of file qregexp.cpp.

const int PatOverflow = 4

Definition at line 163 of file qregexp.cpp.

const int PatSyntax = 2

Definition at line 162 of file qregexp.cpp.

const uint PDG = 0x10020000

Definition at line 140 of file qregexp.cpp.

const uint PWS = 0x10010000

Definition at line 139 of file qregexp.cpp.

uint rxarray[maxlen]
static

Definition at line 905 of file qregexp.cpp.