78 const Range range = { 0, strlen(this->pattern) };
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),
static Array * init(Array *self)
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 bool isKindOfClass(const Object *self, const Class *clazz)
static int options(RESTClient *self, const char *url, Data **data)
static Regexp * initWithPattern(Regexp *self, const char *pattern, int options)
static bool isEqual(const Object *self, const Object *other)
static bool matchesCharacters(const Regexp *self, const char *chars, int options, Range **ranges)
static bool matchesString(const Regexp *self, const String *string, int options, Range **ranges)
static String * description(const Object *self)
static void dealloc(Object *self)
static Object * copy(const Object *self)
static void initialize(Class *clazz)
Regexp * re(const char *pattern, int options)
static int hash(const Object *self)
Extended POSIX regular expressions.
static String * string(void)
static String * stringWithCharacters(const char *chars)
#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.
Object is the root Class of The Objectively Class hierarchy.
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.
bool matchesCharacters(const Regexp *self, const char *chars, int options, Range **matches)
Matches this regular expression against the given characters.
const char * pattern
The pattern.
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.