Added implementation of NSRegularExpression, from iOS 4 Foundation.
This class is a thin wrapper around libicu regular expressions, so if we don't
have libicu we simply don't compile it at all. This will give people a linker
failure, rather than a nonfunctional class if they try to use GNUstep without
ICU with code that requires it.
The Apple documentation says that this class has a primitive method that takes
a block as an argument and that this method is called by others, so subclasses
can replace that block method without touching the convenience methods. We
mimic this behaviour when compiling with block, but when compiling without them
it's a problem. The current code contains some ugly hacks that will work in
normal usage but break with subclassing when not compiling with blocks.
This commit also includes a partial implementation of NSTextCheckingResult,
implementing the subset of its functionality required for NSRegularExpression
to work.
It also includes numerous fixes to GSICUString. This is heavily used by
NSRegularExpression, to avoid copying strings when mapping between UText for
libicu and NSString for GNUstep.
Note: I don't have a copy of iOS anywhere to test this against, so it's
entirely possible that there are significant discrepancies between this
implementation of NSRegularExpression and the iOS version. This version should
function exactly as the iOS one is described as functioning, but I think we've
all seen that Apple documentation refers more to hopes than facts. Any testing
that someone who does have an ip{hone,od,ad} can do is very welcome.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@31635 72102866-910b-0410-8b05-ffd578937521
2010-11-19 22:06:18 +00:00
|
|
|
#import "NSObject.h"
|
|
|
|
#import "GNUstepBase/GSBlocks.h"
|
|
|
|
@class NSTextCheckingResult;
|
|
|
|
|
|
|
|
typedef NSUInteger NSRegularExpressionOptions;
|
|
|
|
static const NSRegularExpressionOptions NSRegularExpressionCaseInsensitive = 1<<0;
|
|
|
|
static const NSRegularExpressionOptions NSRegularExpressionAllowCommentsAndWhitespace = 1<<1;
|
|
|
|
static const NSRegularExpressionOptions NSRegularExpressionIgnoreMetacharacters = 1<<2;
|
|
|
|
static const NSRegularExpressionOptions NSRegularExpressionDotMatchesLineSeparators = 1<<3;
|
|
|
|
static const NSRegularExpressionOptions NSRegularExpressionAnchorsMatchLines = 1<<4;
|
|
|
|
static const NSRegularExpressionOptions NSRegularExpressionUseUnixLineSeparators = 1<<5;
|
|
|
|
static const NSRegularExpressionOptions NSRegularExpressionUseUnicodeWordBoundaries = 1<<6;
|
|
|
|
|
|
|
|
typedef NSUInteger NSMatchingFlags;
|
|
|
|
static const NSMatchingFlags NSMatchingProgress = 1<<0;
|
|
|
|
static const NSMatchingFlags NSMatchingCompleted = 1<<1;
|
|
|
|
static const NSMatchingFlags NSMatchingHitEnd = 1<<2;
|
|
|
|
static const NSMatchingFlags NSMatchingRequiredEnd = 1<<3;
|
|
|
|
static const NSMatchingFlags NSMatchingInternalError = 1<<4;
|
|
|
|
|
|
|
|
typedef NSUInteger NSMatchingOptions;
|
|
|
|
static const NSMatchingOptions NSMatchingReportProgress = 1<<0;
|
|
|
|
static const NSMatchingOptions NSMatchingReportCompletion = 1<<1;
|
|
|
|
static const NSMatchingOptions NSMatchingAnchored = 1<<2;
|
|
|
|
static const NSMatchingOptions NSMatchingWithTransparentBounds = 1<<3;
|
|
|
|
static const NSMatchingOptions NSMatchingWithoutAnchoringBounds = 1<<4;
|
|
|
|
|
|
|
|
|
|
|
|
DEFINE_BLOCK_TYPE(GSRegexBlock, void, NSTextCheckingResult*, NSMatchingFlags, BOOL*);
|
|
|
|
|
|
|
|
#ifndef GSREGEXTYPE
|
|
|
|
#define GSREGEXTYPE void
|
|
|
|
#endif
|
|
|
|
|
|
|
|
@interface NSRegularExpression : NSObject <NSCoding, NSCopying>
|
|
|
|
{
|
2011-02-14 06:37:45 +00:00
|
|
|
#if GS_EXPOSE(NSRegularExpression)
|
|
|
|
@private
|
|
|
|
GSREGEXTYPE *regex;
|
|
|
|
NSRegularExpressionOptions options;
|
|
|
|
#endif
|
2011-02-16 05:49:45 +00:00
|
|
|
#if GS_NONFRAGILE
|
|
|
|
#else
|
2011-02-14 06:37:45 +00:00
|
|
|
/* Pointer to private additional data used to avoid breaking ABI
|
|
|
|
* when we don't have the non-fragile ABI available.
|
2011-02-16 05:49:45 +00:00
|
|
|
* Use this mechanism rather than changing the instance variable
|
|
|
|
* layout (see Source/GSInternal.h for details).
|
2011-02-14 06:37:45 +00:00
|
|
|
*/
|
2011-02-16 05:49:45 +00:00
|
|
|
@private void *_internal GS_UNUSED_IVAR;
|
2011-02-14 06:37:45 +00:00
|
|
|
#endif
|
Added implementation of NSRegularExpression, from iOS 4 Foundation.
This class is a thin wrapper around libicu regular expressions, so if we don't
have libicu we simply don't compile it at all. This will give people a linker
failure, rather than a nonfunctional class if they try to use GNUstep without
ICU with code that requires it.
The Apple documentation says that this class has a primitive method that takes
a block as an argument and that this method is called by others, so subclasses
can replace that block method without touching the convenience methods. We
mimic this behaviour when compiling with block, but when compiling without them
it's a problem. The current code contains some ugly hacks that will work in
normal usage but break with subclassing when not compiling with blocks.
This commit also includes a partial implementation of NSTextCheckingResult,
implementing the subset of its functionality required for NSRegularExpression
to work.
It also includes numerous fixes to GSICUString. This is heavily used by
NSRegularExpression, to avoid copying strings when mapping between UText for
libicu and NSString for GNUstep.
Note: I don't have a copy of iOS anywhere to test this against, so it's
entirely possible that there are significant discrepancies between this
implementation of NSRegularExpression and the iOS version. This version should
function exactly as the iOS one is described as functioning, but I think we've
all seen that Apple documentation refers more to hopes than facts. Any testing
that someone who does have an ip{hone,od,ad} can do is very welcome.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@31635 72102866-910b-0410-8b05-ffd578937521
2010-11-19 22:06:18 +00:00
|
|
|
}
|
|
|
|
+ (NSRegularExpression*)regularExpressionWithPattern: (NSString*)aPattern
|
|
|
|
options: (NSRegularExpressionOptions)opts
|
|
|
|
error: (NSError**)e;
|
|
|
|
- initWithPattern: (NSString*)aPattern
|
|
|
|
options: (NSRegularExpressionOptions)opts
|
|
|
|
error: (NSError**)e;
|
|
|
|
+ (NSRegularExpression*)regularExpressionWithPattern: (NSString*)aPattern
|
|
|
|
options: (NSRegularExpressionOptions)opts
|
|
|
|
error: (NSError**)e;
|
|
|
|
- initWithPattern: (NSString*)aPattern
|
|
|
|
options: (NSRegularExpressionOptions)opts
|
|
|
|
error: (NSError**)e;
|
|
|
|
- (NSString*)pattern;
|
|
|
|
- (void)enumerateMatchesInString: (NSString*)string
|
|
|
|
options: (NSMatchingOptions)options
|
|
|
|
range: (NSRange)range
|
|
|
|
usingBlock: (GSRegexBlock)block;
|
|
|
|
- (NSUInteger)numberOfMatchesInString: (NSString*)string
|
|
|
|
options: (NSMatchingOptions)options
|
|
|
|
range: (NSRange)range;
|
|
|
|
|
|
|
|
- (NSTextCheckingResult*)firstMatchInString: (NSString*)string
|
|
|
|
options: (NSMatchingOptions)options
|
|
|
|
range: (NSRange)range;
|
|
|
|
- (NSArray*)matchesInString: (NSString*)string
|
|
|
|
options:(NSMatchingOptions)options
|
|
|
|
range:(NSRange)range;
|
|
|
|
- (NSRange)rangeOfFirstMatchInString: (NSString*)string
|
|
|
|
options: (NSMatchingOptions)options
|
|
|
|
range: (NSRange)range;
|
|
|
|
- (NSUInteger)replaceMatchesInString: (NSMutableString*)string
|
|
|
|
options: (NSMatchingOptions)options
|
|
|
|
range: (NSRange)range
|
2010-12-31 13:58:27 +00:00
|
|
|
withTemplate: (NSString*)templat;
|
Added implementation of NSRegularExpression, from iOS 4 Foundation.
This class is a thin wrapper around libicu regular expressions, so if we don't
have libicu we simply don't compile it at all. This will give people a linker
failure, rather than a nonfunctional class if they try to use GNUstep without
ICU with code that requires it.
The Apple documentation says that this class has a primitive method that takes
a block as an argument and that this method is called by others, so subclasses
can replace that block method without touching the convenience methods. We
mimic this behaviour when compiling with block, but when compiling without them
it's a problem. The current code contains some ugly hacks that will work in
normal usage but break with subclassing when not compiling with blocks.
This commit also includes a partial implementation of NSTextCheckingResult,
implementing the subset of its functionality required for NSRegularExpression
to work.
It also includes numerous fixes to GSICUString. This is heavily used by
NSRegularExpression, to avoid copying strings when mapping between UText for
libicu and NSString for GNUstep.
Note: I don't have a copy of iOS anywhere to test this against, so it's
entirely possible that there are significant discrepancies between this
implementation of NSRegularExpression and the iOS version. This version should
function exactly as the iOS one is described as functioning, but I think we've
all seen that Apple documentation refers more to hopes than facts. Any testing
that someone who does have an ip{hone,od,ad} can do is very welcome.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@31635 72102866-910b-0410-8b05-ffd578937521
2010-11-19 22:06:18 +00:00
|
|
|
- (NSString*)stringByReplacingMatchesInString: (NSString*)string
|
|
|
|
options: (NSMatchingOptions)options
|
|
|
|
range: (NSRange)range
|
2010-12-31 13:58:27 +00:00
|
|
|
withTemplate: (NSString*)templat;
|
Added implementation of NSRegularExpression, from iOS 4 Foundation.
This class is a thin wrapper around libicu regular expressions, so if we don't
have libicu we simply don't compile it at all. This will give people a linker
failure, rather than a nonfunctional class if they try to use GNUstep without
ICU with code that requires it.
The Apple documentation says that this class has a primitive method that takes
a block as an argument and that this method is called by others, so subclasses
can replace that block method without touching the convenience methods. We
mimic this behaviour when compiling with block, but when compiling without them
it's a problem. The current code contains some ugly hacks that will work in
normal usage but break with subclassing when not compiling with blocks.
This commit also includes a partial implementation of NSTextCheckingResult,
implementing the subset of its functionality required for NSRegularExpression
to work.
It also includes numerous fixes to GSICUString. This is heavily used by
NSRegularExpression, to avoid copying strings when mapping between UText for
libicu and NSString for GNUstep.
Note: I don't have a copy of iOS anywhere to test this against, so it's
entirely possible that there are significant discrepancies between this
implementation of NSRegularExpression and the iOS version. This version should
function exactly as the iOS one is described as functioning, but I think we've
all seen that Apple documentation refers more to hopes than facts. Any testing
that someone who does have an ip{hone,od,ad} can do is very welcome.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@31635 72102866-910b-0410-8b05-ffd578937521
2010-11-19 22:06:18 +00:00
|
|
|
- (NSString*)replacementStringForResult: (NSTextCheckingResult*)result
|
|
|
|
inString: (NSString*)string
|
|
|
|
offset: (NSInteger)offset
|
2010-12-31 13:58:27 +00:00
|
|
|
template: (NSString*)templat;
|
Added implementation of NSRegularExpression, from iOS 4 Foundation.
This class is a thin wrapper around libicu regular expressions, so if we don't
have libicu we simply don't compile it at all. This will give people a linker
failure, rather than a nonfunctional class if they try to use GNUstep without
ICU with code that requires it.
The Apple documentation says that this class has a primitive method that takes
a block as an argument and that this method is called by others, so subclasses
can replace that block method without touching the convenience methods. We
mimic this behaviour when compiling with block, but when compiling without them
it's a problem. The current code contains some ugly hacks that will work in
normal usage but break with subclassing when not compiling with blocks.
This commit also includes a partial implementation of NSTextCheckingResult,
implementing the subset of its functionality required for NSRegularExpression
to work.
It also includes numerous fixes to GSICUString. This is heavily used by
NSRegularExpression, to avoid copying strings when mapping between UText for
libicu and NSString for GNUstep.
Note: I don't have a copy of iOS anywhere to test this against, so it's
entirely possible that there are significant discrepancies between this
implementation of NSRegularExpression and the iOS version. This version should
function exactly as the iOS one is described as functioning, but I think we've
all seen that Apple documentation refers more to hopes than facts. Any testing
that someone who does have an ip{hone,od,ad} can do is very welcome.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@31635 72102866-910b-0410-8b05-ffd578937521
2010-11-19 22:06:18 +00:00
|
|
|
#if GS_HAS_DECLARED_PROPERTIES
|
|
|
|
@property (readonly) NSRegularExpressionOptions options;
|
|
|
|
@property (readonly) NSUInteger numberOfCaptureGroups;
|
|
|
|
#else
|
|
|
|
- (NSRegularExpressionOptions)options;
|
|
|
|
- (NSUInteger)numberOfCaptureGroups;
|
|
|
|
#endif
|
|
|
|
@end
|