Skip to content

Commit

Permalink
reindent
Browse files Browse the repository at this point in the history
psychs committed May 7, 2011
1 parent 22ea68d commit e394a1e
Showing 3 changed files with 78 additions and 77 deletions.
36 changes: 18 additions & 18 deletions framework/core/OnigRegexp.h
Original file line number Diff line number Diff line change
@@ -9,22 +9,22 @@
@class OnigResult;

typedef enum {
OnigOptionNone = ONIG_OPTION_NONE,
OnigOptionIgnorecase = ONIG_OPTION_IGNORECASE,
OnigOptionExtend = ONIG_OPTION_EXTEND,
OnigOptionMultiline = ONIG_OPTION_MULTILINE,
OnigOptionSingleline = ONIG_OPTION_SINGLELINE,
OnigOptionFindLongest = ONIG_OPTION_FIND_LONGEST,
OnigOptionFindNotEmpty = ONIG_OPTION_FIND_NOT_EMPTY,
OnigOptionNegateSingleLine = ONIG_OPTION_NEGATE_SINGLELINE,
OnigOptionDontCaptureGroup = ONIG_OPTION_DONT_CAPTURE_GROUP,
OnigOptionCaptureGroup = ONIG_OPTION_CAPTURE_GROUP,

/* options (search time) */
OnigOptionNotbol = ONIG_OPTION_NOTBOL,
OnigOptionNoteol = ONIG_OPTION_NOTEOL,
OnigOptionPosixRegion = ONIG_OPTION_POSIX_REGION,
OnigOptionMaxbit = ONIG_OPTION_MAXBIT
OnigOptionNone = ONIG_OPTION_NONE,
OnigOptionIgnorecase = ONIG_OPTION_IGNORECASE,
OnigOptionExtend = ONIG_OPTION_EXTEND,
OnigOptionMultiline = ONIG_OPTION_MULTILINE,
OnigOptionSingleline = ONIG_OPTION_SINGLELINE,
OnigOptionFindLongest = ONIG_OPTION_FIND_LONGEST,
OnigOptionFindNotEmpty = ONIG_OPTION_FIND_NOT_EMPTY,
OnigOptionNegateSingleLine = ONIG_OPTION_NEGATE_SINGLELINE,
OnigOptionDontCaptureGroup = ONIG_OPTION_DONT_CAPTURE_GROUP,
OnigOptionCaptureGroup = ONIG_OPTION_CAPTURE_GROUP,
/* options (search time) */
OnigOptionNotbol = ONIG_OPTION_NOTBOL,
OnigOptionNoteol = ONIG_OPTION_NOTEOL,
OnigOptionPosixRegion = ONIG_OPTION_POSIX_REGION,
OnigOptionMaxbit = ONIG_OPTION_MAXBIT
} OnigOption;

@interface OnigRegexp : NSObject
@@ -57,7 +57,7 @@ typedef enum {
OnigRegexp* _expression;
OnigRegion* _region;
NSString* _target;
NSMutableArray* _captureNames;
NSMutableArray* _captureNames;
}

- (NSString*)target;
@@ -76,7 +76,7 @@ typedef enum {
- (NSString*)postMatch;

// named capture support
- (NSArray*) captureNames;
- (NSArray*)captureNames;
- (int)indexForName:(NSString*)name;
- (NSIndexSet*)indexesForName:(NSString*)name;
- (NSString*)stringForName:(NSString*)name;
87 changes: 44 additions & 43 deletions framework/core/OnigRegexp.m
Original file line number Diff line number Diff line change
@@ -41,9 +41,10 @@ - (void)dealloc
[super dealloc];
}

- (void)finalize {
if (_entity) onig_free(_entity);
[super finalize];
- (void)finalize
{
if (_entity) onig_free(_entity);
[super finalize];
}

+ (OnigRegexp*)compile:(NSString*)expression
@@ -63,11 +64,11 @@ + (OnigRegexp*)compile:(NSString*)expression ignorecase:(BOOL)ignorecase multili

+ (OnigRegexp*)compile:(NSString*)expression ignorecase:(BOOL)ignorecase multiline:(BOOL)multiline extended:(BOOL)extended
{
OnigOption options = OnigOptionNone;
options |= multiline ? OnigOptionMultiline : OnigOptionSingleline;
if(ignorecase) options |= OnigOptionIgnorecase;
if(extended) options |= OnigOptionExtend;
return [self compile:expression options:options];
OnigOption options = OnigOptionNone;
options |= multiline ? OnigOptionMultiline : OnigOptionSingleline;
if(ignorecase) options |= OnigOptionIgnorecase;
if(extended) options |= OnigOptionExtend;
return [self compile:expression options:options];
}

+ (OnigRegexp*)compile:(NSString*)expression options:(OnigOption)theOptions
@@ -79,15 +80,15 @@ + (OnigRegexp*)compile:(NSString*)expression options:(OnigOption)theOptions
OnigErrorInfo err;
regex_t* entity = 0;
const UChar* str = (const UChar*)[expression cStringUsingEncoding:STRING_ENCODING];

int status = onig_new(&entity,
str,
str + [expression length] * CHAR_SIZE,
option,
ONIG_ENCODING,
ONIG_SYNTAX_DEFAULT,
&err);

str,
str + [expression length] * CHAR_SIZE,
option,
ONIG_ENCODING,
ONIG_SYNTAX_DEFAULT,
&err);
if (status == ONIG_NORMAL) {
return [[[self alloc] initWithEntity:entity expression:expression] autorelease];
}
@@ -116,13 +117,13 @@ - (OnigResult*)search:(NSString*)target start:(int)start end:(int)end
const UChar* str = (const UChar*)[target cStringUsingEncoding:STRING_ENCODING];

int status = onig_search(_entity,
str,
str + [target length] * CHAR_SIZE,
str + start * CHAR_SIZE,
str + end * CHAR_SIZE,
region,
ONIG_OPTION_NONE);

str,
str + [target length] * CHAR_SIZE,
str + start * CHAR_SIZE,
str + end * CHAR_SIZE,
region,
ONIG_OPTION_NONE);
if (status != ONIG_MISMATCH) {
return [[[OnigResult alloc] initWithRegexp:self region:region target:target] autorelease];
}
@@ -145,17 +146,17 @@ - (OnigResult*)match:(NSString*)target
- (OnigResult*)match:(NSString*)target start:(int)start
{
if (!target) return nil;

OnigRegion* region = onig_region_new();
const UChar* str = (const UChar*)[target cStringUsingEncoding:STRING_ENCODING];

int status = onig_match(_entity,
str,
str + [target length] * CHAR_SIZE,
str + start * CHAR_SIZE,
region,
ONIG_OPTION_NONE);

str,
str + [target length] * CHAR_SIZE,
str + start * CHAR_SIZE,
region,
ONIG_OPTION_NONE);
if (status != ONIG_MISMATCH) {
return [[[OnigResult alloc] initWithRegexp:self region:region target:target] autorelease];
}
@@ -187,7 +188,7 @@ - (id)initWithRegexp:(OnigRegexp*)expression region:(OnigRegion*)region target:(
_expression = [expression retain];
_region = region;
_target = [target copy];
_captureNames = [NSMutableArray array];
_captureNames = [NSMutableArray array];
}
return self;
}
@@ -202,8 +203,8 @@ - (void)dealloc

- (void)finalize
{
if (_region) onig_region_free(_region, 1);
[super finalize];
if (_region) onig_region_free(_region, 1);
[super finalize];
}

- (NSString*)target
@@ -272,21 +273,21 @@ - (NSString*)postMatch
}

- (NSMutableArray*) captureNameArray {
return self->_captureNames;
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;
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];
- (NSArray*)captureNames
{
onig_foreach_name([self->_expression entity], co_name_callback, self);
return [NSArray arrayWithArray:self->_captureNames];
}

- (int)indexForName:(NSString*)name
32 changes: 16 additions & 16 deletions framework/core/OnigRegexpUtility.m
Original file line number Diff line number Diff line change
@@ -7,20 +7,20 @@

NSString* stringReplaceCallback(OnigResult* res, void* str, SEL sel)
{
return (NSString*)str;
return (NSString*)str;
}

NSString* selectorReplaceCallback(OnigResult* res, void* str, SEL sel)
{
id object = str;
return [object performSelector:sel withObject:res];
id object = str;
return [object performSelector:sel withObject:res];
}

#if defined(NS_BLOCKS_AVAILABLE)
NSString* blockReplaceCallback(OnigResult* res, void* str, SEL sel)
{
NSString* (^block)(OnigResult*) = (NSString* (^)(OnigResult*))str;
return block(res);
NSString* (^block)(OnigResult*) = (NSString* (^)(OnigResult*))str;
return block(res);
}
#endif

@@ -71,7 +71,7 @@ - (NSArray*)__split:(id)pattern limit:(NSNumber*)limitNum
// If the pattern is a single space,
// split by contiguous white spaces,
// where leading and trailing white spaces are ignored.

NSRange r = [target rangeOfRegexp:@"^\\s+"];
if (r.location != NSNotFound) {
target = [target substringFromIndex:NSMaxRange(r)];
@@ -175,18 +175,18 @@ - (NSString*)__replaceByRegexp:(id)pattern withCallback:(ReplaceCallback)cp data

- (NSString*)replaceByRegexp:(id)pattern with:(NSString*)string
{
return [self __replaceByRegexp:pattern withCallback:stringReplaceCallback data:string selector:Nil];
return [self __replaceByRegexp:pattern withCallback:stringReplaceCallback data:string selector:Nil];
}

- (NSString*)replaceByRegexp:(id)pattern withCallback:(id)object selector:(SEL)sel
{
return [self __replaceByRegexp:pattern withCallback:selectorReplaceCallback data:object selector:sel];
return [self __replaceByRegexp:pattern withCallback:selectorReplaceCallback data:object selector:sel];
}

#if defined(NS_BLOCKS_AVAILABLE)
- (NSString*)replaceByRegexp:(id)pattern withBlock:(NSString* (^)(OnigResult*))block
{
return [self __replaceByRegexp:pattern withCallback:blockReplaceCallback data:block selector:Nil];
return [self __replaceByRegexp:pattern withCallback:blockReplaceCallback data:block selector:Nil];
}
#endif

@@ -199,7 +199,7 @@ - (NSString*)__replaceAllByRegexp:(id)pattern withCallback:(ReplaceCallback)cp d
if (![pattern isKindOfClass:[OnigRegexp class]]) {
pattern = [OnigRegexp compile:(NSString*)pattern];
}

OnigResult* res = [pattern search:self];
if (!res) {
return [[self mutableCopy] autorelease];
@@ -234,18 +234,18 @@ - (NSString*)__replaceAllByRegexp:(id)pattern withCallback:(ReplaceCallback)cp d

- (NSString*)replaceAllByRegexp:(id)pattern with:(NSString*)string
{
return [self __replaceAllByRegexp:pattern withCallback:stringReplaceCallback data:string selector:Nil];
return [self __replaceAllByRegexp:pattern withCallback:stringReplaceCallback data:string selector:Nil];
}

- (NSString*)replaceAllByRegexp:(id)pattern withCallback:(id)object selector:(SEL)sel
{
return [self __replaceAllByRegexp:pattern withCallback:selectorReplaceCallback data:object selector:sel];
return [self __replaceAllByRegexp:pattern withCallback:selectorReplaceCallback data:object selector:sel];
}

#if defined(NS_BLOCKS_AVAILABLE)
- (NSString*)replaceAllByRegexp:(id)pattern withBlock:(NSString* (^)(OnigResult*))block
{
return [self __replaceAllByRegexp:pattern withCallback:blockReplaceCallback data:block selector:Nil];
return [self __replaceAllByRegexp:pattern withCallback:blockReplaceCallback data:block selector:Nil];
}
#endif

@@ -271,18 +271,18 @@ - (NSMutableString*)replaceByRegexp:(id)pattern withCallback:(id)object selector

- (NSMutableString*)replaceAllByRegexp:(id)pattern withCallback:(id)object selector:(SEL)sel
{
return (NSMutableString*)[super replaceAllByRegexp:pattern withCallback:object selector:sel];
return (NSMutableString*)[super replaceAllByRegexp:pattern withCallback:object selector:sel];
}

#if defined(NS_BLOCKS_AVAILABLE)
- (NSMutableString*)replaceByRegexp:(id)pattern withBlock:(NSString* (^)(OnigResult*))block
{
return (NSMutableString*)[super replaceByRegexp:pattern withBlock:block];
return (NSMutableString*)[super replaceByRegexp:pattern withBlock:block];
}

- (NSMutableString*)replaceAllByRegexp:(id)pattern withBlock:(NSString* (^)(OnigResult*))block
{
return (NSMutableString*)[super replaceAllByRegexp:pattern withBlock:block];
return (NSMutableString*)[super replaceAllByRegexp:pattern withBlock:block];
}
#endif

0 comments on commit e394a1e

Please sign in to comment.