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