mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-23 00:41:02 +00:00
Reformatting and compilation fixes.
This commit is contained in:
parent
1db5b071ee
commit
15ff083a9a
1 changed files with 74 additions and 61 deletions
|
@ -46,6 +46,8 @@
|
|||
|
||||
#define GSREGEXTYPE URegularExpression
|
||||
#import "GSICUString.h"
|
||||
#import "Foundation/NSDictionary.h"
|
||||
#import "Foundation/NSException.h"
|
||||
#import "Foundation/NSRegularExpression.h"
|
||||
#import "Foundation/NSTextCheckingResult.h"
|
||||
#import "Foundation/NSArray.h"
|
||||
|
@ -102,12 +104,15 @@ NSRegularExpressionOptionsToURegexpFlags(NSRegularExpressionOptions opts)
|
|||
@implementation NSRegularExpression
|
||||
|
||||
+ (NSRegularExpression*) regularExpressionWithPattern: (NSString*)aPattern
|
||||
options: (NSRegularExpressionOptions)opts
|
||||
error: (NSError**)e
|
||||
options: (NSRegularExpressionOptions)opts
|
||||
error: (NSError**)e
|
||||
{
|
||||
return [[[self alloc] initWithPattern: aPattern
|
||||
options: opts
|
||||
error: e] autorelease];
|
||||
NSRegularExpression *r;
|
||||
|
||||
r = [[self alloc] initWithPattern: aPattern
|
||||
options: opts
|
||||
error: e];
|
||||
return AUTORELEASE(r);
|
||||
}
|
||||
|
||||
|
||||
|
@ -116,20 +121,22 @@ NSRegularExpressionOptionsToURegexpFlags(NSRegularExpressionOptions opts)
|
|||
options: (NSRegularExpressionOptions)opts
|
||||
error: (NSError**)e
|
||||
{
|
||||
// Raise an NSInvalidArgumentException to match macOS behaviour.
|
||||
if (!aPattern) {
|
||||
NSException *exp;
|
||||
|
||||
exp = [NSException exceptionWithName: NSInvalidArgumentException
|
||||
reason: @"nil argument"];
|
||||
[exp raise];
|
||||
}
|
||||
|
||||
uint32_t flags = NSRegularExpressionOptionsToURegexpFlags(opts);
|
||||
UText p = UTEXT_INITIALIZER;
|
||||
UParseError pe = {0};
|
||||
UErrorCode s = 0;
|
||||
|
||||
// Raise an NSInvalidArgumentException to match macOS behaviour.
|
||||
if (!aPattern)
|
||||
{
|
||||
NSException *exp;
|
||||
|
||||
exp = [NSException exceptionWithName: NSInvalidArgumentException
|
||||
reason: @"nil argument"
|
||||
userInfo: nil];
|
||||
[exp raise];
|
||||
}
|
||||
|
||||
#if !__has_feature(blocks)
|
||||
if ([self class] != [NSRegularExpression class])
|
||||
{
|
||||
|
@ -142,29 +149,31 @@ NSRegularExpressionOptionsToURegexpFlags(NSRegularExpressionOptions opts)
|
|||
utext_close(&p);
|
||||
if (U_FAILURE(s))
|
||||
{
|
||||
// Match macOS behaviour if the pattern is invalid.
|
||||
// Example:
|
||||
// Domain=NSCocoaErrorDomain
|
||||
// Code=2048 "The value “<PATTERN>” is invalid."
|
||||
// UserInfo={NSInvalidValue=<PATTERN>}
|
||||
if (e) {
|
||||
NSDictionary *userInfo;
|
||||
NSString *description;
|
||||
/* Match macOS behaviour if the pattern is invalid.
|
||||
* Example:
|
||||
* Domain=NSCocoaErrorDomain
|
||||
* Code=2048 "The value “<PATTERN>” is invalid."
|
||||
* UserInfo={NSInvalidValue=<PATTERN>}
|
||||
*/
|
||||
if (e)
|
||||
{
|
||||
NSDictionary *userInfo;
|
||||
NSString *description;
|
||||
|
||||
description = [NSString stringWithFormat:
|
||||
@"The value “%@” is invalid.",
|
||||
aPattern];
|
||||
description = [NSString stringWithFormat: @"The value “%@” is invalid.", aPattern];
|
||||
|
||||
userInfo = [NSDictionary dictionaryWithObjectsAndKeys:
|
||||
aPattern, @"NSInvalidValue", description, NSLocalizedDescriptionKey, nil];
|
||||
userInfo = [NSDictionary dictionaryWithObjectsAndKeys:
|
||||
aPattern, @"NSInvalidValue",
|
||||
description, NSLocalizedDescriptionKey,
|
||||
nil];
|
||||
|
||||
*e = [NSError errorWithDomain: NSCocoaErrorDomain
|
||||
code: NSFormattingError
|
||||
userInfo: userInfo];
|
||||
}
|
||||
*e = [NSError errorWithDomain: NSCocoaErrorDomain
|
||||
code: NSFormattingError
|
||||
userInfo: userInfo];
|
||||
}
|
||||
|
||||
[self release];
|
||||
return nil;
|
||||
DESTROY(self);
|
||||
return self;
|
||||
}
|
||||
options = opts;
|
||||
return self;
|
||||
|
@ -218,7 +227,7 @@ NSRegularExpressionOptionsToURegexpFlags(NSRegularExpressionOptions opts)
|
|||
}
|
||||
str = [GSUTextString new];
|
||||
utext_clone(&str->txt, t, FALSE, TRUE, &s);
|
||||
return [str autorelease];
|
||||
return AUTORELEASE(str);
|
||||
}
|
||||
#else
|
||||
- (id) initWithPattern: (NSString*)aPattern
|
||||
|
@ -243,8 +252,8 @@ NSRegularExpressionOptionsToURegexpFlags(NSRegularExpressionOptions opts)
|
|||
if (U_FAILURE(s))
|
||||
{
|
||||
// FIXME: Do something sensible with the error parameter.
|
||||
[self release];
|
||||
return nil;
|
||||
DESTROY(self);
|
||||
return self;
|
||||
}
|
||||
options = opts;
|
||||
return self;
|
||||
|
@ -284,8 +293,7 @@ NSRegularExpressionOptionsToURegexpFlags(NSRegularExpressionOptions opts)
|
|||
{
|
||||
return NO;
|
||||
}
|
||||
return
|
||||
(0 == memcmp((const void*)myText, (const void*)theirText, myLen));
|
||||
return (0 == memcmp((const void*)myText, (const void*)theirText, myLen));
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -341,12 +349,14 @@ static int32_t _workLimit = DEFAULT_WORK_LIMIT;
|
|||
|
||||
+ (void) _defaultsChanged: (NSNotification*)n
|
||||
{
|
||||
NSUserDefaults *defs = [NSUserDefaults standardUserDefaults];
|
||||
id value = [defs objectForKey: @"GSRegularExpressionWorkLimit"];
|
||||
int32_t newLimit = DEFAULT_WORK_LIMIT;
|
||||
NSUserDefaults *defs = [NSUserDefaults standardUserDefaults];
|
||||
id value = [defs objectForKey: @"GSRegularExpressionWorkLimit"];
|
||||
int32_t newLimit = DEFAULT_WORK_LIMIT;
|
||||
|
||||
if ([value respondsToSelector: @selector(intValue)])
|
||||
{
|
||||
int32_t v = [value intValue];
|
||||
int32_t v = [value intValue];
|
||||
|
||||
if (v >= 0)
|
||||
{
|
||||
newLimit = v;
|
||||
|
@ -466,8 +476,10 @@ prepareResult(NSRegularExpression *regex,
|
|||
{
|
||||
NSInteger start = uregex_start(r, i, s);
|
||||
NSInteger end = uregex_end(r, i, s);
|
||||
// The ICU API defines -1 as not found. Convert to
|
||||
// NSNotFound if applicable.
|
||||
|
||||
/* The ICU API defines -1 as not found. Convert to
|
||||
* NSNotFound if applicable.
|
||||
*/
|
||||
if (start == -1)
|
||||
{
|
||||
start = NSNotFound;
|
||||
|
@ -505,12 +517,12 @@ prepareResult(NSRegularExpression *regex,
|
|||
range: (NSRange)range
|
||||
usingBlock: (GSRegexBlock)block
|
||||
{
|
||||
UErrorCode s = 0;
|
||||
UText txt = UTEXT_INITIALIZER;
|
||||
BOOL stop = NO;
|
||||
URegularExpression *r = setupRegex(regex, string, &txt, opts, range, block);
|
||||
NSUInteger groups = [self numberOfCaptureGroups] + 1;
|
||||
NSRange ranges[groups];
|
||||
UErrorCode s = 0;
|
||||
UText txt = UTEXT_INITIALIZER;
|
||||
BOOL stop = NO;
|
||||
URegularExpression *r = setupRegex(regex, string, &txt, opts, range, block);
|
||||
NSUInteger groups = [self numberOfCaptureGroups] + 1;
|
||||
NSRange ranges[groups];
|
||||
|
||||
// Should this throw some kind of exception?
|
||||
if (NULL == r)
|
||||
|
@ -563,12 +575,12 @@ prepareResult(NSRegularExpression *regex,
|
|||
range: (NSRange)range
|
||||
usingBlock: (GSRegexBlock)block
|
||||
{
|
||||
UErrorCode s = 0;
|
||||
BOOL stop = NO;
|
||||
int32_t length = [string length];
|
||||
URegularExpression *r;
|
||||
NSUInteger groups = [self numberOfCaptureGroups] + 1;
|
||||
NSRange ranges[groups];
|
||||
UErrorCode s = 0;
|
||||
BOOL stop = NO;
|
||||
int32_t length = [string length];
|
||||
URegularExpression *r;
|
||||
NSUInteger groups = [self numberOfCaptureGroups] + 1;
|
||||
NSRange ranges[groups];
|
||||
TEMP_BUFFER(buffer, length);
|
||||
|
||||
r = setupRegex(regex, string, buffer, length, opts, range, block);
|
||||
|
@ -718,10 +730,11 @@ prepareResult(NSRegularExpression *regex,
|
|||
# endif
|
||||
#if HAVE_UREGEX_OPENUTEXT
|
||||
#define FAKE_BLOCK_HACK(failRet, code) \
|
||||
UErrorCode s = 0;\
|
||||
UText txt = UTEXT_INITIALIZER;\
|
||||
BOOL stop = NO;\
|
||||
URegularExpression *r = setupRegex(regex, string, &txt, opts, range, 0);\
|
||||
UErrorCode s = 0;\
|
||||
UText txt = UTEXT_INITIALIZER;\
|
||||
BOOL stop = NO;\
|
||||
URegularExpression *r = setupRegex(regex, string, &txt, opts, range, 0);\
|
||||
\
|
||||
if (NULL == r) { return failRet; }\
|
||||
if (opts & NSMatchingAnchored)\
|
||||
{\
|
||||
|
@ -876,7 +889,7 @@ prepareResult(NSRegularExpression *regex,
|
|||
}
|
||||
utext_clone(&ret->txt, output, TRUE, TRUE, &s);
|
||||
[string setString: ret];
|
||||
[ret release];
|
||||
RELEASE(ret);
|
||||
uregex_close(r);
|
||||
|
||||
utext_close(&txt);
|
||||
|
|
Loading…
Reference in a new issue