Oolite
Loading...
Searching...
No Matches
OORegExpMatcher.h
Go to the documentation of this file.
1/*
2
3OORegExpMatcher.h
4
5Regular expression utility built on top of JavaScript regexp objects in lieu
6of Objective-C regexp support. Not thread-safe.
7
8If we had a performance-critical need for regexps, I'd want a real library,
9but this will do for light usage.
10
11
12Copyright (C) 2010-2013 Jens Ayton
13
14Permission is hereby granted, free of charge, to any person obtaining a copy
15of this software and associated documentation files (the "Software"), to deal
16in the Software without restriction, including without limitation the rights
17to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
18copies of the Software, and to permit persons to whom the Software is
19furnished to do so, subject to the following conditions:
20
21The above copyright notice and this permission notice shall be included in all
22copies or substantial portions of the Software.
23
24THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
25IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
27AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
29OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30SOFTWARE.
31
32*/
33
34#import "OOFoundation.h"
35#if !OOJS_QUICKJS
36#include <jsapi.h>
37#endif
38
40
41#if OOJS_QUICKJS
42// Same values as SpiderMonkey's JSREG_FOLD and JSREG_MULTILINE.
43enum {
46};
47#else
48enum {
50 kOORegExpMultiLine = JSREG_MULTILINE
51};
52#endif
53
54@interface OORegExpMatcher : NSObject {
55@private
59 NSUInteger _cachedFlags;
60}
61
62+ (instancetype)regExpMatcher;
63
64- (BOOL)string:(NSString*)string matchesExpression:(NSString*)regExp;
65- (BOOL)string:(NSString*)string matchesExpression:(NSString*)regExp flags:(NSUInteger)flags;
66
67@end
68
69@interface NSString (OORegExpMatcher)
70
71- (BOOL)oo_matchesRegularExpression:(NSString*)regExp;
72
73@end
@ kOORegExpMultiLine
@ kOORegExpCaseInsensitive
OOJSValue * _cachedRegExpObject
NSString * _cachedRegExpString
NSUInteger _cachedFlags
OOJSFunction * _tester