OSDN Git Service

crystaledit: Make almost the same code into a common function
[winmerge-jp/winmerge-jp.git] / Externals / crystaledit / editlib / utils / cregexp.h
1 ///////////////////////////////////////////////////////////////////////////
2 //  File:    regexp.h
3 //  Version: 1.1.0.4
4 //  Updated: 19-Jul-1998
5 //
6 //  Copyright:  Marko Macek
7 //  E-mail:     Marko.Macek@gmx.net or mark@hermes.si
8 //
9 //  Some handy stuff to deal with regular expressions
10 //
11 //  You are free to use or modify this code to the following restrictions:
12 //  - Acknowledge me somewhere in your about box, simple "Parts of code by.."
13 //  will be enough. If you can't (or don't want to), contact me personally.
14 //  - LEAVE THIS HEADER INTACT
15 ////////////////////////////////////////////////////////////////////////////
16
17 #pragma once
18
19 /*
20  * Operator:
21  *
22  * ^            Match the beginning of line
23  * $            Match the end of line
24  * .            Match any character
25  * [ ]          Match characters in set
26  * [^ ]         Match characters not in set
27  * ?            Match previous pattern 0 or 1 times (greedy)
28  * |            Match previous or next pattern
29  * @            Match previous pattern 0 or more times (non-greedy)
30  * #            Match previous pattern 1 or more times (non-greedy)
31  * *            Match previous pattern 0 or more times (greedy)
32  * +            Match previous pattern 1 or more times (greedy)
33  * { }          Group characters to form one pattern
34  * ( )          Group and remember
35  * \            Quote next character (only of not a-z)
36  * <            Match beginning of a word
37  * >            Match end of a word
38  * \x##         Match character with ASCII code ## (hex)
39  * \N###        Match ascii code ### (dec)
40  * \o###        Match ascii code
41  * \a           Match \a              \r           Match 0x13 (cr)
42  * \b           Match \b              \t           Match 0x09 (tab)
43  * \f           Match \f              \v           Match \v
44  * \n           Match 0x10 (lf)       \e           Match escape (^E)
45  * \s           Match whitespace (cr/lf/tab/space)
46  * \S           Match nonwhitespace (!\S)
47  * \w           Match word character
48  * \W           Match non-word character
49  * \d           Match digit character
50  * \D           Match non-digit character
51  * \U           Match uppercase
52  * \L           Match lowercase
53  * \C           Match case sensitively from here on
54  * \c           Match case ingnore from here on
55  */
56
57 #define RE_NOTHING         0  // nothing
58 #define RE_JUMP            1  // jump to
59 #define RE_BREAK           2  // break |
60 #define RE_ATBOL           3  // match at beginning of line
61 #define RE_ATEOL           4  // match at end of line
62 #define RE_ATBOW           5  // match beginning of word
63 #define RE_ATEOW           6  // match end of word
64 #define RE_CASE            7  // match case sensitively from here
65 #define RE_NCASE           8  // ignore case from here.
66 #define RE_END            31  // end of regexp
67
68 #define RE_ANY      (32 +  1) // match any character
69 #define RE_INSET    (32 +  2) // match if in set
70 #define RE_NOTINSET (32 +  3) // match if not in set
71 #define RE_CHAR     (32 +  4) // match character string
72 #define RE_WSPACE   (32 +  5) // match whitespace
73 #define RE_NWSPACE  (32 +  6) // match whitespace
74 #define RE_UPPER    (32 +  7) // match uppercase
75 #define RE_LOWER    (32 +  8) // match lowercase
76 #define RE_DIGIT    (32 +  9) // match digit
77 #define RE_NDIGIT   (32 + 10) // match non-digit
78 #define RE_WORD     (32 + 11) // match word
79 #define RE_NWORD    (32 + 12) // match non-word
80
81 #define RE_GROUP         256  // grouping
82 #define RE_OPEN          512  // open (
83 #define RE_CLOSE        1024  // close )
84 #define RE_MEM          2048  // store () match
85
86 #define RE_BRANCH       4096
87 #define RE_GREEDY       2048  // do a greedy match (as much as possible)
88
89 #define NSEXPS            64  // for replace only 0-9
90
91 #define RX_CASE         1  // matchcase
92
93 typedef struct _RxNode RxNode;
94
95 struct _RxNode;
96
97 typedef struct {
98     ptrdiff_t Open[NSEXPS];    // -1 = not matched
99     ptrdiff_t Close[NSEXPS];
100 } RxMatchRes;
101
102 RxNode EDITPADC_CLASS *RxCompile(LPCTSTR Regexp, unsigned int RxOpt = RX_CASE);
103 int EDITPADC_CLASS RxExec(RxNode *Regexp, LPCTSTR Data, size_t Len, LPCTSTR Start, RxMatchRes *Match);
104 int EDITPADC_CLASS RxReplace(LPCTSTR rep, LPCTSTR Src, int len, RxMatchRes match, LPTSTR *Dest, int *Dlen);
105 void EDITPADC_CLASS RxFree(RxNode *Node);
106