home *** CD-ROM | disk | FTP | other *** search
/ CD Actual Thematic 25: Programming / pc_actual_25.iso / C_C++ / VisualProgrammingArmoury / data1.cab / MyFileGroup / INCLUDE / RegExp.hpp < prev    next >
Encoding:
C/C++ Source or Header  |  1999-06-23  |  4.8 KB  |  147 lines

  1. #ifndef _INC_REGEXP_HPP
  2. #define _INC_REGEXP_HPP
  3. #ifdef __GNUG__
  4.  
  5. #ifdef BUILD_TCCORE
  6. #define TCCORELIB    dllexport
  7. #else
  8. #ifdef BUILD_LOCAL
  9. #define TCCORELIB
  10. #else
  11. #define TCCORELIB    dllimport
  12. #endif
  13. #endif
  14.  
  15. #else
  16.  
  17. #ifdef BUILD_TCCORE
  18. #define TCCORELIB    __declspec(dllexport)
  19. #else
  20. #ifdef BUILD_LOCAL
  21. #define TCCORELIB
  22. #else
  23. #define TCCORELIB    __declspec(dllimport)
  24. #endif
  25. #endif
  26.  
  27. #endif
  28.  
  29. // **********************************************************************
  30. class TCCORELIB TC_CRegExp 
  31. {
  32. public:
  33.     enum { MAX_PAIRS = 10 };
  34. /*
  35.  
  36. REGULAR EXPRESSION SYNTAX:
  37.  
  38. A regular expression is zero or more branches, separated by `|`.
  39. It matches anything that matches one of the branches.
  40.  
  41. A branch is zero or more pieces, concatenated.
  42. It matches a match for the first, followed by a match for the second, etc.
  43.  
  44. A piece is an atom possibly followed by `*`, `+`, or `?`.
  45.  
  46. An atom followed by `*` matches a sequence of 0 or more matches of the atom.
  47. An atom followed by `+` matches a sequence of 1 or more matches of the atom.
  48. An atom followed by `?` matches a match of the atom, or the null string.
  49.  
  50. An atom is:
  51.     -    a regular expression in parentheses (matching a match for the regular expression)
  52.     -    range (see below)
  53.     -    `.` (matching any single character)
  54.     -    `^` (matching the null string at the beginning of the input string)
  55.     -    `$` (matching the null string at the end of the input string)
  56.     -    `\e` followed by a single character (matching that character)
  57.     -    a single character with no other significance (matching that character).
  58.  
  59. A range is a sequence of characters enclosed in `[]`.
  60. It normally matches any single character from the sequence.
  61.  
  62. If the sequence begins with `^`, it matches any single character not from the rest of the sequence.
  63.  
  64. If two characters in the sequence are separated by `-`, this is shorthand
  65. for the full list of ASCII characters between them (e.g. `[0-9]` matches any decimal digit).
  66.  
  67. To include a literal `]` in the sequence, make it the first character
  68. (following a possible `^`).
  69.  
  70. To include a literal `-`, make it the first or last character.
  71.  
  72. */
  73.  
  74. // **********************************************************************
  75. public: 
  76. struct IntPair 
  77. {
  78. public:  long position ;
  79. public:  long length ;
  80.  
  81. }; // end of class IntPair
  82.  
  83. // **********************************************************************
  84.  
  85. // **********************************************************************
  86. public: 
  87. struct RegExpStruct 
  88. {
  89. public:  char * startp [MAX_PAIRS];
  90. public:  char * endp [MAX_PAIRS];
  91. public:  char regstart ;
  92. public:  char reganch ;
  93. public:  char * regmust ;
  94. public:  int regmlen ;
  95. public:  char program [1];
  96.  
  97. }; // end of class RegExpStruct
  98.  
  99. // **********************************************************************
  100. protected:  RegExpStruct* m_RegExp ;
  101. protected:  TC_CString m_RegExpString ;
  102. protected:  TC_CString m_LastError ;
  103. protected:  char* m_RegParse ;
  104. protected:  int m_RegNPar ;
  105. protected:  char m_RegDummy ;
  106. protected:  char* m_RegCode ;
  107. protected:  long m_RegSize ;
  108. protected:  char * m_RegInput ;
  109. protected:  char * m_RegBOL ;
  110. protected:  char ** m_RegStartP ;
  111. protected:  char ** m_RegEndP ;
  112. protected:  void regerror (char* s)  ;
  113. protected:  char* reg (int paren, int* flagp)  ;
  114. protected:  char* regbranch (int* flagp)  ;
  115. protected:  char* regpiece (int* flagp)  ;
  116. protected:  char* regatom (int* flagp)  ;
  117. protected:  char* regnode (char op)  ;
  118. protected:  void regc (char b)  ;
  119. protected:  void reginsert (char op, char* opnd)  ;
  120. protected:  void regtail (char *p, char *val)  ;
  121. protected:  void regoptail (char *p, char *val)  ;
  122. protected:  int regtry (RegExpStruct *prog, char *string)  ;
  123. protected:  int regmatch (char *prog)  ;
  124. protected:  int regrepeat (char *p)  ;
  125. protected:  char * regnext (register char *p)  ;
  126. protected:  TC_CRegExp::RegExpStruct* _regcomp (char* exp)  ;
  127. protected:  int _regexec (register RegExpStruct *prog, register char *string)  ;
  128. protected:  void _regsub (RegExpStruct *prog, char *source, char *dest)  ;
  129. public:   TC_CRegExp ()  ;
  130. public:   TC_CRegExp (const char* regExp)  ;
  131. public:   TC_CRegExp (TC_CRegExp& r)  ;
  132. public:   ~TC_CRegExp ()  ;
  133. public:  BOOL SetRegExp (const char* regExp)  ;
  134. public:  BOOL SetRegExp (TC_CRegExp& regExp)  ;
  135. public:  TC_CRegExp& operator= (const char* regExp)  ;
  136. public:  TC_CRegExp& operator= (TC_CRegExp& regExp)  ;
  137. public:  long IndexIn (const char* string, long beginFrom  = 0)  ;
  138. public:  long Match (const char* string, long& length, long beginFrom = 0)  ;
  139. public:  long Match (const char* string, IntPair segs [MAX_PAIRS], long beginFrom = 0)  ;
  140. public:  TC_CString & LastError ()  ;
  141.  
  142. }; // end of class TC_CRegExp
  143.  
  144. // **********************************************************************
  145.  
  146. #endif // _INC_REGEXP_HPP
  147.