Permalink
Browse files

Merge pull request #2 from shadowphoenix/master

Named captures
  • Loading branch information...
2 parents 60f6063 + 6fd2647 commit 22ea68d165a247cf5eb0781f31ce83652618efd8 @psychs committed May 7, 2011
View
1 .gitignore
@@ -18,4 +18,5 @@ BuildLog.htm
mt.dep
debuglog.*
*.intermediate.manifest
+xcuserdata/
View
6 framework/CocoaOniguruma.xcodeproj/project.pbxproj
@@ -330,7 +330,11 @@
isa = PBXProject;
buildConfigurationList = 1DEB91B108733DA50010E9CD /* Build configuration list for PBXProject "CocoaOniguruma" */;
compatibilityVersion = "Xcode 3.0";
+ developmentRegion = English;
hasScannedForEncodings = 1;
+ knownRegions = (
+ en,
+ );
mainGroup = 0867D691FE84028FC02AAC07 /* CocoaOniguruma */;
productRefGroup = 034768DFFF38A50411DB9C8B /* Products */;
projectDirPath = "";
@@ -452,6 +456,7 @@
FRAMEWORK_VERSION = A;
GCC_DYNAMIC_NO_PIC = NO;
GCC_ENABLE_FIX_AND_CONTINUE = YES;
+ GCC_ENABLE_OBJC_GC = supported;
GCC_MODEL_TUNING = G5;
GCC_OPTIMIZATION_LEVEL = 0;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
@@ -471,6 +476,7 @@
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
FRAMEWORK_VERSION = A;
+ GCC_ENABLE_OBJC_GC = supported;
GCC_MODEL_TUNING = G5;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = CocoaOniguruma_Prefix.pch;
View
7 framework/CocoaOniguruma.xcodeproj/project.xcworkspace/contents.xcworkspacedata
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<Workspace
+ version = "1.0">
+ <FileRef
+ location = "self:CocoaOniguruma.xcodeproj">
+ </FileRef>
+</Workspace>
View
2 framework/core/OnigRegexp.h
@@ -57,6 +57,7 @@ typedef enum {
OnigRegexp* _expression;
OnigRegion* _region;
NSString* _target;
+ NSMutableArray* _captureNames;
}
- (NSString*)target;
@@ -75,6 +76,7 @@ typedef enum {
- (NSString*)postMatch;
// named capture support
+- (NSArray*) captureNames;
- (int)indexForName:(NSString*)name;
- (NSIndexSet*)indexesForName:(NSString*)name;
- (NSString*)stringForName:(NSString*)name;
View
33 framework/core/OnigRegexp.m
@@ -16,6 +16,9 @@
@interface OnigResult (Private)
- (id)initWithRegexp:(OnigRegexp*)expression region:(OnigRegion*)region target:(NSString*)target;
+
+- (NSMutableArray*) captureNameArray;
+
@end
@@ -38,6 +41,11 @@ - (void)dealloc
[super dealloc];
}
+- (void)finalize {
+ if (_entity) onig_free(_entity);
+ [super finalize];
+}
+
+ (OnigRegexp*)compile:(NSString*)expression
{
return [self compile:expression ignorecase:NO multiline:NO extended:NO];
@@ -179,6 +187,7 @@ - (id)initWithRegexp:(OnigRegexp*)expression region:(OnigRegion*)region target:(
_expression = [expression retain];
_region = region;
_target = [target copy];
+ _captureNames = [NSMutableArray array];
}
return self;
}
@@ -191,6 +200,12 @@ - (void)dealloc
[super dealloc];
}
+- (void)finalize
+{
+ if (_region) onig_region_free(_region, 1);
+ [super finalize];
+}
+
- (NSString*)target
{
return _target;
@@ -256,6 +271,24 @@ - (NSString*)postMatch
return [_target substringFromIndex:[self locationAt:0] + [self lengthAt:0]];
}
+- (NSMutableArray*) captureNameArray {
+ return self->_captureNames;
+}
+
+
+// Used to get list of names
+int co_name_callback(const OnigUChar *name, const OnigUChar *end, int ngroups, int *group_list, OnigRegex re, void *arg) {
+ OnigResult *result = (OnigResult *)arg;
+
+ [[result captureNameArray] addObject:[NSString stringWithUTF8String:(const char*)name]];
+ return 0;
+}
+
+- (NSArray*) captureNames {
+ onig_foreach_name([self->_expression entity],co_name_callback,self);
+ return [NSArray arrayWithArray:self->_captureNames];
+}
+
- (int)indexForName:(NSString*)name
{
NSIndexSet* indexes = [self indexesForName:name];
View
4 framework/core/OnigRegexpUtility.m
@@ -108,7 +108,7 @@ - (NSArray*)__split:(id)pattern limit:(NSNumber*)limitNum
BOOL lastNull = NO;
OnigResult* res;
- while (res = [pattern search:target start:start]) {
+ while ((res = [pattern search:target start:start])) {
NSRange range = [res bodyRange];
int end = range.location;
int right = NSMaxRange(range);
@@ -223,7 +223,7 @@ - (NSString*)__replaceAllByRegexp:(id)pattern withCallback:(ReplaceCallback)cp d
}
if ([self length] < offset) break;
- } while (res = [pattern search:self start:offset]);
+ } while ((res = [pattern search:self start:offset]));
if (offset < [self length]) {
[s appendString:[self substringFromIndex:offset]];

0 comments on commit 22ea68d

Please sign in to comment.