42 return (
Object *)
re(this->pattern, this->options);
78 const Range range = { 0, strlen(this->pattern) };
98 if (this->options == that->
options) {
99 return strcmp(this->pattern, that->
pattern) == 0;
116 self->
regex = calloc(1,
sizeof(regex_t));
119 const int err = regcomp(self->
regex, pattern, REG_EXTENDED | options);
138 regmatch_t matches[numberOfMatches];
140 const int err = regexec(self->
regex, chars, numberOfMatches, matches, options);
141 assert(err == 0 || err == REG_NOMATCH);
143 *ranges = calloc(numberOfMatches,
sizeof(
Range));
146 Range *range = *ranges;
147 const regmatch_t *match = matches;
148 for (
size_t i = 0; i < numberOfMatches; i++, range++, match++) {
151 range->
length = match->rm_eo - match->rm_so;
160 const int err = regexec(self->
regex, chars, 0, NULL, options);
161 assert(err == 0 || err == REG_NOMATCH);
177#pragma mark - Class lifecycle
207 .instanceSize =
sizeof(
Regexp),
208 .interfaceOffset = offsetof(
Regexp, interface),
209 .interfaceSize =
sizeof(RegexpInterface),
Class * _initialize(const ClassDef *def)
Initializes the given Class.
#define alloc(type)
Allocate and initialize and instance of type.
#define super(type, obj, method,...)
int HashForInteger(int hash, const long integer)
Accumulates the hash value of integer into hash.
int HashForBytes(int hash, const uint8_t *bytes, const Range range)
Accumulates the hash value of bytes into hash.
Utilities for calculating hash values.
#define HASH_SEED
The hash seed value.
static void initialize(Class *clazz)
Extended POSIX regular expressions.
#define do_once(once, block)
Executes the given block at most one time.
ClassDefs are passed to _initialize via an archetype to initialize a Class.
The runtime representation of a Class.
ident interface
The interface of the Class.
Condition * init(Condition *self)
Initializes this Condition.
MutableString * string(void)
Returns a new MutableString.
Object is the root Class of The Objectively Class hierarchy.
Class * _Object(void)
The Object archetype.
Object * copy(const Object *self)
Creates a shallow copy of this Object.
_Bool isKindOfClass(const Object *self, const Class *clazz)
Tests for Class hierarchy membership.
String * description(const Object *self)
_Bool isEqual(const Object *self, const Object *other)
Tests equality of the other Object.
int hash(const Object *self)
void dealloc(Object *self)
Frees all resources held by this Object.
A location and length into contiguous collections.
ssize_t location
The location.
Extended POSIX regular expressions.
ident regex
The backing regular expression.
const char * pattern
The pattern.
_Bool matchesCharacters(const Regexp *self, const char *chars, int options, Range **matches)
Matches this regular expression against the given characters.
Regexp * initWithPattern(Regexp *self, const char *pattern, int options)
Initializes this regular expression.
_Bool matchesString(const Regexp *self, const String *string, int options, Range **matches)
Matches this regular expression against the given String.
OBJECTIVELY_EXPORT Regexp * re(const char *pattern, int options)
A convenience function for instantiating Regexps.
Class * _Regexp(void)
The Regexp archetype.
int options
A bitwise-or of REG_ICASE, REG_NEWLINE.
size_t numberOfSubExpressions
The number of parenthesized sub-expressions.
char * chars
The backing null-terminated UTF-8 encoded character array.
String * stringWithCharacters(const char *chars)
Returns a new String by copying chars.