2011-07-21 13:17:27 +00:00
# import < Foundation / NSString . h >
2014-04-12 04:38:13 +00:00
# import < Foundation / NSRegularExpression . h >
2011-07-21 13:17:27 +00:00
# import "ObjectTesting.h"
int main ( void )
{
2014-04-12 04:38:13 +00:00
[ NSAutoreleasePool new ] ;
START_SET ( "NSString + regex" )
2011-08-03 12:04:27 +00:00
# if ! ( __APPLE __ || GS_USE _ICU )
2014-04-12 04:38:13 +00:00
SKIP ( "NSRegularExpression not built, please install libicu" )
2011-08-03 12:04:27 +00:00
# else
2014-04-12 04:38:13 +00:00
NSRegularExpression * expr ;
NSString * regex ;
NSString * source ;
NSInteger index ;
NSRange r ;
source = @ "abcdddddd e f g" ;
regex = @ "abcd*" ;
r = [ source rangeOfString : regex options : NSRegularExpressionSearch ] ;
PASS ( r . length = = 9 , "Correct length for regex, expected 9 got %d" ,
( int ) r . length ) ;
regex = @ "aBcD*" ;
r = [ source rangeOfString : regex
options : ( NSRegularExpressionSearch | NSCaseInsensitiveSearch ) ] ;
PASS ( r . length = = 9 , "Correct length for regex, expected 9 got %d" ,
( int ) r . length ) ;
source = @ "h1. Real Acme\n\n||{noborder}{left}Item||{right}Price||\n|Testproduct|{right}2 x $59.50|\n| |{right}net amount: $100.00|\n| |{right}total amount: $119.00|\n\n\nh2. Thanks for your purchase!\n\n\n" ;
expr = [ NSRegularExpression regularExpressionWithPattern : @ "h[123]\\. "
options : NSRegularExpressionCaseInsensitive error : NULL ] ;
index = 33 ;
NSLog ( @ "%@" , [ expr firstMatchInString : source
options : NSMatchingAnchored
range : NSMakeRange ( index , [ source length ] - index - 1 ) ] ) ;
2011-08-03 12:04:27 +00:00
# endif
2014-04-12 04:38:13 +00:00
END_SET ( "NSString + regex" )
return 0 ;
2011-07-21 13:17:27 +00:00
}