mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-25 09:41:15 +00:00
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
79 lines
2.2 KiB
Objective-C
79 lines
2.2 KiB
Objective-C
#import "Foundation/NSTextCheckingResult.h"
|
|
#import "Foundation/NSRegularExpression.h"
|
|
|
|
/**
|
|
* Private class encapsulating a regular expression match.
|
|
*/
|
|
@interface GSRegularExpressionCheckingResult : NSTextCheckingResult
|
|
{
|
|
// TODO: This could be made more efficient by adding a variant that only
|
|
// contained a single range.
|
|
@public
|
|
/** The number of ranges matched */
|
|
NSUInteger rangeCount;
|
|
/** The array of ranges. */
|
|
NSRange *ranges;
|
|
/** The regular expression object that generated this match. */
|
|
NSRegularExpression *regularExpression;
|
|
}
|
|
@end
|
|
|
|
@implementation NSTextCheckingResult
|
|
+ (NSTextCheckingResult*)regularExpressionCheckingResultWithRanges: (NSRangePointer)ranges
|
|
count: (NSUInteger)count
|
|
regularExpression: (NSRegularExpression*)regularExpression
|
|
{
|
|
GSRegularExpressionCheckingResult *result = [GSRegularExpressionCheckingResult new];
|
|
result->rangeCount = count;
|
|
result->ranges = calloc(sizeof(NSRange), count);
|
|
memcpy(result->ranges, ranges, (sizeof(NSRange) * count));
|
|
ASSIGN(result->regularExpression, regularExpression);
|
|
return [result autorelease];
|
|
}
|
|
- (NSDictionary*)addressComponents { return 0; }
|
|
- (NSDictionary*)components { return 0; }
|
|
- (NSDate*)date { return 0; }
|
|
- (NSTimeInterval) duration { return 0; }
|
|
- (NSArray*)grammarDetails { return 0; }
|
|
- (NSUInteger) numberOfRanges { return 0; }
|
|
- (NSOrthography*)orthography { return 0; }
|
|
- (NSString*)phoneNumber { return 0; }
|
|
- (NSRange) range { return NSMakeRange(0, NSNotFound); }
|
|
- (NSRegularExpression*)regularExpression { return 0; }
|
|
- (NSString*)replacementString { return 0; }
|
|
- (NSTextCheckingType)resultType { return -1; }
|
|
- (NSTimeZone*)timeZone { return 0; }
|
|
- (NSURL*)URL { return 0; }
|
|
@end
|
|
|
|
|
|
|
|
@implementation GSRegularExpressionCheckingResult
|
|
- (NSUInteger)rangeCount
|
|
{
|
|
return rangeCount;
|
|
}
|
|
- (NSRange)range
|
|
{
|
|
return ranges[0];
|
|
}
|
|
- (NSRange)rangeAtIndex: (NSUInteger)idx
|
|
{
|
|
if (idx >= rangeCount)
|
|
{
|
|
return NSMakeRange(0, NSNotFound);
|
|
}
|
|
return ranges[idx];
|
|
}
|
|
- (NSTextCheckingType)resultType
|
|
{
|
|
return NSTextCheckingTypeRegularExpression;
|
|
}
|
|
- (void)dealloc
|
|
{
|
|
[regularExpression release];
|
|
free(ranges);
|
|
[super dealloc];
|
|
}
|
|
@end
|
|
|