Permalink
Browse files

Added enum for options and created a new compile method that takes op…

…tions
  • Loading branch information...
1 parent 96db4d9 commit 4633f7815c2ddcc5095809a10e10bf8647afa137 @griff griff committed Jan 17, 2011
Showing with 29 additions and 4 deletions.
  1. +19 −0 framework/core/OnigRegexp.h
  2. +10 −4 framework/core/OnigRegexp.m
View
19 framework/core/OnigRegexp.h
@@ -8,6 +8,24 @@
@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
+} OnigOption;
@interface OnigRegexp : NSObject
{
@@ -19,6 +37,7 @@
+ (OnigRegexp*)compileIgnorecase:(NSString*)expression;
+ (OnigRegexp*)compile:(NSString*)expression ignorecase:(BOOL)ignorecase multiline:(BOOL)multiline;
+ (OnigRegexp*)compile:(NSString*)expression ignorecase:(BOOL)ignorecase multiline:(BOOL)multiline extended:(BOOL)extended;
++ (OnigRegexp*)compile:(NSString*)expression withOptions:(OnigOption)options;
- (OnigResult*)search:(NSString*)target;
- (OnigResult*)search:(NSString*)target start:(int)start;
View
14 framework/core/OnigRegexp.m
@@ -55,12 +55,18 @@ + (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 withOptions:options];
+}
+
++ (OnigRegexp*)compile:(NSString*)expression withOptions:(OnigOption)aOptions
+{
if (!expression) return nil;
- OnigOptionType option = ONIG_OPTION_NONE;
- option |= multiline ? ONIG_OPTION_MULTILINE : ONIG_OPTION_SINGLELINE;
- if (ignorecase) option |= ONIG_OPTION_IGNORECASE;
- if (extended) option |= ONIG_OPTION_EXTEND;
+ OnigOptionType option = aOptions;
OnigErrorInfo err;
regex_t* entity = 0;

0 comments on commit 4633f78

Please sign in to comment.