41 NSAssert(![NSThread respondsToSelector:
@selector(isMainThread)] || [[NSThread currentThread] isMainThread],
@"OORegExpMatcher may only be used on the main thread.");
54 if ((
self = [super
init]))
56 const char *argumentNames[2] = {
"string",
"regexp" };
57 unsigned codeLine = __LINE__ + 1;
58 NSString *code =
@"return regexp.test(string);";
67 argumentNames:argumentNames
68 fileName:[@__FILE__ lastPathComponent]
93- (BOOL) string:(NSString *)string matchesExpression:(NSString *)regExp
95 return [
self string:string matchesExpression:regExp flags:0];
99- (BOOL) string:(NSString *)string matchesExpression:(NSString *)regExp flags:(NSUInteger)flags
101 NSAssert(![NSThread respondsToSelector:
@selector(isMainThread)] || [[NSThread currentThread] isMainThread],
@"OORegExpMatcher may only be used on the main thread.");
103 size_t expLength = [regExp length];
115 buffer = malloc(expLength *
sizeof *buffer);
117 [regExp getCharacters:buffer];
120 JSObject *regExpObj = JS_NewUCRegExpObjectNoStatics(context, buffer, expLength, (uintN)flags);
127 BOOL result = [_tester evaluatePredicateWithContext:context
129 arguments:[NSArray arrayWithObjects:string, _cachedRegExpObject, nil]];
139@implementation NSString (OORegExpMatcher)
141- (BOOL) oo_matchesRegularExpression:(NSString *)regExp
OOINLINE JSContext * OOJSAcquireContext(void)
OOINLINE void OOJSRelinquishContext(JSContext *context)
static OORegExpMatcher * sActiveInstance
OOJavaScriptEngine * sharedEngine()
OOJSValue * _cachedRegExpObject
NSString * _cachedRegExpString
instancetype regExpMatcher()