Proposed C API for Regular Expressions
Andy Heninger <[email protected]> Fri, 12 Mar 2004 15:16:39 -0800
| Newsgroups | gmane.comp.lib.icu.general |
|---|---|
| Message-ID | <[email protected]> |
A proposal for a C API to ICU regular expressions is here:
http://oss.software.ibm.com/cvs/icu/icu/source/i18n/unicode/uregex.h?rev=1.1&content-type=text/x-cvsweb-markup
This is brand new; It's certain to have things wrong, and things that
could be done better, or more simply or in ways that are easier to
understand or use.
The functions pretty much follow those from the C++ API. The main areas
of difference are these:
1) The C++ API has two main classes, RegexPattern, representing a
compiled regexp pattern, and RegexMatcher, representing the state of a
specific match. Patterns are read-only and shareable by multiple
matchers. This structure was copied from the Java JDK regular
expression package.
For C, I have proposed combining these two concepts into one. Doing so
makes user code simpler, and doesn't appear to have any real
disadvantages. Internally, the implementation still has both types, and
compiled patterns can still be shared when appropriate. (They are
shared when a regexp object is cloned.)
In our C++ API, without Java's garbage collection, managing the
dependency between a pattern and the Matcher objects that use it is a
manual and potentially error prone process. With the C API, it will all
be automatic.
2) A reduction in the number of overloaded function variants.
Overloads are awkward to translate to C because the function name must
change too. The upshot is longer parameter lists to some functions, as
the simplified overloads and/or defaulted parameters from C++ are gone.
3) String types change from class UnicodeString to (UChar *) everywhere.
So please, everyone, let me know what you think.
Thanks,
-- Andy Heninger
[email protected]