Bumping to version 1.0.1, which uses the latest ITKit. This resolves GrowlITTSW bug #4.
[GrowlITTSW.git] / RegexKitLite.h
1 //
2 //  RegexKitLite.h
3 //  http://regexkit.sourceforge.net/
4 //  Licensed under the terms of the BSD License, as specified below.
5 //
6
7 /*
8  Copyright (c) 2008, John Engelhart
9  
10  All rights reserved.
11  
12  Redistribution and use in source and binary forms, with or without
13  modification, are permitted provided that the following conditions are met:
14  
15  * Redistributions of source code must retain the above copyright
16  notice, this list of conditions and the following disclaimer.
17  
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.
21  
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.
25  
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.
37 */ 
38
39 #ifdef    __OBJC__
40 #import <Foundation/NSObjCRuntime.h>
41 #import <Foundation/NSRange.h>
42 #import <Foundation/NSString.h>
43 #endif // __OBJC__
44
45 #include <limits.h>
46 #include <stdint.h>
47 #include <sys/types.h>
48
49 #ifndef REGEXKITLITE_VERSION_DEFINED
50 #define REGEXKITLITE_VERSION_DEFINED
51
52 #define REGEXKITLITE_VERSION_MAJOR 2
53 #define REGEXKITLITE_VERSION_MINOR 2
54
55 #define REGEXKITLITE_VERSION_CSTRING   _RKL_VERSION_STRING(REGEXKITLITE_VERSION_MAJOR, REGEXKITLITE_VERSION_MINOR)
56 #define REGEXKITLITE_VERSION_NSSTRING  @REGEXKITLITE_VERSION_CSTRING
57
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)
62
63 #endif // REGEXKITLITE_VERSION_DEFINED
64
65 #ifdef __cplusplus
66 extern "C" {
67 #endif
68
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
78 #else // 32-bit
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
86
87 #ifndef RKLREGEXOPTIONS_DEFINED
88 #define RKLREGEXOPTIONS_DEFINED
89
90 // These must be idential to their ICU regex counterparts. See http://www.icu-project.org/userguide/regexp.html
91 enum {
92   RKLNoOptions             = 0,
93   RKLCaseless              = 2,
94   RKLComments              = 4,
95   RKLDotAll                = 32,
96   RKLMultiline             = 8,
97   RKLUnicodeWordBoundaries = 256
98 };
99 typedef uint32_t RKLRegexOptions;
100
101 #endif // RKLREGEXOPTIONS_DEFINED
102
103 #ifndef _REGEXKITLITE_H_
104 #define _REGEXKITLITE_H_
105
106 #ifdef __OBJC__
107
108 @class NSError;
109
110 // NSException exception name.
111 extern NSString * const RKLICURegexException;
112
113 // NSError error domains and user info keys.
114 extern NSString * const RKLICURegexErrorDomain;
115
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;
124
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
130 #endif
131
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)
137 #else
138 #define RKL_METHOD_PREPEND(x) x
139 #endif
140
141 @interface NSString (RegexKitLiteAdditions)
142
143 + (void)RKL_METHOD_PREPEND(clearStringCache);
144
145 + (NSInteger)RKL_METHOD_PREPEND(captureCountForRegex):(NSString *)regex;
146 + (NSInteger)RKL_METHOD_PREPEND(captureCountForRegex):(NSString *)regex options:(RKLRegexOptions)options error:(NSError **)error;
147
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;
151
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;
155
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;
160
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;
165
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;
169
170 @end
171
172 @interface NSMutableString (RegexKitLiteAdditions)
173
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;
177
178 @end
179
180 #endif // __OBJC__
181
182 #endif // _REGEXKITLITE_H_
183
184 #ifdef __cplusplus
185 }  // extern "C"
186 #endif