Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Named captures #2

Merged
merged 4 commits into from

2 participants

@shadowphoenix

These commits adds some lines to gitignore for new Xcode 4 files, fixes a couple of warnings when using clang to compile, adds support for garbage collection (by placing the free calls into -finalize), and adds support for retrieving the list of names used in a regexp.

@psychs psychs merged commit 22ea68d into from
@psychs
Owner

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
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]];
Something went wrong with that request. Please try again.