28#include <Objectively/Hash.h>
29#include <Objectively/MutableArray.h>
30#include <Objectively/String.h>
34#define _Class _SimpleSelector
57 return str(this->pattern);
63static int hash(
const Object *self) {
67 return HashForCString(HASH_SEED, this->pattern);
73static _Bool
isEqual(
const Object *self,
const Object *other) {
75 if (super(Object, self,
isEqual, other)) {
84 return strcmp(this->pattern, that->
pattern) == 0;
90#pragma mark - SimpleSelector
101 self->
pattern = strtrim(pattern);
134static Array *
parse(
const char *sequence) {
136 MutableArray *simpleSelectors = $$(MutableArray, arrayWithCapacity, 4);
137 assert(simpleSelectors);
141 const char *c = sequence;
142 const char *delim = sequence;
144 const size_t size = strcspn(c,
"*.#:");
145 if (
size || *c ==
'*') {
149 pattern = strdup(
"*");
152 pattern = calloc(1,
size + 1);
155 strncpy(pattern, c,
size);
159 assert(simpleSelector);
162 assert(simpleSelector->
type);
166 $(simpleSelectors, addObject, simpleSelector);
168 release(simpleSelector);
173 c += strspn(c,
"*.#:");
177 return (Array *) simpleSelectors;
180#pragma mark - Class lifecycle
187 ((ObjectInterface *) clazz->interface)->dealloc =
dealloc;
188 ((ObjectInterface *) clazz->interface)->description =
description;
189 ((ObjectInterface *) clazz->interface)->hash =
hash;
190 ((ObjectInterface *) clazz->interface)->isEqual =
isEqual;
192 ((SimpleSelectorInterface *) clazz->interface)->initWithPattern =
initWithPattern;
193 ((SimpleSelectorInterface *) clazz->interface)->
parse =
parse;
205 clazz = _initialize(&(
const ClassDef) {
206 .name =
"SimpleSelector",
207 .superclass = _Object(),
210 .interfaceSize =
sizeof(SimpleSelectorInterface),
static String * description(const Object *self)
static _Bool isEqual(const Object *self, const Object *other)
static SimpleSelectorType simpleSelectorType(const char c)
static void dealloc(Object *self)
static void initialize(Class *clazz)
static int hash(const Object *self)
SimpleSelectorType
The types of SimpleSelectors.
@ SimpleSelectorTypePseudo
@ SimpleSelectorTypeClass
@ SimpleSelectorTypeUniversal
CollectionView * init(CollectionView *self, const SDL_Rect *frame)
Initializes this CollectionView with the specified frame and style.
SDL_Size size(const Image *self)
Array * parse(const char *rules)
Parses the null-terminated C string of Selector rules into an Array of Selectors.
Array * parse(const char *sequence)
SimpleSelectorType type
The SimpleSelectorType.
Class * _SimpleSelector(void)
The SimpleSelector archetype.
SimpleSelector * initWithPattern(SimpleSelector *self, const char *pattern)
Initializes this SimpleSelector.
char * pattern
The pattern, as provided by the user.