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