Skip to content

Commit

Permalink
Simplify by removng unnecessary argument in new callback
Browse files Browse the repository at this point in the history
  • Loading branch information
rfm committed Jan 4, 2025
1 parent 88720ad commit 2882d8c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 15 deletions.
4 changes: 2 additions & 2 deletions Headers/Foundation/NSRegularExpression.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ static const NSMatchingOptions NSMatchingWithoutAnchoringBounds = 1<<4;
#if GS_API_VERSION( 13100, GS_API_LATEST)
/** Enumeration with a C function callback uses this prototype
*/
typedef void (*GSRegexEnumerationCallback)(NSRegularExpression *regex,
typedef void (*GSRegexEnumerationCallback)(
void *context, NSTextCheckingResult *match,
NSMatchingFlags flags, BOOL *shouldStop);
#endif
Expand Down Expand Up @@ -135,7 +135,7 @@ GS_EXPORT_CLASS
* Its behavior is like that of the
* -enumerateMatchesInString:options:range:usingBlock: method, except that
* it uses a callback rather than a block, and the callback is supplied with
* both the NSRegularExpression instance being used and the context value.
* the context value specified as an argument to this method.
* <br />
* The operation of the method is basically to call the supplied callback
* function for each match of the expression in the string.
Expand Down
21 changes: 10 additions & 11 deletions Source/NSRegularExpression.m
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@
#import "Foundation/NSError.h"

typedef struct {
NSRegularExpression *e; // The RE being used
GSRegexEnumerationCallback h; // The handler callback function
void *c; // Context for this enumeration
} GSRegexContext;
Expand Down Expand Up @@ -119,7 +118,7 @@ @implementation NSRegularExpression
/* Callback method to invoke a block
*/
static void
blockCallback(NSRegularExpression *regex,
blockCallback(
void *context, NSTextCheckingResult *match,
NSMatchingFlags flags, BOOL *shouldStop)
{
Expand Down Expand Up @@ -401,7 +400,7 @@ - (NSUInteger) hash
{
return FALSE;
}
(*c->h)(c->e, c->c, nil, NSMatchingProgress, &stop);
(*c->h)(c->c, nil, NSMatchingProgress, &stop);

return (stop ? FALSE : TRUE);
}
Expand Down Expand Up @@ -594,7 +593,7 @@ - (void) enumerateMatchesInString: (NSString*)string
UErrorCode s = 0;
UText txt = UTEXT_INITIALIZER;
BOOL stop = NO;
GSRegexContext ctx = { self, handler, context };
GSRegexContext ctx = { handler, context };
URegularExpression *r = setupRegex(regex, string, &txt, opts, range, &ctx);
NSUInteger groups = [self numberOfCaptureGroups] + 1;
NSRange ranges[groups];
Expand All @@ -618,7 +617,7 @@ - (void) enumerateMatchesInString: (NSString*)string
regularExpressionCheckingResultWithRanges: ranges
count: groups
regularExpression: self];
(*handler)(self, context, result, flags, &stop);
(*handler)(context, result, flags, &stop);
}
}
else
Expand All @@ -634,12 +633,12 @@ - (void) enumerateMatchesInString: (NSString*)string
regularExpressionCheckingResultWithRanges: ranges
count: groups
regularExpression: self];
(*handler)(self, context, result, flags, &stop);
(*handler)(context, result, flags, &stop);
}
}
if (opts & NSMatchingCompleted)
{
(*handler)(self, context, nil, NSMatchingCompleted, &stop);
(*handler)(context, nil, NSMatchingCompleted, &stop);
}
utext_close(&txt);
uregex_close(r);
Expand All @@ -657,7 +656,7 @@ - (void) enumerateMatchesInString: (NSString*)string
URegularExpression *r;
NSUInteger groups = [self numberOfCaptureGroups] + 1;
NSRange ranges[groups];
GSRegexContext ctx = { self, handler, context };
GSRegexContext ctx = { handler, context };
TEMP_BUFFER(buffer, length);

r = setupRegex(regex, string, buffer, length, opts, range, &ctx);
Expand All @@ -681,7 +680,7 @@ - (void) enumerateMatchesInString: (NSString*)string
regularExpressionCheckingResultWithRanges: ranges
count: groups
regularExpression: self];
(*handler)(self, context, result, flags, &stop);
(*handler)(context, result, flags, &stop);
}
}
else
Expand All @@ -697,12 +696,12 @@ - (void) enumerateMatchesInString: (NSString*)string
regularExpressionCheckingResultWithRanges: ranges
count: groups
regularExpression: self];
(*handler)(self, context, result, flags, &stop);
(*handler)(context, result, flags, &stop);
}
}
if (opts & NSMatchingCompleted)
{
(*handler)(self, context, nil, NSMatchingCompleted, &stop);
(*handler)(context, nil, NSMatchingCompleted, &stop);
}
uregex_close(r);
}
Expand Down
4 changes: 2 additions & 2 deletions Tests/base/NSRegularExpression/callbacks.m
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#import <Foundation/Foundation.h>
#import "ObjectTesting.h"

static void callback(NSRegularExpression *re, void *context,
NSTextCheckingResult *match, NSMatchingFlags flags, BOOL *stop)
static void callback(void *context, NSTextCheckingResult *match,
NSMatchingFlags flags, BOOL *stop)
{
if (match)
{
Expand Down

0 comments on commit 2882d8c

Please sign in to comment.