File: regex.m

package info (click to toggle)
gnustep-base 1.31.1-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 26,580 kB
  • sloc: objc: 239,446; ansic: 36,519; cpp: 122; sh: 112; makefile: 100; xml: 32
file content (45 lines) | stat: -rw-r--r-- 1,458 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#import <Foundation/NSString.h>
#import <Foundation/NSRegularExpression.h>
#import "ObjectTesting.h"

int main(void)
{
  [NSAutoreleasePool new];
  START_SET("NSString + regex")

#if !(__APPLE__ || GS_USE_ICU)
  SKIP("NSRegularExpression not built, please install libicu")
#else
  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)]);
#endif

  END_SET("NSString + regex")
  return 0;
}