2011-12-22 12:52:56 +00:00
/ * * Implementation of NSRegularExpression for GNUStep
2010-12-16 10:59:50 +00:00
Copyright ( C ) 2010 Free Software Foundation , Inc .
This file is part of the GNUstep Base 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 .
2010-12-16 10:59:50 +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 .
2010-12-16 10:59:50 +00:00
* /
2011-08-13 15:28:22 +00:00
# define EXPOSE_NSRegularExpression _IVARS 1
2010-12-16 10:59:50 +00:00
# import "common.h"
2010-12-16 10:09:43 +00:00
# if GS_USE _ICU = = 1
2021-07-16 12:31:38 +00:00
# if defined ( HAVE_UNICODE _UREGEX _H )
# include < unicode / uregex . h >
2021-08-06 07:29:11 +00:00
# elif defined ( HAVE_ICU _H )
2021-07-16 12:31:38 +00:00
# include < icu . h >
# endif
2011-12-22 12:52:56 +00:00
2012-02-23 17:57:50 +00:00
/ * FIXME It would be nice to use autoconf for checking whether uregex_openUText
* is defined . However the naive check using AC_CHECK _FUNCS ( uregex_openUText )
2017-02-11 14:24:58 +00:00
* won ' t work because libicu internally renames all entry points with some cpp
2012-02-23 17:57:50 +00:00
* magic .
* /
2024-11-21 21:05:34 +00:00
# if ! defined ( HAVE_UREGEX _OPENUTEXT )
2022-02-18 16:00:14 +00:00
# if U_ICU _VERSION _MAJOR _NUM > 4 || ( U_ICU _VERSION _MAJOR _NUM = = 4 && U_ICU _VERSION _MINOR _NUM >= 4 ) || defined ( HAVE_ICU _H )
2011-12-22 12:52:56 +00:00
# define HAVE_UREGEX _OPENUTEXT 1
# endif
2024-11-21 21:05:34 +00:00
# endif
/ * Until the uregex_replaceAllUText ( ) and uregex_replaceFirstUText ( ) work
* without leaking memory , we can ' t use them : - (
* Preoblem exists on Ubuntu in 2024 with icu -74.2
* /
# if defined ( HAVE_UREGEX _OPENUTEXT )
# undef HAVE_UREGEX _OPENUTEXT
# endif
2011-08-03 12:04:27 +00:00
2011-07-22 13:23:11 +00:00
# define NSRegularExpressionWorks
2011-08-03 12:04:27 +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
# define GSREGEXTYPE URegularExpression
# import "GSICUString.h"
2023-11-13 19:45:16 +00:00
# import "Foundation/NSDictionary.h"
# import "Foundation/NSException.h"
2011-08-02 08:33:33 +00:00
# import "Foundation/NSRegularExpression.h"
# import "Foundation/NSTextCheckingResult.h"
2011-08-03 12:04:27 +00:00
# import "Foundation/NSArray.h"
# import "Foundation/NSCoder.h"
2016-06-17 09:04:04 +00:00
# import "Foundation/NSUserDefaults.h"
# import "Foundation/NSNotification.h"
2023-11-13 18:55:49 +00:00
# import "Foundation/FoundationErrors.h"
# import "Foundation/NSError.h"
2011-08-03 12:04:27 +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
/ * *
* To be helpful , Apple decided to define a set of flags that mean exactly the
* same thing as the URegexpFlags enum in libicu , but have different values .
* This was completely stupid , but we probably have to live with it . We could
* in theory use the libicu values directly ( that would be sensible ) , but that
* would break any code that didn ' t correctly use the symbolic constants .
* /
2010-12-16 10:59:50 +00:00
uint32_t
NSRegularExpressionOptionsToURegexpFlags ( NSRegularExpressionOptions opts )
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
{
2010-12-16 10:59:50 +00:00
uint32_t flags = 0 ;
if ( opts & NSRegularExpressionCaseInsensitive )
{
flags | = UREGEX_CASE _INSENSITIVE ;
}
if ( opts & NSRegularExpressionAllowCommentsAndWhitespace )
{
flags | = UREGEX_COMMENTS ;
}
if ( opts & NSRegularExpressionIgnoreMetacharacters )
{
2012-02-23 17:57:50 +00:00
flags | = UREGEX_LITERAL ;
2010-12-16 10:59:50 +00:00
}
if ( opts & NSRegularExpressionDotMatchesLineSeparators )
{
flags | = UREGEX_DOTALL ;
}
if ( opts & NSRegularExpressionAnchorsMatchLines )
{
flags | = UREGEX_MULTILINE ;
}
if ( opts & NSRegularExpressionUseUnixLineSeparators )
{
flags | = UREGEX_UNIX _LINES ;
}
if ( opts & NSRegularExpressionUseUnicodeWordBoundaries )
{
flags | = UREGEX_UWORD ;
}
return flags ;
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
}
@ implementation NSRegularExpression
2010-12-16 10:59:50 +00:00
+ ( NSRegularExpression * ) regularExpressionWithPattern : ( NSString * ) aPattern
2023-11-13 19:45:16 +00:00
options : ( NSRegularExpressionOptions ) opts
error : ( NSError * * ) e
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
{
2023-11-13 19:45:16 +00:00
NSRegularExpression * r ;
r = [ [ self alloc ] initWithPattern : aPattern
options : opts
error : e ] ;
return AUTORELEASE ( r ) ;
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
}
2010-12-16 10:59:50 +00:00
2012-03-27 10:03:40 +00:00
2011-12-22 12:52:56 +00:00
# if HAVE_UREGEX _OPENUTEXT
2010-12-16 10:59:50 +00:00
- ( id ) initWithPattern : ( NSString * ) aPattern
options : ( NSRegularExpressionOptions ) opts
error : ( NSError * * ) e
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
{
2010-12-16 10:59:50 +00:00
uint32_t flags = NSRegularExpressionOptionsToURegexpFlags ( opts ) ;
UText p = UTEXT_INITIALIZER ;
UParseError pe = { 0 } ;
UErrorCode s = 0 ;
2023-11-13 19:45:16 +00:00
// Raise an NSInvalidArgumentException to match macOS behaviour .
if ( ! aPattern )
{
NSException * exp ;
exp = [ NSException exceptionWithName : NSInvalidArgumentException
reason : @ "nil argument"
userInfo : nil ] ;
2024-11-16 21:11:56 +00:00
RELEASE ( self ) ;
2023-11-13 19:45:16 +00:00
[ exp raise ] ;
}
2012-03-27 10:03:40 +00:00
# if ! __has _feature ( blocks )
if ( [ self class ] ! = [ NSRegularExpression class ] )
{
GSOnceMLog ( @ "Warning: NSRegularExpression was built by a compiler without blocks support. NSRegularExpression will deviate from the documented behaviour when subclassing and any code that subclasses NSRegularExpression may break in unexpected ways. If you must subclass NSRegularExpression, you are strongly recommended to use a compiler with blocks support." ) ;
}
# endif
2010-12-16 10:59:50 +00:00
UTextInitWithNSString ( & p , aPattern ) ;
regex = uregex_openUText ( & p , flags , & pe , & s ) ;
utext_close ( & p ) ;
if ( U_FAILURE ( s ) )
{
2023-11-13 19:45:16 +00:00
/ * Match macOS behaviour if the pattern is invalid .
* Example :
* Domain = NSCocoaErrorDomain
* Code = 2048 "The value “<PATTERN>” is invalid."
* UserInfo = { NSInvalidValue = < PATTERN > }
* /
if ( e )
{
NSDictionary * userInfo ;
NSString * description ;
2023-11-13 18:55:49 +00:00
2024-11-21 21:05:34 +00:00
description = [ NSString
stringWithFormat : @ "The value “%@” is invalid." , aPattern ] ;
2023-11-13 18:55:49 +00:00
2023-11-13 19:45:16 +00:00
userInfo = [ NSDictionary dictionaryWithObjectsAndKeys :
aPattern , @ "NSInvalidValue" ,
description , NSLocalizedDescriptionKey ,
nil ] ;
2023-11-13 18:55:49 +00:00
2023-11-13 19:45:16 +00:00
* e = [ NSError errorWithDomain : NSCocoaErrorDomain
code : NSFormattingError
userInfo : userInfo ] ;
}
2023-11-13 18:55:49 +00:00
2023-11-13 19:45:16 +00:00
DESTROY ( self ) ;
return self ;
2010-12-16 10:59:50 +00:00
}
options = opts ;
return self ;
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
}
2010-12-16 10:59:50 +00:00
2016-06-17 07:43:51 +00:00
- ( BOOL ) isEqual : ( id ) obj
{
if ( [ obj isKindOfClass : [ NSRegularExpression class ] ] )
{
if ( self = = obj )
{
return YES ;
}
else if ( options ! = ( ( NSRegularExpression * ) obj ) -> options )
{
return NO ;
}
else
{
UErrorCode myErr = 0 ;
UErrorCode theirErr = 0 ;
const UText * myText = uregex_patternUText ( regex , & myErr ) ;
const UText * theirText =
uregex_patternUText ( ( ( NSRegularExpression * ) obj ) -> regex , & theirErr ) ;
if ( U_FAILURE ( myErr ) ! = U_FAILURE ( theirErr ) )
{
return NO ;
}
else if ( U_FAILURE ( myErr ) && U_FAILURE ( theirErr ) )
{
return YES ;
}
return utext_equals ( myText , theirText ) ;
}
}
else
{
return [ super isEqual : obj ] ;
}
}
2010-12-16 10:59:50 +00:00
- ( NSString * ) pattern
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-08-03 12:04:27 +00:00
UErrorCode s = 0 ;
UText * t = uregex_patternUText ( regex , & s ) ;
GSUTextString * str = NULL ;
if ( U_FAILURE ( s ) )
{
return nil ;
}
str = [ GSUTextString new ] ;
utext_clone ( & str -> txt , t , FALSE , TRUE , & s ) ;
2023-11-13 19:45:16 +00:00
return AUTORELEASE ( str ) ;
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-22 12:52:56 +00:00
# else
- ( id ) initWithPattern : ( NSString * ) aPattern
options : ( NSRegularExpressionOptions ) opts
error : ( NSError * * ) e
{
int32_t length = [ aPattern length ] ;
uint32_t flags = NSRegularExpressionOptionsToURegexpFlags ( opts ) ;
UParseError pe = { 0 } ;
UErrorCode s = 0 ;
TEMP_BUFFER ( buffer , length ) ;
2012-03-27 10:03:40 +00:00
# if ! __has _feature ( blocks )
if ( [ self class ] ! = [ NSRegularExpression class ] )
{
GSOnceMLog ( @ "Warning: NSRegularExpression was built by a compiler without blocks support. NSRegularExpression will deviate from the documented behaviour when subclassing and any code that subclasses NSRegularExpression may break in unexpected ways. If you must subclass NSRegularExpression, you are strongly recommended to use a compiler with blocks support." ) ;
}
# endif
2024-11-21 21:05:34 +00:00
// Raise an NSInvalidArgumentException to match macOS behaviour .
if ( ! aPattern )
{
NSException * exp ;
exp = [ NSException exceptionWithName : NSInvalidArgumentException
reason : @ "nil argument"
userInfo : nil ] ;
RELEASE ( self ) ;
[ exp raise ] ;
}
2011-12-22 12:52:56 +00:00
[ aPattern getCharacters : buffer range : NSMakeRange ( 0 , length ) ] ;
regex = uregex_open ( buffer , length , flags , & pe , & s ) ;
if ( U_FAILURE ( s ) )
{
2024-11-21 21:05:34 +00:00
/ * Match macOS behaviour if the pattern is invalid .
* Example :
* Domain = NSCocoaErrorDomain
* Code = 2048 "The value “<PATTERN>” is invalid."
* UserInfo = { NSInvalidValue = < PATTERN > }
* /
if ( e )
{
NSDictionary * userInfo ;
NSString * description ;
description = [ NSString
stringWithFormat : @ "The value “%@” is invalid." , aPattern ] ;
userInfo = [ NSDictionary dictionaryWithObjectsAndKeys :
aPattern , @ "NSInvalidValue" ,
description , NSLocalizedDescriptionKey ,
nil ] ;
* e = [ NSError errorWithDomain : NSCocoaErrorDomain
code : NSFormattingError
userInfo : userInfo ] ;
}
2023-11-13 19:45:16 +00:00
DESTROY ( self ) ;
return self ;
2011-12-22 12:52:56 +00:00
}
options = opts ;
return self ;
}
2016-06-17 07:43:51 +00:00
- ( BOOL ) isEqual : ( id ) obj
{
if ( [ obj isKindOfClass : [ NSRegularExpression class ] ] )
{
if ( self = = obj )
{
return YES ;
}
else if ( options ! = ( ( NSRegularExpression * ) obj ) -> options )
{
return NO ;
}
else
{
UErrorCode myErr = 0 ;
UErrorCode theirErr = 0 ;
int32_t myLen = 0 ;
int32_t theirLen = 0 ;
const UChar * myText = uregex_pattern ( regex , & myLen , & myErr ) ;
const UChar * theirText = uregex_pattern (
( ( NSRegularExpression * ) obj ) -> regex ,
& theirLen , & theirErr ) ;
if ( U_FAILURE ( myErr ) ! = U_FAILURE ( theirErr ) )
{
return NO ;
}
else if ( U_FAILURE ( myErr ) && U_FAILURE ( theirErr ) )
{
return YES ;
}
if ( myLen ! = theirLen )
{
return NO ;
}
2023-11-13 19:45:16 +00:00
return ( 0 = = memcmp ( ( const void * ) myText , ( const void * ) theirText , myLen ) ) ;
2016-06-17 07:43:51 +00:00
}
}
else
{
return [ super isEqual : obj ] ;
}
}
2011-12-22 12:52:56 +00:00
- ( NSString * ) pattern
{
UErrorCode s = 0 ;
int32_t length ;
const unichar * pattern = uregex_pattern ( regex , & length , & s ) ;
2016-06-17 07:43:51 +00:00
2011-12-22 12:52:56 +00:00
if ( U_FAILURE ( s ) )
{
return nil ;
}
return [ NSString stringWithCharacters : pattern length : length ] ;
}
# 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
2016-06-17 07:43:51 +00:00
- ( NSUInteger ) hash
{
return [ [ self pattern ] hash ] ^ options ;
}
2010-12-16 10:59:50 +00:00
static UBool
callback ( const void * context , int32_t steps )
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
{
2010-12-16 10:59:50 +00:00
BOOL stop = NO ;
GSRegexBlock block = ( GSRegexBlock ) context ;
if ( NULL = = context )
{
return FALSE ;
}
CALL_BLOCK ( block , nil , NSMatchingProgress , & stop ) ;
return stop ;
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
}
2010-12-16 10:59:50 +00:00
2016-06-17 09:04:04 +00:00
# define DEFAULT_WORK _LIMIT 1500
/ * *
* The work limit specifies the number of iterations the matcher will do before
* aborting an operation . This ensures that degenerate pattern / input
* combinations don ' t send the application into what for all intents and
* purposes seems like an infinite loop .
* /
static int32_t _workLimit = DEFAULT_WORK _LIMIT ;
+ ( void ) _defaultsChanged : ( NSNotification * ) n
{
2023-11-13 19:45:16 +00:00
NSUserDefaults * defs = [ NSUserDefaults standardUserDefaults ] ;
id value = [ defs objectForKey : @ "GSRegularExpressionWorkLimit" ] ;
int32_t newLimit = DEFAULT_WORK _LIMIT ;
2016-06-17 09:04:04 +00:00
if ( [ value respondsToSelector : @ selector ( intValue ) ] )
{
2023-11-13 19:45:16 +00:00
int32_t v = [ value intValue ] ;
2016-06-17 09:04:04 +00:00
if ( v >= 0 )
{
newLimit = v ;
}
}
_workLimit = newLimit ;
}
+ ( void ) initialize
{
if ( self = = [ NSRegularExpression class ] )
{
[ [ NSNotificationCenter defaultCenter ]
addObserver : self
selector : @ selector ( _defaultsChanged : )
name : NSUserDefaultsDidChangeNotification
object : nil ] ;
[ self _defaultsChanged : nil ] ;
}
}
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
/ * *
* Sets up a libicu regex object for use . Note : the documentation states that
* NSRegularExpression must be thread safe . To accomplish this , we store a
* prototype URegularExpression in the object , and then clone it in each
* method . This is required because URegularExpression , unlike
* NSRegularExpression , is stateful , and sharing this state between threads
* would break concurrent calls .
* /
2011-12-22 12:52:56 +00:00
# if HAVE_UREGEX _OPENUTEXT
2010-12-16 10:59:50 +00:00
static URegularExpression *
setupRegex ( URegularExpression * regex ,
NSString * string ,
UText * txt ,
NSMatchingOptions options ,
NSRange range ,
GSRegexBlock block )
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
{
2010-12-16 10:59:50 +00:00
UErrorCode s = 0 ;
URegularExpression * r = uregex_clone ( regex , & s ) ;
if ( options & NSMatchingReportProgress )
{
uregex_setMatchCallback ( r , callback , block , & s ) ;
}
UTextInitWithNSString ( txt , string ) ;
uregex_setUText ( r , txt , & s ) ;
uregex_setRegion ( r , range . location , range . location + range . length , & s ) ;
if ( options & NSMatchingWithoutAnchoringBounds )
{
uregex_useAnchoringBounds ( r , FALSE , & s ) ;
}
if ( options & NSMatchingWithTransparentBounds )
{
uregex_useTransparentBounds ( r , TRUE , & s ) ;
}
2016-06-17 09:04:04 +00:00
uregex_setTimeLimit ( r , _workLimit , & s ) ;
2010-12-16 10:59:50 +00:00
if ( U_FAILURE ( s ) )
{
uregex_close ( r ) ;
return NULL ;
}
return r ;
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-22 12:52:56 +00:00
# else
static URegularExpression *
setupRegex ( URegularExpression * regex ,
NSString * string ,
unichar * buffer ,
int32_t length ,
NSMatchingOptions options ,
NSRange range ,
GSRegexBlock block )
{
UErrorCode s = 0 ;
URegularExpression * r = uregex_clone ( regex , & s ) ;
[ string getCharacters : buffer range : NSMakeRange ( 0 , length ) ] ;
if ( options & NSMatchingReportProgress )
{
uregex_setMatchCallback ( r , callback , block , & s ) ;
}
uregex_setText ( r , buffer , length , & s ) ;
uregex_setRegion ( r , range . location , range . location + range . length , & s ) ;
if ( options & NSMatchingWithoutAnchoringBounds )
{
uregex_useAnchoringBounds ( r , FALSE , & s ) ;
}
if ( options & NSMatchingWithTransparentBounds )
{
uregex_useTransparentBounds ( r , TRUE , & s ) ;
}
2016-06-17 09:04:04 +00:00
uregex_setTimeLimit ( r , _workLimit , & s ) ;
2011-12-22 12:52:56 +00:00
if ( U_FAILURE ( s ) )
{
uregex_close ( r ) ;
return NULL ;
}
return r ;
}
# endif
2010-12-16 10:59:50 +00:00
static uint32_t
prepareResult ( NSRegularExpression * regex ,
URegularExpression * r ,
NSRangePointer ranges ,
NSUInteger groups ,
UErrorCode * s )
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
{
2010-12-16 10:59:50 +00:00
uint32_t flags = 0 ;
NSUInteger i = 0 ;
for ( i = 0 ; i < groups ; i + + )
{
2015-09-01 11:31:16 +00:00
NSInteger start = uregex_start ( r , i , s ) ;
NSInteger end = uregex_end ( r , i , s ) ;
2023-11-13 19:45:16 +00:00
/ * The ICU API defines -1 as not found . Convert to
* NSNotFound if applicable .
* /
2015-09-01 11:31:16 +00:00
if ( start = = -1 )
{
start = NSNotFound ;
}
if ( end = = -1 )
{
end = NSNotFound ;
}
2010-12-16 10:59:50 +00:00
2014-04-12 04:38:13 +00:00
if ( end < start )
{
flags | = NSMatchingInternalError ;
end = start = NSNotFound ;
}
2010-12-16 10:59:50 +00:00
ranges [ i ] = NSMakeRange ( start , end - start ) ;
}
if ( uregex_hitEnd ( r , s ) )
{
flags | = NSMatchingHitEnd ;
}
if ( uregex_requireEnd ( r , s ) )
{
flags | = NSMatchingRequiredEnd ;
}
if ( 0 ! = * s )
{
flags | = NSMatchingInternalError ;
}
return flags ;
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-22 12:52:56 +00:00
# if HAVE_UREGEX _OPENUTEXT
2010-12-16 10:59:50 +00:00
- ( void ) enumerateMatchesInString : ( NSString * ) string
options : ( NSMatchingOptions ) opts
range : ( NSRange ) range
usingBlock : ( GSRegexBlock ) block
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
{
2023-11-13 19:45:16 +00:00
UErrorCode s = 0 ;
UText txt = UTEXT_INITIALIZER ;
BOOL stop = NO ;
URegularExpression * r = setupRegex ( regex , string , & txt , opts , range , block ) ;
NSUInteger groups = [ self numberOfCaptureGroups ] + 1 ;
NSRange ranges [ groups ] ;
2010-12-16 10:59:50 +00:00
// Should this throw some kind of exception ?
if ( NULL = = r )
{
return ;
}
if ( opts & NSMatchingAnchored )
{
if ( uregex_lookingAt ( r , -1 , & s ) && ( 0 = = s ) )
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
{
2010-12-16 10:59:50 +00:00
// FIXME : Factor all of this out into prepareResult ( )
uint32_t flags ;
NSTextCheckingResult * result ;
flags = prepareResult ( self , r , ranges , groups , & s ) ;
2014-04-12 04:38:13 +00:00
result = ( flags & NSMatchingInternalError ) ? nil
: [ NSTextCheckingResult
2010-12-16 10:59:50 +00:00
regularExpressionCheckingResultWithRanges : ranges
count : groups
regularExpression : self ] ;
CALL_BLOCK ( block , result , flags , & stop ) ;
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
}
2010-12-16 10:59:50 +00:00
}
else
{
while ( ! stop && uregex_findNext ( r , & s ) && ( 0 = = s ) )
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
{
2010-12-16 10:59:50 +00:00
uint32_t flags ;
NSTextCheckingResult * result ;
flags = prepareResult ( self , r , ranges , groups , & s ) ;
2014-04-12 04:38:13 +00:00
result = ( flags & NSMatchingInternalError ) ? nil
: [ NSTextCheckingResult
2010-12-16 10:59:50 +00:00
regularExpressionCheckingResultWithRanges : ranges
count : groups
regularExpression : self ] ;
CALL_BLOCK ( block , result , flags , & stop ) ;
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
}
2010-12-16 10:59:50 +00:00
}
if ( opts & NSMatchingCompleted )
{
CALL_BLOCK ( block , nil , NSMatchingCompleted , & stop ) ;
}
utext_close ( & txt ) ;
uregex_close ( r ) ;
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-22 12:52:56 +00:00
# else
- ( void ) enumerateMatchesInString : ( NSString * ) string
options : ( NSMatchingOptions ) opts
range : ( NSRange ) range
usingBlock : ( GSRegexBlock ) block
{
2023-11-13 19:45:16 +00:00
UErrorCode s = 0 ;
BOOL stop = NO ;
int32_t length = [ string length ] ;
URegularExpression * r ;
NSUInteger groups = [ self numberOfCaptureGroups ] + 1 ;
NSRange ranges [ groups ] ;
2011-12-22 12:52:56 +00:00
TEMP_BUFFER ( buffer , length ) ;
r = setupRegex ( regex , string , buffer , length , opts , range , block ) ;
// Should this throw some kind of exception ?
if ( NULL = = r )
{
return ;
}
if ( opts & NSMatchingAnchored )
{
if ( uregex_lookingAt ( r , -1 , & s ) && ( 0 = = s ) )
{
// FIXME : Factor all of this out into prepareResult ( )
uint32_t flags ;
NSTextCheckingResult * result ;
flags = prepareResult ( self , r , ranges , groups , & s ) ;
2014-04-12 04:38:13 +00:00
result = ( flags & NSMatchingInternalError ) ? nil
: [ NSTextCheckingResult
2011-12-22 12:52:56 +00:00
regularExpressionCheckingResultWithRanges : ranges
count : groups
regularExpression : self ] ;
CALL_BLOCK ( block , result , flags , & stop ) ;
}
}
else
{
while ( ! stop && uregex_findNext ( r , & s ) && ( 0 = = s ) )
{
uint32_t flags ;
NSTextCheckingResult * result ;
flags = prepareResult ( self , r , ranges , groups , & s ) ;
2014-04-12 04:38:13 +00:00
result = ( flags & NSMatchingInternalError ) ? nil
: [ NSTextCheckingResult
2011-12-22 12:52:56 +00:00
regularExpressionCheckingResultWithRanges : ranges
count : groups
regularExpression : self ] ;
CALL_BLOCK ( block , result , flags , & stop ) ;
}
}
if ( opts & NSMatchingCompleted )
{
CALL_BLOCK ( block , nil , NSMatchingCompleted , & stop ) ;
}
uregex_close ( r ) ;
}
# endif
2010-12-16 10:59:50 +00:00
/ * The remaining methods are all meant to be wrappers around the primitive
* method that takes a block argument . Unfortunately , this is not really
* possible when compiling with a compiler that doesn ' t support blocks .
* /
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 __has _feature ( blocks )
2010-12-16 10:59:50 +00:00
- ( NSUInteger ) numberOfMatchesInString : ( NSString * ) string
options : ( NSMatchingOptions ) opts
range : ( 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
{
2010-12-16 10:59:50 +00:00
__block NSUInteger count = 0 ;
2024-05-12 09:03:15 +00:00
GSRegexBlock block ;
2010-12-16 10:59:50 +00:00
opts & = ~ NSMatchingReportProgress ;
opts & = ~ NSMatchingReportCompletion ;
2024-05-12 09:03:15 +00:00
block =
2010-12-16 10:59:50 +00:00
^ ( NSTextCheckingResult * result , NSMatchingFlags flags , BOOL * stop )
{
count + + ;
} ;
[ self enumerateMatchesInString : string
options : opts
range : range
usingBlock : block ] ;
return count ;
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
}
2010-12-16 10:59:50 +00:00
- ( NSTextCheckingResult * ) firstMatchInString : ( NSString * ) string
options : ( NSMatchingOptions ) opts
range : ( 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
{
2024-05-12 09:03:15 +00:00
__block NSTextCheckingResult * r = nil ;
GSRegexBlock block ;
2010-12-16 10:59:50 +00:00
opts & = ~ NSMatchingReportProgress ;
opts & = ~ NSMatchingReportCompletion ;
2024-05-12 09:03:15 +00:00
block =
2010-12-16 10:59:50 +00:00
^ ( NSTextCheckingResult * result , NSMatchingFlags flags , BOOL * stop )
{
r = result ;
* stop = YES ;
} ;
[ self enumerateMatchesInString : string
options : opts
range : range
usingBlock : block ] ;
return r ;
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
}
2010-12-16 10:59:50 +00:00
- ( NSArray * ) matchesInString : ( NSString * ) string
options : ( NSMatchingOptions ) opts
range : ( 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
{
2010-12-16 10:59:50 +00:00
NSMutableArray * array = [ NSMutableArray array ] ;
2024-05-12 09:03:15 +00:00
GSRegexBlock block ;
2010-12-16 10:59:50 +00:00
opts & = ~ NSMatchingReportProgress ;
opts & = ~ NSMatchingReportCompletion ;
2024-05-12 09:03:15 +00:00
block =
2010-12-16 10:59:50 +00:00
^ ( NSTextCheckingResult * result , NSMatchingFlags flags , BOOL * stop )
{
[ array addObject : result ] ;
} ;
[ self enumerateMatchesInString : string
options : opts
range : range
usingBlock : block ] ;
return array ;
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
}
2010-12-16 10:59:50 +00:00
- ( NSRange ) rangeOfFirstMatchInString : ( NSString * ) string
options : ( NSMatchingOptions ) opts
range : ( 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
{
2024-05-12 09:03:15 +00:00
__block NSRange r = { NSNotFound , 0 } ;
GSRegexBlock block ;
2010-12-16 10:59:50 +00:00
opts & = ~ NSMatchingReportProgress ;
opts & = ~ NSMatchingReportCompletion ;
2024-05-12 09:03:15 +00:00
block =
2010-12-16 10:59:50 +00:00
^ ( NSTextCheckingResult * result , NSMatchingFlags flags , BOOL * stop )
{
r = [ result range ] ;
* stop = YES ;
} ;
[ self enumerateMatchesInString : string
options : opts
range : range
usingBlock : block ] ;
return r ;
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
}
2010-12-16 10:59:50 +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
# else
2013-02-28 16:50:37 +00:00
# ifdef __clang __ / * FIXME . . . this is blocks specific , not clang specific * /
2012-03-27 10:03:40 +00:00
# warning Your compiler does not support blocks . NSRegularExpression will deviate from the documented behaviour when subclassing and any code that subclasses NSRegularExpression may break in unexpected ways . If you must subclass NSRegularExpression , you may want to use a compiler with blocks support .
# warning Your compiler would support blocks if you added - fblocks to your OBJCFLAGS
# endif
2011-12-22 12:52:56 +00:00
# if HAVE_UREGEX _OPENUTEXT
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
# define FAKE_BLOCK _HACK ( failRet , code ) \
2023-11-13 19:45:16 +00:00
UErrorCode s = 0 ; \
UText txt = UTEXT_INITIALIZER ; \
BOOL stop = NO ; \
URegularExpression * r = setupRegex ( regex , string , & txt , opts , range , 0 ) ; \
\
2010-12-16 10:59:50 +00:00
if ( NULL = = r ) { return failRet ; } \
if ( opts & NSMatchingAnchored ) \
{ \
if ( uregex_lookingAt ( r , -1 , & s ) && ( 0 = = s ) ) \
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
{ \
2010-12-16 10:59:50 +00:00
code \
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
} \
2010-12-16 10:59:50 +00:00
} \
else \
{ \
while ( ! stop && uregex_findNext ( r , & s ) && ( s = = 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
{ \
2010-12-16 10:59:50 +00:00
code \
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
} \
2010-12-16 10:59:50 +00:00
} \
utext_close ( & txt ) ; \
uregex_close ( r ) ;
2011-12-22 12:52:56 +00:00
# else
# define FAKE_BLOCK _HACK ( failRet , code ) \
UErrorCode s = 0 ; \
BOOL stop = NO ; \
uint32_t length = [ string length ] ; \
URegularExpression * r ; \
TEMP_BUFFER ( buffer , length ) ; \
r = setupRegex ( regex , string , buffer , length , opts , range , 0 ) ; \
if ( NULL = = r ) { return failRet ; } \
if ( opts & NSMatchingAnchored ) \
{ \
if ( uregex_lookingAt ( r , -1 , & s ) && ( 0 = = s ) ) \
{ \
code \
} \
} \
else \
{ \
while ( ! stop && uregex_findNext ( r , & s ) && ( s = = 0 ) ) \
{ \
code \
} \
} \
uregex_close ( r ) ;
# endif
2010-12-16 10:59:50 +00:00
- ( NSUInteger ) numberOfMatchesInString : ( NSString * ) string
options : ( NSMatchingOptions ) opts
range : ( 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
{
2010-12-16 10:59:50 +00:00
NSUInteger count = 0 ;
FAKE_BLOCK _HACK ( count ,
{
count + + ;
} ) ;
return count ;
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
}
2010-12-16 10:59:50 +00:00
- ( NSTextCheckingResult * ) firstMatchInString : ( NSString * ) string
options : ( NSMatchingOptions ) opts
range : ( 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
{
2010-12-16 10:59:50 +00:00
NSTextCheckingResult * result = nil ;
NSUInteger groups = [ self numberOfCaptureGroups ] + 1 ;
NSRange ranges [ groups ] ;
FAKE_BLOCK _HACK ( result ,
{
2014-04-12 04:38:13 +00:00
uint32_t flags ;
flags = prepareResult ( self , r , ranges , groups , & s ) ;
result = ( flags & NSMatchingInternalError ) ? nil
: [ NSTextCheckingResult
2010-12-16 10:59:50 +00:00
regularExpressionCheckingResultWithRanges : ranges
count : groups
regularExpression : self ] ;
stop = YES ;
} ) ;
return result ;
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
}
2010-12-16 10:59:50 +00:00
- ( NSArray * ) matchesInString : ( NSString * ) string
options : ( NSMatchingOptions ) opts
range : ( 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
{
2010-12-16 10:59:50 +00:00
NSMutableArray * array = [ NSMutableArray array ] ;
NSUInteger groups = [ self numberOfCaptureGroups ] + 1 ;
NSRange ranges [ groups ] ;
FAKE_BLOCK _HACK ( array ,
{
NSTextCheckingResult * result = NULL ;
2014-04-12 04:38:13 +00:00
uint32_t flags ;
2010-12-16 10:59:50 +00:00
2014-04-12 04:38:13 +00:00
flags = prepareResult ( self , r , ranges , groups , & s ) ;
result = ( flags & NSMatchingInternalError ) ? nil
: [ NSTextCheckingResult
2010-12-16 10:59:50 +00:00
regularExpressionCheckingResultWithRanges : ranges
count : groups
regularExpression : self ] ;
2014-04-12 04:38:13 +00:00
if ( nil ! = result )
{
[ array addObject : result ] ;
}
2010-12-16 10:59:50 +00:00
} ) ;
return array ;
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
}
2010-12-16 10:59:50 +00:00
- ( NSRange ) rangeOfFirstMatchInString : ( NSString * ) string
options : ( NSMatchingOptions ) opts
range : ( 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 14:59:14 +00:00
NSRange result = { NSNotFound , 0 } ;
2010-12-16 10:59:50 +00:00
FAKE_BLOCK _HACK ( result ,
{
prepareResult ( self , r , & result , 1 , & s ) ;
stop = YES ;
} ) ;
return result ;
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
}
2010-12-16 10:59:50 +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
# endif
2010-12-16 10:59:50 +00:00
2011-12-22 12:52:56 +00:00
# if HAVE_UREGEX _OPENUTEXT
2010-12-16 10:59:50 +00:00
- ( NSUInteger ) replaceMatchesInString : ( NSMutableString * ) string
options : ( NSMatchingOptions ) opts
range : ( NSRange ) range
withTemplate : ( NSString * ) template
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
{
2010-12-16 10:59:50 +00:00
// FIXME : We ' re computing a value that is most likely ignored in an
// expensive way .
2024-11-21 21:05:34 +00:00
NSInteger results = [ self numberOfMatchesInString : string
options : opts
range : range ] ;
UErrorCode s = 0 ;
UText txt = UTEXT_INITIALIZER ;
UText replacement = UTEXT_INITIALIZER ;
GSUTextString * ret = [ GSUTextString new ] ;
URegularExpression * r = setupRegex ( regex , string , & txt , opts , range , 0 ) ;
UText * output = NULL ;
2010-12-16 10:59:50 +00:00
UTextInitWithNSString ( & replacement , template ) ;
2024-11-21 21:05:34 +00:00
output = uregex_replaceAllUText ( r , & replacement , NULL , & s ) ;
2016-10-12 13:43:32 +00:00
if ( 0 ! = s )
{
2024-11-21 21:05:34 +00:00
uregex_close ( r ) ;
utext_close ( & replacement ) ;
utext_close ( & txt ) ;
DESTROY ( ret ) ;
2016-10-12 13:43:32 +00:00
return 0 ;
}
2024-11-21 21:05:34 +00:00
utext_clone ( & ret -> txt , output , TRUE , TRUE , & s ) ;
[ string setString : ret ] ;
RELEASE ( ret ) ;
uregex_close ( r ) ;
utext_close ( & txt ) ;
utext_close ( output ) ;
utext_close ( & replacement ) ;
2010-12-16 10:59:50 +00:00
return results ;
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
}
2010-12-16 10:59:50 +00:00
- ( NSString * ) stringByReplacingMatchesInString : ( NSString * ) string
options : ( NSMatchingOptions ) opts
range : ( NSRange ) range
withTemplate : ( NSString * ) template
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
{
2024-11-21 21:05:34 +00:00
UErrorCode s = 0 ;
UText txt = UTEXT_INITIALIZER ;
UText replacement = UTEXT_INITIALIZER ;
UText * output = NULL ;
GSUTextString * ret = [ GSUTextString new ] ;
URegularExpression * r = setupRegex ( regex , string , & txt , opts , range , 0 ) ;
2010-12-16 10:59:50 +00:00
UTextInitWithNSString ( & replacement , template ) ;
2024-11-21 21:05:34 +00:00
output = uregex_replaceAllUText ( r , & replacement , NULL , & s ) ;
2016-10-12 13:43:32 +00:00
if ( 0 ! = s )
{
2024-11-21 21:05:34 +00:00
uregex_close ( r ) ;
utext_close ( & replacement ) ;
utext_close ( & txt ) ;
DESTROY ( ret ) ;
2016-10-12 13:43:32 +00:00
return nil ;
}
2024-11-21 21:05:34 +00:00
utext_clone ( & ret -> txt , output , TRUE , TRUE , & s ) ;
uregex_close ( r ) ;
utext_close ( & txt ) ;
utext_close ( output ) ;
utext_close ( & replacement ) ;
return AUTORELEASE ( ret ) ;
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
}
2010-12-16 10:59:50 +00:00
- ( NSString * ) replacementStringForResult : ( NSTextCheckingResult * ) result
inString : ( NSString * ) string
offset : ( NSInteger ) offset
template : ( NSString * ) template
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
{
2024-11-21 21:05:34 +00:00
UErrorCode s = 0 ;
UText txt = UTEXT_INITIALIZER ;
UText replacement = UTEXT_INITIALIZER ;
UText * output = NULL ;
GSUTextString * ret = [ GSUTextString new ] ;
NSRange range = [ result range ] ;
URegularExpression * r = setupRegex ( regex ,
2010-12-16 10:59:50 +00:00
[ string substringWithRange : range ] ,
& txt ,
0 ,
NSMakeRange ( 0 , range . length ) ,
0 ) ;
UTextInitWithNSString ( & replacement , template ) ;
2024-11-21 21:05:34 +00:00
output = uregex_replaceFirstUText ( r , & replacement , NULL , & s ) ;
2016-10-12 13:43:32 +00:00
if ( 0 ! = s )
{
2024-11-21 21:05:34 +00:00
uregex_close ( r ) ;
utext_close ( & replacement ) ;
utext_close ( & txt ) ;
DESTROY ( ret ) ;
2016-10-12 13:43:32 +00:00
return nil ;
}
2024-11-21 21:05:34 +00:00
utext_clone ( & ret -> txt , output , TRUE , TRUE , & s ) ;
utext_close ( output ) ;
uregex_close ( r ) ;
utext_close ( & txt ) ;
utext_close ( & replacement ) ;
return AUTORELEASE ( ret ) ;
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-22 12:52:56 +00:00
# else
- ( NSUInteger ) replaceMatchesInString : ( NSMutableString * ) string
options : ( NSMatchingOptions ) opts
range : ( NSRange ) range
withTemplate : ( NSString * ) template
{
// FIXME : We ' re computing a value that is most likely ignored in an
// expensive way .
NSInteger results = [ self numberOfMatchesInString : string
options : opts
range : range ] ;
2024-11-21 21:05:34 +00:00
if ( results > 0 )
{
UErrorCode s = 0 ;
uint32_t length = [ string length ] ;
uint32_t replLength = [ template length ] ;
unichar replacement [ replLength ] ;
int32_t outLength ;
URegularExpression * r ;
TEMP_BUFFER ( buffer , length ) ;
r = setupRegex ( regex , string , buffer , length , opts , range , 0 ) ;
[ template getCharacters : replacement range : NSMakeRange ( 0 , replLength ) ] ;
outLength = uregex_replaceAll ( r , replacement , replLength , NULL , 0 , & s ) ;
if ( 0 = = s || U_BUFFER _OVERFLOW _ERROR = = s )
{
unichar * output ;
s = 0 ; // May have been set to a buffer overflow error
output = NSZoneMalloc ( 0 , ( outLength + 1 ) * sizeof ( unichar ) ) ;
uregex_replaceAll ( r , replacement , replLength ,
output , outLength + 1 , & s ) ;
if ( 0 = = s )
{
NSString * out ;
out = [ [ NSString alloc ] initWithCharactersNoCopy : output
length : outLength
freeWhenDone : YES ] ;
[ string setString : out ] ;
RELEASE ( out ) ;
}
else
{
NSZoneFree ( 0 , output ) ;
results = 0 ;
}
}
else
{
results = 0 ;
}
uregex_close ( r ) ;
}
2011-12-22 12:52:56 +00:00
return results ;
}
- ( NSString * ) stringByReplacingMatchesInString : ( NSString * ) string
options : ( NSMatchingOptions ) opts
range : ( NSRange ) range
withTemplate : ( NSString * ) template
{
UErrorCode s = 0 ;
uint32_t length = [ string length ] ;
URegularExpression * r ;
uint32_t replLength = [ template length ] ;
unichar replacement [ replLength ] ;
int32_t outLength ;
2024-11-21 21:05:34 +00:00
NSString * result = nil ;
2011-12-22 12:52:56 +00:00
TEMP_BUFFER ( buffer , length ) ;
r = setupRegex ( regex , string , buffer , length , opts , range , 0 ) ;
[ template getCharacters : replacement range : NSMakeRange ( 0 , replLength ) ] ;
outLength = uregex_replaceAll ( r , replacement , replLength , NULL , 0 , & s ) ;
2024-11-21 21:05:34 +00:00
if ( 0 = = s || U_BUFFER _OVERFLOW _ERROR = = s )
{
unichar * output ;
s = 0 ; // may have been set to a buffer overflow error
output = NSZoneMalloc ( 0 , ( outLength + 1 ) * sizeof ( unichar ) ) ;
uregex_replaceAll ( r , replacement , replLength , output , outLength + 1 , & s ) ;
if ( 0 = = s )
{
result = AUTORELEASE ( [ [ NSString alloc ]
initWithCharactersNoCopy : output
length : outLength
freeWhenDone : YES ] ) ;
}
else
{
NSZoneFree ( 0 , output ) ;
}
}
2011-12-22 12:52:56 +00:00
2024-11-21 21:05:34 +00:00
uregex_close ( r ) ;
return result ;
2011-12-22 12:52:56 +00:00
}
- ( NSString * ) replacementStringForResult : ( NSTextCheckingResult * ) result
inString : ( NSString * ) string
offset : ( NSInteger ) offset
template : ( NSString * ) template
{
UErrorCode s = 0 ;
NSRange range = [ result range ] ;
URegularExpression * r ;
uint32_t replLength = [ template length ] ;
unichar replacement [ replLength ] ;
int32_t outLength ;
2024-11-21 21:05:34 +00:00
NSString * str = nil ;
2011-12-22 12:52:56 +00:00
TEMP_BUFFER ( buffer , range . length ) ;
r = setupRegex ( regex ,
[ string substringWithRange : range ] ,
buffer ,
range . length ,
0 ,
NSMakeRange ( 0 , range . length ) ,
0 ) ;
[ template getCharacters : replacement range : NSMakeRange ( 0 , replLength ) ] ;
outLength = uregex_replaceFirst ( r , replacement , replLength , NULL , 0 , & s ) ;
2024-11-21 21:05:34 +00:00
if ( 0 = = s || U_BUFFER _OVERFLOW _ERROR = = s )
{
unichar * output ;
s = 0 ;
output = NSZoneMalloc ( 0 , ( outLength + 1 ) * sizeof ( unichar ) ) ;
uregex_replaceFirst ( r , replacement , replLength ,
output , outLength + 1 , & s ) ;
if ( 0 = = s )
{
str = AUTORELEASE ( [ [ NSString alloc ]
initWithCharactersNoCopy : output
length : outLength
freeWhenDone : YES ] ) ;
}
else
{
NSZoneFree ( 0 , output ) ;
}
}
uregex_close ( r ) ;
return str ;
2011-12-22 12:52:56 +00:00
}
# endif
2010-12-16 10:59:50 +00:00
2024-05-12 09:03:15 +00:00
+ ( NSString * ) escapedPatternForString : ( NSString * ) string
{
/ * https : // unicode - org . github . io / icu / userguide / strings / regexp . html
* Need to escape * ? + [ ( ) { } ^ $ | \ .
* /
2023-01-04 02:33:47 +00:00
return [ [ NSRegularExpression
regularExpressionWithPattern : @ "([*?+\\[(){}^$|\\\\.])"
options : 0
error : NULL ]
stringByReplacingMatchesInString : string
options : 0
range : NSMakeRange ( 0 , [ string length ] )
withTemplate : @ "\\\\$1"
] ;
}
2010-12-16 10:59:50 +00:00
- ( NSRegularExpressionOptions ) options
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
{
2010-12-16 10:59:50 +00:00
return options ;
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
}
2010-12-16 10:59:50 +00:00
- ( NSUInteger ) numberOfCaptureGroups
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
{
2010-12-16 10:59:50 +00:00
UErrorCode s = 0 ;
return uregex_groupCount ( regex , & s ) ;
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
}
2010-12-16 10:59:50 +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
{
2010-12-16 10:59:50 +00:00
uregex_close ( regex ) ;
[ 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
}
2010-12-16 10:59:50 +00:00
- ( void ) encodeWithCoder : ( NSCoder * ) aCoder
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
{
2010-12-16 10:59:50 +00:00
if ( [ aCoder allowsKeyedCoding ] )
{
[ aCoder encodeInteger : options forKey : @ "options" ] ;
[ aCoder encodeObject : [ self pattern ] forKey : @ "pattern" ] ;
}
else
{
[ aCoder encodeValueOfObjCType : @ encode ( NSRegularExpressionOptions )
at : & options ] ;
[ aCoder encodeObject : [ self pattern ] ] ;
}
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
}
2010-12-16 10:59:50 +00:00
- ( id ) initWithCoder : ( NSCoder * ) aCoder
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-08-03 12:04:27 +00:00
NSString * pattern ;
2010-12-16 10:59:50 +00:00
if ( [ aCoder allowsKeyedCoding ] )
{
2011-08-03 12:04:27 +00:00
options = [ aCoder decodeIntegerForKey : @ "options" ] ;
pattern = [ aCoder decodeObjectForKey : @ "pattern" ] ;
2010-12-16 10:59:50 +00:00
}
else
{
[ aCoder decodeValueOfObjCType : @ encode ( NSRegularExpressionOptions )
2011-08-03 12:04:27 +00:00
at : & options ] ;
pattern = [ aCoder decodeObject ] ;
2010-12-16 10:59:50 +00:00
}
2011-08-03 12:04:27 +00:00
return [ self initWithPattern : pattern options : options error : NULL ] ;
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
}
2010-12-16 10:59:50 +00:00
- ( id ) copyWithZone : ( NSZone * ) aZone
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
{
2010-12-16 10:59:50 +00:00
NSRegularExpressionOptions opts = options ;
UErrorCode s = 0 ;
URegularExpression * r = uregex_clone ( regex , & s ) ;
if ( 0 ! = s )
{
return nil ;
}
self = [ [ self class ] allocWithZone : aZone ] ;
if ( nil = = self )
{
return nil ;
}
options = opts ;
regex = r ;
return self ;
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
2011-12-22 12:52:56 +00:00
# endif // GS_ICU = = 1
2011-08-03 12:04:27 +00:00
# ifndef NSRegularExpressionWorks
# import "Foundation/NSRegularExpression.h"
# import "Foundation/NSZone.h"
# import "Foundation/NSException.h"
@ implementation NSRegularExpression
+ ( id ) allocWithZone : ( NSZone * ) aZone
{
[ NSException raise : NSInvalidArgumentException
format : @ "NSRegularExpression requires ICU 4.4 or later" ] ;
return nil ;
}
- ( id ) copyWithZone : ( NSZone * ) zone
{
return nil ;
}
- ( void ) encodeWithCoder : ( NSCoder * ) aCoder
{
}
- ( id ) initWithCoder : ( NSCoder * ) aCoder
{
return nil ;
}
@ end
# endif