README revision 1.1.1.1.2.2 1 1.1.1.1.2.2 yamt #
2 1.1.1.1.2.2 yamt # $Id: README,v 1.1.1.1.2.2 2008/06/04 02:04:02 yamt Exp $
3 1.1.1.1.2.2 yamt #
4 1.1.1.1.2.2 yamt # Copyright 1997, 1998, 1999 Computing Research Labs,
5 1.1.1.1.2.2 yamt # New Mexico State University
6 1.1.1.1.2.2 yamt #
7 1.1.1.1.2.2 yamt # Permission is hereby granted, free of charge, to any person obtaining a
8 1.1.1.1.2.2 yamt # copy of this software and associated documentation files (the "Software"),
9 1.1.1.1.2.2 yamt # to deal in the Software without restriction, including without limitation
10 1.1.1.1.2.2 yamt # the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 1.1.1.1.2.2 yamt # and/or sell copies of the Software, and to permit persons to whom the
12 1.1.1.1.2.2 yamt # Software is furnished to do so, subject to the following conditions:
13 1.1.1.1.2.2 yamt #
14 1.1.1.1.2.2 yamt # The above copyright notice and this permission notice shall be included in
15 1.1.1.1.2.2 yamt # all copies or substantial portions of the Software.
16 1.1.1.1.2.2 yamt #
17 1.1.1.1.2.2 yamt # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 1.1.1.1.2.2 yamt # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 1.1.1.1.2.2 yamt # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 1.1.1.1.2.2 yamt # THE COMPUTING RESEARCH LAB OR NEW MEXICO STATE UNIVERSITY BE LIABLE FOR ANY
21 1.1.1.1.2.2 yamt # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
22 1.1.1.1.2.2 yamt # OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
23 1.1.1.1.2.2 yamt # THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 1.1.1.1.2.2 yamt #
25 1.1.1.1.2.2 yamt
26 1.1.1.1.2.2 yamt
27 1.1.1.1.2.2 yamt Unicode and Regular Expressions
28 1.1.1.1.2.2 yamt Version 0.5
29 1.1.1.1.2.2 yamt
30 1.1.1.1.2.2 yamt This is a simple regular expression package for matching against Unicode text
31 1.1.1.1.2.2 yamt in UCS2 form. The implementation of this URE package is a variation on the
32 1.1.1.1.2.2 yamt RE->DFA algorithm done by Mark Hopkins (markh@csd4.csd.uwm.edu). Mark
33 1.1.1.1.2.2 yamt Hopkins' algorithm had the virtue of being very simple, so it was used as a
34 1.1.1.1.2.2 yamt model.
35 1.1.1.1.2.2 yamt
36 1.1.1.1.2.2 yamt ---------------------------------------------------------------------------
37 1.1.1.1.2.2 yamt
38 1.1.1.1.2.2 yamt Assumptions:
39 1.1.1.1.2.2 yamt
40 1.1.1.1.2.2 yamt o Regular expression and text already normalized.
41 1.1.1.1.2.2 yamt
42 1.1.1.1.2.2 yamt o Conversion to lower case assumes a 1-1 mapping.
43 1.1.1.1.2.2 yamt
44 1.1.1.1.2.2 yamt Definitions:
45 1.1.1.1.2.2 yamt
46 1.1.1.1.2.2 yamt Separator - any one of U+2028, U+2029, '\n', '\r'.
47 1.1.1.1.2.2 yamt
48 1.1.1.1.2.2 yamt Operators:
49 1.1.1.1.2.2 yamt . - match any character.
50 1.1.1.1.2.2 yamt * - match zero or more of the last subexpression.
51 1.1.1.1.2.2 yamt + - match one or more of the last subexpression.
52 1.1.1.1.2.2 yamt ? - match zero or one of the last subexpression.
53 1.1.1.1.2.2 yamt () - subexpression grouping.
54 1.1.1.1.2.2 yamt
55 1.1.1.1.2.2 yamt Notes:
56 1.1.1.1.2.2 yamt
57 1.1.1.1.2.2 yamt o The "." operator normally does not match separators, but a flag is
58 1.1.1.1.2.2 yamt available for the ure_exec() function that will allow this operator to
59 1.1.1.1.2.2 yamt match a separator.
60 1.1.1.1.2.2 yamt
61 1.1.1.1.2.2 yamt Literals and Constants:
62 1.1.1.1.2.2 yamt
63 1.1.1.1.2.2 yamt c - literal UCS2 character.
64 1.1.1.1.2.2 yamt \x.... - hexadecimal number of up to 4 digits.
65 1.1.1.1.2.2 yamt \X.... - hexadecimal number of up to 4 digits.
66 1.1.1.1.2.2 yamt \u.... - hexadecimal number of up to 4 digits.
67 1.1.1.1.2.2 yamt \U.... - hexadecimal number of up to 4 digits.
68 1.1.1.1.2.2 yamt
69 1.1.1.1.2.2 yamt Character classes:
70 1.1.1.1.2.2 yamt
71 1.1.1.1.2.2 yamt [...] - Character class.
72 1.1.1.1.2.2 yamt [^...] - Negated character class.
73 1.1.1.1.2.2 yamt \pN1,N2,...,Nn - Character properties class.
74 1.1.1.1.2.2 yamt \PN1,N2,...,Nn - Negated character properties class.
75 1.1.1.1.2.2 yamt
76 1.1.1.1.2.2 yamt POSIX character classes recognized:
77 1.1.1.1.2.2 yamt
78 1.1.1.1.2.2 yamt :alnum:
79 1.1.1.1.2.2 yamt :alpha:
80 1.1.1.1.2.2 yamt :cntrl:
81 1.1.1.1.2.2 yamt :digit:
82 1.1.1.1.2.2 yamt :graph:
83 1.1.1.1.2.2 yamt :lower:
84 1.1.1.1.2.2 yamt :print:
85 1.1.1.1.2.2 yamt :punct:
86 1.1.1.1.2.2 yamt :space:
87 1.1.1.1.2.2 yamt :upper:
88 1.1.1.1.2.2 yamt :xdigit:
89 1.1.1.1.2.2 yamt
90 1.1.1.1.2.2 yamt Notes:
91 1.1.1.1.2.2 yamt
92 1.1.1.1.2.2 yamt o Character property classes are \p or \P followed by a comma separated
93 1.1.1.1.2.2 yamt list of integers between 1 and 32. These integers are references to
94 1.1.1.1.2.2 yamt the following character properties:
95 1.1.1.1.2.2 yamt
96 1.1.1.1.2.2 yamt N Character Property
97 1.1.1.1.2.2 yamt --------------------------
98 1.1.1.1.2.2 yamt 1 _URE_NONSPACING
99 1.1.1.1.2.2 yamt 2 _URE_COMBINING
100 1.1.1.1.2.2 yamt 3 _URE_NUMDIGIT
101 1.1.1.1.2.2 yamt 4 _URE_NUMOTHER
102 1.1.1.1.2.2 yamt 5 _URE_SPACESEP
103 1.1.1.1.2.2 yamt 6 _URE_LINESEP
104 1.1.1.1.2.2 yamt 7 _URE_PARASEP
105 1.1.1.1.2.2 yamt 8 _URE_CNTRL
106 1.1.1.1.2.2 yamt 9 _URE_PUA
107 1.1.1.1.2.2 yamt 10 _URE_UPPER
108 1.1.1.1.2.2 yamt 11 _URE_LOWER
109 1.1.1.1.2.2 yamt 12 _URE_TITLE
110 1.1.1.1.2.2 yamt 13 _URE_MODIFIER
111 1.1.1.1.2.2 yamt 14 _URE_OTHERLETTER
112 1.1.1.1.2.2 yamt 15 _URE_DASHPUNCT
113 1.1.1.1.2.2 yamt 16 _URE_OPENPUNCT
114 1.1.1.1.2.2 yamt 17 _URE_CLOSEPUNCT
115 1.1.1.1.2.2 yamt 18 _URE_OTHERPUNCT
116 1.1.1.1.2.2 yamt 19 _URE_MATHSYM
117 1.1.1.1.2.2 yamt 20 _URE_CURRENCYSYM
118 1.1.1.1.2.2 yamt 21 _URE_OTHERSYM
119 1.1.1.1.2.2 yamt 22 _URE_LTR
120 1.1.1.1.2.2 yamt 23 _URE_RTL
121 1.1.1.1.2.2 yamt 24 _URE_EURONUM
122 1.1.1.1.2.2 yamt 25 _URE_EURONUMSEP
123 1.1.1.1.2.2 yamt 26 _URE_EURONUMTERM
124 1.1.1.1.2.2 yamt 27 _URE_ARABNUM
125 1.1.1.1.2.2 yamt 28 _URE_COMMONSEP
126 1.1.1.1.2.2 yamt 29 _URE_BLOCKSEP
127 1.1.1.1.2.2 yamt 30 _URE_SEGMENTSEP
128 1.1.1.1.2.2 yamt 31 _URE_WHITESPACE
129 1.1.1.1.2.2 yamt 32 _URE_OTHERNEUT
130 1.1.1.1.2.2 yamt
131 1.1.1.1.2.2 yamt o Character classes can contain literals, constants, and character
132 1.1.1.1.2.2 yamt property classes. Example:
133 1.1.1.1.2.2 yamt
134 1.1.1.1.2.2 yamt [abc\U10A\p1,3,4]
135 1.1.1.1.2.2 yamt
136 1.1.1.1.2.2 yamt ---------------------------------------------------------------------------
137 1.1.1.1.2.2 yamt
138 1.1.1.1.2.2 yamt Before using URE
139 1.1.1.1.2.2 yamt ----------------
140 1.1.1.1.2.2 yamt Before URE is used, two functions need to be created. One to check if a
141 1.1.1.1.2.2 yamt character matches a set of URE character properties, and one to convert a
142 1.1.1.1.2.2 yamt character to lower case.
143 1.1.1.1.2.2 yamt
144 1.1.1.1.2.2 yamt Stubs for these function are located in the urestubs.c file.
145 1.1.1.1.2.2 yamt
146 1.1.1.1.2.2 yamt Using URE
147 1.1.1.1.2.2 yamt ---------
148 1.1.1.1.2.2 yamt
149 1.1.1.1.2.2 yamt Sample pseudo-code fragment.
150 1.1.1.1.2.2 yamt
151 1.1.1.1.2.2 yamt ure_buffer_t rebuf;
152 1.1.1.1.2.2 yamt ure_dfa_t dfa;
153 1.1.1.1.2.2 yamt ucs2_t *re, *text;
154 1.1.1.1.2.2 yamt unsigned long relen, textlen;
155 1.1.1.1.2.2 yamt unsigned long match_start, match_end;
156 1.1.1.1.2.2 yamt
157 1.1.1.1.2.2 yamt /*
158 1.1.1.1.2.2 yamt * Allocate the dynamic storage needed to compile regular expressions.
159 1.1.1.1.2.2 yamt */
160 1.1.1.1.2.2 yamt rebuf = ure_buffer_create();
161 1.1.1.1.2.2 yamt
162 1.1.1.1.2.2 yamt for each regular expression in a list {
163 1.1.1.1.2.2 yamt re = next regular expression;
164 1.1.1.1.2.2 yamt relen = length(re);
165 1.1.1.1.2.2 yamt
166 1.1.1.1.2.2 yamt /*
167 1.1.1.1.2.2 yamt * Compile the regular expression with the case insensitive flag
168 1.1.1.1.2.2 yamt * turned on.
169 1.1.1.1.2.2 yamt */
170 1.1.1.1.2.2 yamt dfa = ure_compile(re, relen, 1, rebuf);
171 1.1.1.1.2.2 yamt
172 1.1.1.1.2.2 yamt /*
173 1.1.1.1.2.2 yamt * Look for the first match in some text. The matching will be done
174 1.1.1.1.2.2 yamt * in a case insensitive manner because the expression was compiled
175 1.1.1.1.2.2 yamt * with the case insensitive flag on.
176 1.1.1.1.2.2 yamt */
177 1.1.1.1.2.2 yamt if (ure_exec(dfa, 0, text, textlen, &match_start, &match_end))
178 1.1.1.1.2.2 yamt printf("MATCH: %ld %ld\n", match_start, match_end);
179 1.1.1.1.2.2 yamt
180 1.1.1.1.2.2 yamt /*
181 1.1.1.1.2.2 yamt * Look for the first match in some text, ignoring non-spacing
182 1.1.1.1.2.2 yamt * characters.
183 1.1.1.1.2.2 yamt */
184 1.1.1.1.2.2 yamt if (ure_exec(dfa, URE_IGNORE_NONSPACING, text, textlen,
185 1.1.1.1.2.2 yamt &match_start, &match_end))
186 1.1.1.1.2.2 yamt printf("MATCH: %ld %ld\n", match_start, match_end);
187 1.1.1.1.2.2 yamt
188 1.1.1.1.2.2 yamt /*
189 1.1.1.1.2.2 yamt * Free the DFA.
190 1.1.1.1.2.2 yamt */
191 1.1.1.1.2.2 yamt ure_free_dfa(dfa);
192 1.1.1.1.2.2 yamt }
193 1.1.1.1.2.2 yamt
194 1.1.1.1.2.2 yamt /*
195 1.1.1.1.2.2 yamt * Free the dynamic storage used for compiling the expressions.
196 1.1.1.1.2.2 yamt */
197 1.1.1.1.2.2 yamt ure_free_buffer(rebuf);
198 1.1.1.1.2.2 yamt
199 1.1.1.1.2.2 yamt ---------------------------------------------------------------------------
200 1.1.1.1.2.2 yamt
201 1.1.1.1.2.2 yamt Mark Leisher <mleisher (at] crl.nmsu.edu>
202 1.1.1.1.2.2 yamt 29 March 1997
203 1.1.1.1.2.2 yamt
204 1.1.1.1.2.2 yamt ===========================================================================
205 1.1.1.1.2.2 yamt
206 1.1.1.1.2.2 yamt CHANGES
207 1.1.1.1.2.2 yamt -------
208 1.1.1.1.2.2 yamt
209 1.1.1.1.2.2 yamt Version: 0.5
210 1.1.1.1.2.2 yamt Date : 21 September 1999
211 1.1.1.1.2.2 yamt ==========================
212 1.1.1.1.2.2 yamt 1. Added copyright stuff and put in CVS.
213