2011-12-23 16:09:49 +00:00
|
|
|
/* Copyright (C) 2011 Free Software Foundation, Inc.
|
|
|
|
|
|
|
|
This file is part of the GNUstep Library.
|
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU Lesser General Public
|
|
|
|
License as published by the Free Software Foundation; either
|
|
|
|
version 2 of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This library is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
2019-12-09 23:36:00 +00:00
|
|
|
Lesser General Public License for more details.
|
2011-12-23 16:09:49 +00:00
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public
|
|
|
|
License along with this library; if not, write to the Free
|
2024-11-07 13:37:59 +00:00
|
|
|
Software Foundation, Inc., 31 Milk Street #960789 Boston, MA 02196 USA.
|
2011-12-23 16:09:49 +00:00
|
|
|
*/
|
|
|
|
|
2013-08-22 15:44:54 +00:00
|
|
|
#import "common.h"
|
2011-12-23 16:09:49 +00:00
|
|
|
#import "Foundation/NSException.h"
|
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 "Foundation/NSTextCheckingResult.h"
|
|
|
|
#import "Foundation/NSRegularExpression.h"
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Private class encapsulating a regular expression match.
|
|
|
|
*/
|
|
|
|
@interface GSRegularExpressionCheckingResult : NSTextCheckingResult
|
|
|
|
{
|
2011-12-23 16:09:49 +00:00
|
|
|
// 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;
|
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
|
|
|
}
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation NSTextCheckingResult
|
2012-02-04 13:33:03 +00:00
|
|
|
+ (NSTextCheckingResult*)
|
|
|
|
regularExpressionCheckingResultWithRanges: (NSRangePointer)ranges
|
|
|
|
count: (NSUInteger)count
|
|
|
|
regularExpression: (NSRegularExpression*)regularExpression
|
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
|
|
|
{
|
2011-12-23 16:09:49 +00:00
|
|
|
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];
|
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
|
|
|
}
|
2011-12-23 16:09:49 +00:00
|
|
|
|
2012-02-04 13:33:03 +00:00
|
|
|
- (NSDictionary*) addressComponents
|
|
|
|
{
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSDictionary*) components
|
|
|
|
{
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSDate*) date
|
|
|
|
{
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSTimeInterval) duration
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSArray*) grammarDetails
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSUInteger) numberOfRanges
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSOrthography*) orthography
|
|
|
|
{
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString*) phoneNumber
|
|
|
|
{
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSRange) range
|
2011-12-23 16:09:49 +00:00
|
|
|
{
|
|
|
|
[self subclassResponsibility: _cmd];
|
|
|
|
return NSMakeRange(NSNotFound, 0);
|
|
|
|
}
|
2012-02-04 13:33:03 +00:00
|
|
|
|
|
|
|
- (NSRegularExpression*) regularExpression
|
|
|
|
{
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString*) replacementString
|
|
|
|
{
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSTextCheckingType) resultType
|
2011-12-23 16:09:49 +00:00
|
|
|
{
|
|
|
|
[self subclassResponsibility: _cmd];
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2012-02-04 13:33:03 +00:00
|
|
|
- (NSTimeZone*) timeZone
|
|
|
|
{
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSURL*) URL
|
|
|
|
{
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
- (NSRange) rangeAtIndex: (NSUInteger)idx
|
2011-12-23 16:09:49 +00:00
|
|
|
{
|
|
|
|
if (idx >= [self numberOfRanges])
|
|
|
|
{
|
|
|
|
[NSException raise: NSInvalidArgumentException
|
2012-02-04 13:33:03 +00:00
|
|
|
format: @"index %"PRIuPTR" out of range", idx];
|
2011-12-23 16:09:49 +00:00
|
|
|
}
|
|
|
|
return [self range];
|
|
|
|
}
|
2011-12-23 16:49:23 +00:00
|
|
|
|
2012-02-04 13:33:03 +00:00
|
|
|
- (NSTextCheckingResult *) resultByAdjustingRangesWithOffset: (NSInteger)offset
|
2011-12-23 16:49:23 +00:00
|
|
|
{
|
|
|
|
[self subclassResponsibility: _cmd];
|
|
|
|
return nil;
|
|
|
|
}
|
2012-02-04 13:33:03 +00:00
|
|
|
|
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
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@implementation GSRegularExpressionCheckingResult
|
2011-12-23 16:09:49 +00:00
|
|
|
|
2012-02-04 13:33:03 +00:00
|
|
|
- (void) dealloc
|
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
|
|
|
{
|
2011-12-23 16:09:49 +00:00
|
|
|
[regularExpression release];
|
|
|
|
free(ranges);
|
|
|
|
[super dealloc];
|
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
|
|
|
}
|
2011-12-23 16:09:49 +00:00
|
|
|
|
2012-02-04 13:33:03 +00:00
|
|
|
- (NSUInteger) numberOfRanges
|
2011-12-23 16:09:49 +00:00
|
|
|
{
|
|
|
|
return rangeCount;
|
|
|
|
}
|
|
|
|
|
2012-02-04 13:33:03 +00:00
|
|
|
- (NSRange) range
|
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
|
|
|
{
|
2011-12-23 16:09:49 +00:00
|
|
|
return ranges[0];
|
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
|
|
|
}
|
2011-12-23 16:09:49 +00:00
|
|
|
|
2012-02-04 13:33:03 +00:00
|
|
|
- (NSRange) rangeAtIndex: (NSUInteger)idx
|
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
|
|
|
{
|
2011-12-23 16:09:49 +00:00
|
|
|
if (idx >= rangeCount)
|
|
|
|
{
|
|
|
|
[NSException raise: NSInvalidArgumentException
|
2012-02-04 13:33:03 +00:00
|
|
|
format: @"index %"PRIuPTR" out of range", idx];
|
2011-12-23 16:09:49 +00:00
|
|
|
}
|
|
|
|
return ranges[idx];
|
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
|
|
|
}
|
2011-12-23 16:09:49 +00:00
|
|
|
|
2012-02-04 13:33:03 +00:00
|
|
|
- (NSRegularExpression*) regularExpression
|
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
|
|
|
{
|
2011-12-23 16:09:49 +00:00
|
|
|
return regularExpression;
|
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
|
|
|
}
|
2011-12-23 16:09:49 +00:00
|
|
|
|
2012-02-04 13:33:03 +00:00
|
|
|
- (NSTextCheckingType) resultType
|
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
|
|
|
{
|
2011-12-23 16:09:49 +00:00
|
|
|
return NSTextCheckingTypeRegularExpression;
|
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
|
|
|
}
|
2011-12-23 16:09:49 +00:00
|
|
|
|
2012-02-04 13:33:03 +00:00
|
|
|
- (NSTextCheckingResult*) resultByAdjustingRangesWithOffset: (NSInteger)offset
|
2011-12-23 16:49:23 +00:00
|
|
|
{
|
|
|
|
NSUInteger i;
|
|
|
|
GSRegularExpressionCheckingResult *result =
|
|
|
|
[[GSRegularExpressionCheckingResult new] autorelease];
|
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
|
|
|
|
2011-12-23 16:49:23 +00:00
|
|
|
result->rangeCount = rangeCount;
|
|
|
|
result->ranges = calloc(sizeof(NSRange), rangeCount);
|
|
|
|
for (i = 0; i < rangeCount; i++)
|
|
|
|
{
|
|
|
|
NSRange r = ranges[i];
|
2012-02-04 13:33:03 +00:00
|
|
|
|
|
|
|
if ((offset > 0 && NSNotFound - r.location <= offset)
|
|
|
|
|| (offset < 0 && r.location < -offset))
|
2011-12-23 16:49:23 +00:00
|
|
|
{
|
|
|
|
[NSException raise: NSInvalidArgumentException
|
2012-01-09 08:28:27 +00:00
|
|
|
format: @"Invalid offset %"PRIdPTR" for range: %@",
|
|
|
|
offset, NSStringFromRange(r)];
|
2011-12-23 16:49:23 +00:00
|
|
|
}
|
|
|
|
r.location += offset;
|
|
|
|
result->ranges[i] = r;
|
|
|
|
}
|
|
|
|
ASSIGN(result->regularExpression, regularExpression);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|