|
46 | 46 | (i/defcfn cre2_strings_to_ranges) |
47 | 47 | ) |
48 | 48 |
|
49 | | -(def optmap |
| 49 | +(def cre2_optmap |
50 | 50 | { :ascii #(cre2_set_encoding % 2) |
51 | 51 | :posix #(cre2_opt_set_posix_syntax % 1) |
52 | 52 | :longest_match #(cre2_opt_set_longest_match % 1) |
|
57 | 57 | :never_capture #(do %) ;; ?? |
58 | 58 | :ignore_case #(cre2_opt_set_case_sensitive % 0) }) |
59 | 59 |
|
60 | | -(defn- cre2-opts [opts] |
| 60 | +(defn cre2_make_opts [opts] |
61 | 61 | (let [opt (cre2_opt_new)] |
62 | | - (doseq [key opts] ((key optmap) opt)) |
| 62 | + (doseq [key opts] ((key cre2_optmap) opt)) |
63 | 63 | opt)) |
64 | 64 |
|
65 | | - |
66 | | -(defn match |
| 65 | +(defn cre2_run_match |
67 | 66 | [pattern text] |
68 | | - (cre2_match |
69 | | - pattern |
70 | | - text |
71 | | - (count text) |
72 | | - 0 |
73 | | - (count text) |
74 | | - 1 ;; anchor 1 - no, 2 - start, 3 - both |
75 | | - (cre2_string_t) |
76 | | - (+ 1 (cre2_num_capturing_groups pattern)))) |
77 | | - |
78 | | -(defn regex |
79 | | - {:doc "Returns internal representation for regular |
80 | | - expression, used in matching functions." |
81 | | - :signatures [[rexeg-str opts]]} |
82 | | - [regex-str opts] |
83 | | - (re-pattern regex-str opts)) |
| 67 | + (= 1 |
| 68 | + (cre2_match pattern |
| 69 | + text (count text) |
| 70 | + 0 (count text) |
| 71 | + 1 ;; anchor 1 - no, 2 - start, 3 - both |
| 72 | + (cre2_string_t) |
| 73 | + (+ 1 (cre2_num_capturing_groups pattern))))) |
84 | 74 |
|
85 | 75 | (defprotocol IRegex |
86 | | - (re-matches [r s]) |
87 | | - (re-find [r s])) |
| 76 | + (re-matches [r t])) |
88 | 77 |
|
89 | | -(defrecord CRE2Regex [pattern opts] |
| 78 | +(deftype CRE2Regex [pattern opts] |
90 | 79 | IFinalize |
91 | 80 | (-finalize! [this] |
92 | | - (println "dropping cre2 obj " this) |
93 | 81 | (cre2_opt_delete opts) |
94 | 82 | (cre2_delete pattern)) |
95 | 83 |
|
96 | | - IRegex) |
| 84 | + IRegex |
| 85 | + (re-matches [_ text] (cre2_run_match pattern text))) |
97 | 86 |
|
98 | 87 | (def ^:dynamic *default-re-engine* :cre2) |
99 | 88 |
|
|
102 | 91 |
|
103 | 92 | ;; add cre2 to registry |
104 | 93 | (defmethod re-engine :cre2 [_ regex-str opts] |
105 | | - (let [copts (cre2-opts opts)] |
| 94 | + (let [copts (cre2_make_opts opts)] |
106 | 95 | (->CRE2Regex (cre2_new regex-str (count regex-str) copts) copts))) |
107 | 96 |
|
108 | | -;; dispatch on the right engine constructor via registry |
109 | | -(defn re-pattern |
110 | | - ([s o] (re-pattern s o *default-re-engine*)) |
111 | | - ([s o kw] (re-engine kw s o))) |
112 | | - |
| 97 | +(defn regex |
| 98 | + {:doc "Returns internal representation for regular |
| 99 | + expression, used in matching functions." |
| 100 | + :signatures [[rexeg-str opts]]} |
| 101 | + ([pattern opts] (regex pattern opts *default-re-engine*)) |
| 102 | + ([pattern opts engine] (re-engine engine pattern opts))) |
0 commit comments