3 // http://regexkit.sourceforge.net/
4 // Licensed under the terms of the BSD License, as specified below.
8 Copyright (c) 2008, John Engelhart
12 Redistribution and use in source and binary forms, with or without
13 modification, are permitted provided that the following conditions are met:
15 * Redistributions of source code must retain the above copyright
16 notice, this list of conditions and the following disclaimer.
18 * Redistributions in binary form must reproduce the above copyright
19 notice, this list of conditions and the following disclaimer in the
20 documentation and/or other materials provided with the distribution.
22 * Neither the name of the Zang Industries nor the names of its
23 contributors may be used to endorse or promote products derived from
24 this software without specific prior written permission.
26 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
27 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
28 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
29 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
30 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
31 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
32 TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40 #import <Foundation/NSObjCRuntime.h>
41 #import <Foundation/NSRange.h>
42 #import <Foundation/NSString.h>
47 #include <sys/types.h>
49 #ifndef REGEXKITLITE_VERSION_DEFINED
50 #define REGEXKITLITE_VERSION_DEFINED
52 #define REGEXKITLITE_VERSION_MAJOR 2
53 #define REGEXKITLITE_VERSION_MINOR 2
55 #define REGEXKITLITE_VERSION_CSTRING _RKL_VERSION_STRING(REGEXKITLITE_VERSION_MAJOR, REGEXKITLITE_VERSION_MINOR)
56 #define REGEXKITLITE_VERSION_NSSTRING @REGEXKITLITE_VERSION_CSTRING
58 #define _RKL__STRINGIFY(b) #b
59 #define _RKL_STRINGIFY(a) _RKL__STRINGIFY(a)
60 #define _RKL_JOIN_VERSION(a,b) _RKL_STRINGIFY(a##.##b)
61 #define _RKL_VERSION_STRING(a,b) _RKL_JOIN_VERSION(a,b)
63 #endif // REGEXKITLITE_VERSION_DEFINED
69 // For Mac OS X < 10.5.
70 #ifndef NSINTEGER_DEFINED
71 #define NSINTEGER_DEFINED
72 #ifdef __LP64__ || NS_BUILD_32_LIKE_64
73 typedef long NSInteger;
74 typedef unsigned long NSUInteger;
75 #define NSIntegerMin LONG_MIN
76 #define NSIntegerMax LONG_MAX
77 #define NSUIntegerMax ULONG_MAX
79 typedef int NSInteger;
80 typedef unsigned int NSUInteger;
81 #define NSIntegerMin INT_MIN
82 #define NSIntegerMax INT_MAX
83 #define NSUIntegerMax UINT_MAX
84 #endif // __LP64__ || NS_BUILD_32_LIKE_64
85 #endif // NSINTEGER_DEFINED
87 #ifndef RKLREGEXOPTIONS_DEFINED
88 #define RKLREGEXOPTIONS_DEFINED
90 // These must be idential to their ICU regex counterparts. See http://www.icu-project.org/userguide/regexp.html
97 RKLUnicodeWordBoundaries = 256
99 typedef uint32_t RKLRegexOptions;
101 #endif // RKLREGEXOPTIONS_DEFINED
103 #ifndef _REGEXKITLITE_H_
104 #define _REGEXKITLITE_H_
110 // NSException exception name.
111 extern NSString * const RKLICURegexException;
113 // NSError error domains and user info keys.
114 extern NSString * const RKLICURegexErrorDomain;
116 extern NSString * const RKLICURegexErrorCodeErrorKey;
117 extern NSString * const RKLICURegexErrorNameErrorKey;
118 extern NSString * const RKLICURegexLineErrorKey;
119 extern NSString * const RKLICURegexOffsetErrorKey;
120 extern NSString * const RKLICURegexPreContextErrorKey;
121 extern NSString * const RKLICURegexPostContextErrorKey;
122 extern NSString * const RKLICURegexRegexErrorKey;
123 extern NSString * const RKLICURegexRegexOptionsErrorKey;
125 // If it looks like low memory notifications might be available, add code to register and respond to them.
126 // This is (should be) harmless if it turns out that this isn't the case, since the notification that we register for,
127 // UIApplicationDidReceiveMemoryWarningNotification, is dynamically looked up via dlsym().
128 #if (TARGET_OS_EMBEDDED || TARGET_OS_IPHONE) && (!defined(RKL_REGISTER_FOR_IPHONE_LOWMEM_NOTIFICATIONS) || (RKL_REGISTER_FOR_IPHONE_LOWMEM_NOTIFICATIONS != 0))
129 #define RKL_REGISTER_FOR_IPHONE_LOWMEM_NOTIFICATIONS 1
132 #ifdef RKL_PREPEND_TO_METHODS
133 // This requires a few levels of rewriting to get the desired results.
134 #define RKL_METHOD_PREPEND_2(c,d) c ## d
135 #define RKL_METHOD_PREPEND_1(a,b) RKL_METHOD_PREPEND_2(a,b)
136 #define RKL_METHOD_PREPEND(x) RKL_METHOD_PREPEND_1(RKL_PREPEND_TO_METHODS, x)
138 #define RKL_METHOD_PREPEND(x) x
141 @interface NSString (RegexKitLiteAdditions)
143 + (void)RKL_METHOD_PREPEND(clearStringCache);
145 + (NSInteger)RKL_METHOD_PREPEND(captureCountForRegex):(NSString *)regex;
146 + (NSInteger)RKL_METHOD_PREPEND(captureCountForRegex):(NSString *)regex options:(RKLRegexOptions)options error:(NSError **)error;
148 - (NSArray *)RKL_METHOD_PREPEND(componentsSeparatedByRegex):(NSString *)regex;
149 - (NSArray *)RKL_METHOD_PREPEND(componentsSeparatedByRegex):(NSString *)regex range:(NSRange)range;
150 - (NSArray *)RKL_METHOD_PREPEND(componentsSeparatedByRegex):(NSString *)regex options:(RKLRegexOptions)options range:(NSRange)range error:(NSError **)error;
152 - (BOOL)RKL_METHOD_PREPEND(isMatchedByRegex):(NSString *)regex;
153 - (BOOL)RKL_METHOD_PREPEND(isMatchedByRegex):(NSString *)regex inRange:(NSRange)range;
154 - (BOOL)RKL_METHOD_PREPEND(isMatchedByRegex):(NSString *)regex options:(RKLRegexOptions)options inRange:(NSRange)range error:(NSError **)error;
156 - (NSRange)RKL_METHOD_PREPEND(rangeOfRegex):(NSString *)regex;
157 - (NSRange)RKL_METHOD_PREPEND(rangeOfRegex):(NSString *)regex capture:(NSInteger)capture;
158 - (NSRange)RKL_METHOD_PREPEND(rangeOfRegex):(NSString *)regex inRange:(NSRange)range;
159 - (NSRange)RKL_METHOD_PREPEND(rangeOfRegex):(NSString *)regex options:(RKLRegexOptions)options inRange:(NSRange)range capture:(NSInteger)capture error:(NSError **)error;
161 - (NSString *)RKL_METHOD_PREPEND(stringByMatching):(NSString *)regex;
162 - (NSString *)RKL_METHOD_PREPEND(stringByMatching):(NSString *)regex capture:(NSInteger)capture;
163 - (NSString *)RKL_METHOD_PREPEND(stringByMatching):(NSString *)regex inRange:(NSRange)range;
164 - (NSString *)RKL_METHOD_PREPEND(stringByMatching):(NSString *)regex options:(RKLRegexOptions)options inRange:(NSRange)range capture:(NSInteger)capture error:(NSError **)error;
166 - (NSString *)RKL_METHOD_PREPEND(stringByReplacingOccurrencesOfRegex):(NSString *)regex withString:(NSString *)replacement;
167 - (NSString *)RKL_METHOD_PREPEND(stringByReplacingOccurrencesOfRegex):(NSString *)regex withString:(NSString *)replacement range:(NSRange)searchRange;
168 - (NSString *)RKL_METHOD_PREPEND(stringByReplacingOccurrencesOfRegex):(NSString *)regex withString:(NSString *)replacement options:(RKLRegexOptions)options range:(NSRange)searchRange error:(NSError **)error;
172 @interface NSMutableString (RegexKitLiteAdditions)
174 - (NSUInteger)RKL_METHOD_PREPEND(replaceOccurrencesOfRegex):(NSString *)regex withString:(NSString *)replacement;
175 - (NSUInteger)RKL_METHOD_PREPEND(replaceOccurrencesOfRegex):(NSString *)regex withString:(NSString *)replacement range:(NSRange)searchRange;
176 - (NSUInteger)RKL_METHOD_PREPEND(replaceOccurrencesOfRegex):(NSString *)regex withString:(NSString *)replacement options:(RKLRegexOptions)options range:(NSRange)searchRange error:(NSError **)error;
182 #endif // _REGEXKITLITE_H_