get closer to coding standards

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@31743 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
rfm 2010-12-16 10:59:50 +00:00
parent ee053452a9
commit 09206b0e5b
3 changed files with 873 additions and 691 deletions

View file

@ -1,3 +1,8 @@
2010-12-16 Richard Frith-Macdonald <rfm@gnu.org>
* Source/NSRegularExpression.m: Move towards coding standards compliance
* Source/GSICUString.m: ditto
2010-12-16 Richard Frith-Macdonald <rfm@gnu.org>
* configure.ac: Remove redundant/incorrect define of HAVE_ICU.

View file

@ -1,3 +1,27 @@
/** Implementation of GSICUString for GNUStep
Copyright (C) 2010 Free Software Foundation, Inc.
This file is part of the GNUstep Base Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02111 USA.
$Date: 2010-09-18 16:09:58 +0100 (Sat, 18 Sep 2010) $ $Revision: 31371 $
*/
#import "common.h"
#if GS_USE_ICU == 1
#import "GSICUString.h"
@ -13,7 +37,8 @@ static const NSUInteger chunkSize = 32;
/**
* Returns the number of UTF16 characters in a UText backed by an NSString.
*/
static int64_t UTextNSStringNativeLength(UText *ut)
static int64_t
UTextNSStringNativeLength(UText *ut)
{
return [(NSString*)ut->p length];
}
@ -23,19 +48,27 @@ static int64_t UTextNSStringNativeLength(UText *ut)
* Loads a group of characters into the buffer that can be directly accessed by
* users of the UText. This is used for iteration but UText users.
*/
UBool UTextNSStringAccess(UText *ut, int64_t nativeIndex, UBool forward)
UBool
UTextNSStringAccess(UText *ut, int64_t nativeIndex, UBool forward)
{
NSString *str = ut->p;
NSString *str = (NSString*)ut->p;
NSUInteger length = [str length];
if (nativeIndex >= length) { return FALSE; }
// Special case if the chunk already contains this index
NSRange r;
if (nativeIndex >= length)
{
return FALSE;
}
/* Special case if the chunk already contains this index
*/
if (nativeIndex >= ut->chunkNativeStart
&& nativeIndex < (ut->chunkNativeStart + ut->chunkLength))
{
ut->chunkOffset = nativeIndex - ut->chunkNativeStart;
return TRUE;
}
NSRange r = {nativeIndex, chunkSize};
r = NSMakeRange(nativeIndex, chunkSize);
forward = TRUE;
if (forward)
{
@ -68,7 +101,8 @@ UBool UTextNSStringAccess(UText *ut, int64_t nativeIndex, UBool forward)
/**
* Replaces characters in an NSString-backed UText.
*/
static int32_t UTextNSMutableStringReplace(UText *ut,
static int32_t
UTextNSMutableStringReplace(UText *ut,
int64_t nativeStart,
int64_t nativeLimit,
const UChar *replacementText,
@ -78,6 +112,7 @@ static int32_t UTextNSMutableStringReplace(UText *ut,
NSMutableString *str = (NSMutableString*)ut->p;
NSRange r = NSMakeRange(nativeStart, nativeLimit-nativeStart);
NSString *replacement = [NSString alloc];
if (replacmentLength < 0)
{
replacement = [replacement initWithCString: (const char*)replacementText
@ -109,26 +144,32 @@ static int32_t UTextNSMutableStringReplace(UText *ut,
* Reads some characters. This is roughly analogous to NSString's
* -getCharacters:range:.
*/
static int32_t UTextNSStringExtract(UText *ut,
static int32_t
UTextNSStringExtract(UText *ut,
int64_t nativeStart,
int64_t nativeLimit,
UChar *dest,
int32_t destCapacity,
UErrorCode *status)
{
// If we're loading no characters, we are expected to return the number of
// characters that we could load if requested.
NSString *str;
NSUInteger length;
NSRange r;
/* If we're loading no characters, we are expected to return the number of
* characters that we could load if requested.
*/
if (destCapacity == 0)
{
return nativeLimit - nativeStart;
}
NSString *str = ut->p;
NSUInteger length = [str length];
str = (NSString*)ut->p;
length = [str length];
if (nativeLimit > length)
{
nativeLimit = length;
}
NSRange r = NSMakeRange(nativeStart, nativeLimit - nativeStart );
r = NSMakeRange(nativeStart, nativeLimit - nativeStart );
if (destCapacity < r.length)
{
r.length = destCapacity;
@ -151,14 +192,17 @@ void UTextNSStringCopy(UText *ut,
UBool move,
UErrorCode *status)
{
NSMutableString *str = ut->p;
NSMutableString *str = (NSMutableString*)ut->p;
NSUInteger length = [str length];
NSRange r;
NSString *substr;
if (nativeLimit > length)
{
nativeLimit = length;
}
NSRange r = NSMakeRange(nativeStart, nativeLimit - nativeStart);
NSString *substr = [str substringWithRange: r];
r = NSMakeRange(nativeStart, nativeLimit - nativeStart);
substr = [str substringWithRange: r];
[str insertString: substr atIndex: nativeDest];
if (move)
{
@ -168,7 +212,10 @@ void UTextNSStringCopy(UText *ut,
}
[str deleteCharactersInRange: r];
}
if (NULL != status) { *status = 0; }
if (NULL != status)
{
*status = 0;
}
}
@ -177,7 +224,8 @@ void UTextNSStringCopy(UText *ut,
* be allocated on the stack, or reused by different storage implementations,
* this does not destroy the UText itself.
*/
static void UTextNStringClose(UText *ut)
static void
UTextNStringClose(UText *ut)
{
ut->chunkContents = NULL;
[(NSString*)ut->p release];
@ -190,12 +238,14 @@ static void UTextNStringClose(UText *ut)
* Typically, this should not actually copy the underlying storage, because it
* is immutable.
*/
UText* UTextNSStringClone(UText *dest,
UText*
UTextNSStringClone(UText *dest,
const UText *src,
UBool deep,
UErrorCode *status)
{
NSString *str = src->p;
NSString *str = (NSString*)src->p;
if (deep)
{
str = [[str copy] autorelease];
@ -206,12 +256,14 @@ UText* UTextNSStringClone(UText *dest,
/**
* Copies the UText object, optionally copying the NSMutableString.
*/
UText* UTextNSMutableStringClone(UText *dest,
UText*
UTextNSMutableStringClone(UText *dest,
const UText *src,
UBool deep,
UErrorCode *status)
{
NSMutableString *str = src->p;
NSMutableString *str = (NSMutableString*)src->p;
if (deep)
{
str = [str mutableCopy];
@ -222,7 +274,8 @@ UText* UTextNSMutableStringClone(UText *dest,
/**
* Returns the index of the current character in the temporary buffer.
*/
int64_t UTextNSStringMapOffsetToNative(const UText *ut)
int64_t
UTextNSStringMapOffsetToNative(const UText *ut)
{
return ut->chunkNativeStart + ut->chunkOffset;
}
@ -265,12 +318,17 @@ static const UTextFuncs NSMutableStringFuncs =
0, 0, 0 // Spare
};
UText* UTextInitWithNSMutableString(UText *txt, NSMutableString *str)
UText*
UTextInitWithNSMutableString(UText *txt, NSMutableString *str)
{
UErrorCode status = 0;
txt = utext_setup(txt, chunkSize * sizeof(unichar), &status);
if (U_FAILURE(status)) { return NULL; }
if (U_FAILURE(status))
{
return NULL;
}
txt->p = [str retain];
txt->pFuncs = &NSMutableStringFuncs;
@ -282,12 +340,16 @@ UText* UTextInitWithNSMutableString(UText *txt, NSMutableString *str)
return txt;
}
UText* UTextInitWithNSString(UText *txt, NSString *str)
UText*
UTextInitWithNSString(UText *txt, NSString *str)
{
UErrorCode status = 0;
txt = utext_setup(txt, 64, &status);
if (U_FAILURE(status)) { return NULL; }
if (U_FAILURE(status))
{
return NULL;
}
txt->p = [str retain];
txt->pFuncs = &NSStringFuncs;
@ -298,26 +360,34 @@ UText* UTextInitWithNSString(UText *txt, NSString *str)
}
@implementation GSUTextString
- init
- (id) init
{
if (nil == (self = [super init])) { return nil; }
if (nil != (self = [super init]))
{
UText t = UTEXT_INITIALIZER;
memcpy(&txt, &t, sizeof(t));
}
return self;
}
- (NSUInteger)length
- (NSUInteger) length
{
return utext_nativeLength(&txt);
}
- (unichar)characterAtIndex: (NSUInteger)idx
- (unichar) characterAtIndex: (NSUInteger)idx
{
unichar c;
[self getCharacters: &c range: NSMakeRange(idx, 1)];
return c;
}
- (void)getCharacters: (unichar*)buffer range: (NSRange)r
- (void) getCharacters: (unichar*)buffer range: (NSRange)r
{
UErrorCode status = 0;
utext_extract(&txt, r.location, r.location+r.length, buffer, r.length,
&status);
if (U_FAILURE(status))
@ -325,7 +395,8 @@ UText* UTextInitWithNSString(UText *txt, NSString *str)
_NSRangeExceptionRaise();
}
}
- (void)dealloc
- (void) dealloc
{
utext_close(&txt);
[super dealloc];
@ -333,26 +404,33 @@ UText* UTextInitWithNSString(UText *txt, NSString *str)
@end
@implementation GSUTextMutableString
- init
- (id) init
{
if (nil == (self = [super init])) { return nil; }
if (nil != (self = [super init]))
{
UText t = UTEXT_INITIALIZER;
memcpy(&txt, &t, sizeof(t));
}
return self;
}
- (NSUInteger)length
- (NSUInteger) length
{
return utext_nativeLength(&txt);
}
- (unichar)characterAtIndex: (NSUInteger)idx
- (unichar) characterAtIndex: (NSUInteger)idx
{
unichar c;
[self getCharacters: &c range: NSMakeRange(idx, 1)];
return c;
}
- (void)getCharacters: (unichar*)buffer range: (NSRange)r
- (void) getCharacters: (unichar*)buffer range: (NSRange)r
{
UErrorCode status = 0;
utext_extract(&txt, r.location, r.location+r.length, buffer, r.length,
&status);
if (U_FAILURE(status))
@ -360,19 +438,20 @@ UText* UTextInitWithNSString(UText *txt, NSString *str)
_NSRangeExceptionRaise();
}
}
- (void)replaceCharactersInRange: (NSRange)r
- (void) replaceCharactersInRange: (NSRange)r
withString: (NSString*)aString
{
NSUInteger size = [aString length];
UErrorCode status = 0;
TEMP_BUFFER(buffer, size);
[aString getCharacters: buffer range: NSMakeRange(0, size)];
utext_replace(&txt, r.location, r.location + r.length, buffer, size,
&status);
utext_replace(&txt, r.location, r.location + r.length, buffer, size, &status);
}
- (void)dealloc
- (void) dealloc
{
utext_close(&txt);
[super dealloc];

View file

@ -1,4 +1,29 @@
#include "common.h"
/** Implementation of NSRegualrExpression for GNUStep
Copyright (C) 2010 Free Software Foundation, Inc.
This file is part of the GNUstep Base Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02111 USA.
$Date: 2010-09-18 16:09:58 +0100 (Sat, 18 Sep 2010) $ $Revision: 31371 $
*/
#import "common.h"
#if GS_USE_ICU == 1
#include "unicode/uregex.h"
#if (U_ICU_VERSION_MAJOR_NUM > 4 || (U_ICU_VERSION_MAJOR_NUM == 4 && U_ICU_VERSION_MINOR_NUM >= 4))
@ -18,9 +43,11 @@
* in theory use the libicu values directly (that would be sensible), but that
* would break any code that didn't correctly use the symbolic constants.
*/
uint32_t NSRegularExpressionOptionsToURegexpFlags(NSRegularExpressionOptions opts)
uint32_t
NSRegularExpressionOptionsToURegexpFlags(NSRegularExpressionOptions opts)
{
uint32_t flags = 0;
if (opts & NSRegularExpressionCaseInsensitive)
{
flags |= UREGEX_CASE_INSENSITIVE;
@ -53,13 +80,17 @@ uint32_t NSRegularExpressionOptionsToURegexpFlags(NSRegularExpressionOptions opt
}
@implementation NSRegularExpression
+ (NSRegularExpression*)regularExpressionWithPattern: (NSString*)aPattern
+ (NSRegularExpression*) regularExpressionWithPattern: (NSString*)aPattern
options: (NSRegularExpressionOptions)opts
error: (NSError**)e
{
return [[[self alloc] initWithPattern: aPattern options: opts error: e] autorelease];
return [[[self alloc] initWithPattern: aPattern
options: opts
error: e] autorelease];
}
- initWithPattern: (NSString*)aPattern
- (id) initWithPattern: (NSString*)aPattern
options: (NSRegularExpressionOptions)opts
error: (NSError**)e
{
@ -67,6 +98,7 @@ uint32_t NSRegularExpressionOptionsToURegexpFlags(NSRegularExpressionOptions opt
UText p = UTEXT_INITIALIZER;
UParseError pe = {0};
UErrorCode s = 0;
UTextInitWithNSString(&p, aPattern);
regex = uregex_openUText(&p, flags, &pe, &s);
utext_close(&p);
@ -79,11 +111,13 @@ uint32_t NSRegularExpressionOptionsToURegexpFlags(NSRegularExpressionOptions opt
options = opts;
return self;
}
- (NSString*)pattern
- (NSString*) pattern
{
UErrorCode s = 0;
UText *t = uregex_patternUText(regex, &s);
GSUTextString *str = NULL;
if (U_FAILURE(s))
{
return nil;
@ -94,14 +128,20 @@ uint32_t NSRegularExpressionOptionsToURegexpFlags(NSRegularExpressionOptions opt
return [str autorelease];
}
static UBool callback(const void *context, int32_t steps)
static UBool
callback(const void *context, int32_t steps)
{
BOOL stop = NO;
GSRegexBlock block = (GSRegexBlock)context;
if (NULL == context) { return FALSE; }
if (NULL == context)
{
return FALSE;
}
CALL_BLOCK(block, nil, NSMatchingProgress, &stop);
return stop;
}
/**
* Sets up a libicu regex object for use. Note: the documentation states that
* NSRegularExpression must be thread safe. To accomplish this, we store a
@ -110,7 +150,8 @@ static UBool callback(const void *context, int32_t steps)
* NSRegularExpression, is stateful, and sharing this state between threads
* would break concurrent calls.
*/
static URegularExpression *setupRegex(URegularExpression *regex,
static URegularExpression *
setupRegex(URegularExpression *regex,
NSString *string,
UText *txt,
NSMatchingOptions options,
@ -119,6 +160,7 @@ static URegularExpression *setupRegex(URegularExpression *regex,
{
UErrorCode s = 0;
URegularExpression *r = uregex_clone(regex, &s);
if (options & NSMatchingReportProgress)
{
uregex_setMatchCallback(r, callback, block, &s);
@ -141,7 +183,9 @@ static URegularExpression *setupRegex(URegularExpression *regex,
}
return r;
}
static uint32_t prepareResult(NSRegularExpression *regex,
static uint32_t
prepareResult(NSRegularExpression *regex,
URegularExpression *r,
NSRangePointer ranges,
NSUInteger groups,
@ -149,10 +193,12 @@ static uint32_t prepareResult(NSRegularExpression *regex,
{
uint32_t flags = 0;
NSUInteger i = 0;
for (i = 0 ; i<groups ; i++)
for (i = 0; i < groups; i++)
{
NSUInteger start = uregex_start(r, i, s);
NSUInteger end = uregex_end(r, i, s);
ranges[i] = NSMakeRange(start, end-start);
}
if (uregex_hitEnd(r, s))
@ -170,7 +216,7 @@ static uint32_t prepareResult(NSRegularExpression *regex,
return flags;
}
- (void)enumerateMatchesInString: (NSString*)string
- (void) enumerateMatchesInString: (NSString*)string
options: (NSMatchingOptions)opts
range: (NSRange)range
usingBlock: (GSRegexBlock)block
@ -181,16 +227,23 @@ static uint32_t prepareResult(NSRegularExpression *regex,
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) { return; }
if (NULL == r)
{
return;
}
if (opts & NSMatchingAnchored)
{
if (uregex_lookingAt(r, -1, &s) && (0==s))
if (uregex_lookingAt(r, -1, &s) && (0 == s))
{
// FIXME: Factor all of this out into prepareResult()
uint32_t flags = prepareResult(self, r, ranges, groups, &s);
NSTextCheckingResult *result =
[NSTextCheckingResult regularExpressionCheckingResultWithRanges: ranges
uint32_t flags;
NSTextCheckingResult *result;
flags = prepareResult(self, r, ranges, groups, &s);
result = [NSTextCheckingResult
regularExpressionCheckingResultWithRanges: ranges
count: groups
regularExpression: self];
CALL_BLOCK(block, result, flags, &stop);
@ -198,11 +251,14 @@ static uint32_t prepareResult(NSRegularExpression *regex,
}
else
{
while (!stop && uregex_findNext(r, &s) && (s == 0))
while (!stop && uregex_findNext(r, &s) && (0 == s))
{
uint32_t flags = prepareResult(self, r, ranges, groups, &s);
NSTextCheckingResult *result =
[NSTextCheckingResult regularExpressionCheckingResultWithRanges: ranges
uint32_t flags;
NSTextCheckingResult *result;
flags = prepareResult(self, r, ranges, groups, &s);
result = [NSTextCheckingResult
regularExpressionCheckingResultWithRanges: ranges
count: groups
regularExpression: self];
CALL_BLOCK(block, result, flags, &stop);
@ -215,18 +271,22 @@ static uint32_t prepareResult(NSRegularExpression *regex,
utext_close(&txt);
uregex_close(r);
}
// The remaining methods are all meant to be wrappers around the primitive
// method that takes a block argument. Unfortunately, this is not really
// possible when compiling with a compiler that doesn't support blocks.
/* The remaining methods are all meant to be wrappers around the primitive
* method that takes a block argument. Unfortunately, this is not really
* possible when compiling with a compiler that doesn't support blocks.
*/
#if __has_feature(blocks)
- (NSUInteger)numberOfMatchesInString: (NSString*)string
- (NSUInteger) numberOfMatchesInString: (NSString*)string
options: (NSMatchingOptions)opts
range: (NSRange)range
{
__block NSUInteger count = 0;
opts &= ~NSMatchingReportProgress;
opts &= ~NSMatchingReportCompletion;
GSRegexBlock block =
^(NSTextCheckingResult *result, NSMatchingFlags flags, BOOL *stop)
{
@ -238,13 +298,16 @@ static uint32_t prepareResult(NSRegularExpression *regex,
usingBlock: block];
return count;
}
- (NSTextCheckingResult*)firstMatchInString: (NSString*)string
- (NSTextCheckingResult*) firstMatchInString: (NSString*)string
options: (NSMatchingOptions)opts
range: (NSRange)range
{
__block NSTextCheckingResult *r = nil;
opts &= ~NSMatchingReportProgress;
opts &= ~NSMatchingReportCompletion;
GSRegexBlock block =
^(NSTextCheckingResult *result, NSMatchingFlags flags, BOOL *stop)
{
@ -257,13 +320,16 @@ static uint32_t prepareResult(NSRegularExpression *regex,
usingBlock: block];
return r;
}
- (NSArray*)matchesInString: (NSString*)string
- (NSArray*) matchesInString: (NSString*)string
options:(NSMatchingOptions)opts
range:(NSRange)range
{
NSMutableArray *array = [NSMutableArray array];
opts &= ~NSMatchingReportProgress;
opts &= ~NSMatchingReportCompletion;
GSRegexBlock block =
^(NSTextCheckingResult *result, NSMatchingFlags flags, BOOL *stop)
{
@ -275,17 +341,20 @@ static uint32_t prepareResult(NSRegularExpression *regex,
usingBlock: block];
return array;
}
- (NSRange)rangeOfFirstMatchInString: (NSString*)string
- (NSRange) rangeOfFirstMatchInString: (NSString*)string
options: (NSMatchingOptions)opts
range: (NSRange)range
{
__block NSRange r;
opts &= ~NSMatchingReportProgress;
opts &= ~NSMatchingReportCompletion;
GSRegexBlock block =
^(NSTextCheckingResult *result, NSMatchingFlags flags, BOOL *stop)
{
r= [result range];
r = [result range];
*stop = YES;
};
[self enumerateMatchesInString: string
@ -294,6 +363,7 @@ static uint32_t prepareResult(NSRegularExpression *regex,
usingBlock: block];
return r;
}
#else
# warning Your compiler does not support blocks. NSRegularExpression will deviate from the documented behaviour when subclassing and any code that subclasses NSRegularExpression may break in unexpected ways. It is strongly recommended that you use a compiler with blocks support.
# ifdef __clang__
@ -321,60 +391,69 @@ static uint32_t prepareResult(NSRegularExpression *regex,
}\
utext_close(&txt);\
uregex_close(r);
- (NSUInteger)numberOfMatchesInString: (NSString*)string
- (NSUInteger) numberOfMatchesInString: (NSString*)string
options: (NSMatchingOptions)opts
range: (NSRange)range
{
NSUInteger count = 0;
FAKE_BLOCK_HACK(count,
{
count++;
});
return count;
}
- (NSTextCheckingResult*)firstMatchInString: (NSString*)string
- (NSTextCheckingResult*) firstMatchInString: (NSString*)string
options: (NSMatchingOptions)opts
range: (NSRange)range
{
NSTextCheckingResult *result = nil;
NSUInteger groups = [self numberOfCaptureGroups] + 1;
NSRange ranges[groups];
FAKE_BLOCK_HACK(result,
{
prepareResult(self, r, ranges, groups, &s);
result =
[NSTextCheckingResult regularExpressionCheckingResultWithRanges: ranges
result = [NSTextCheckingResult
regularExpressionCheckingResultWithRanges: ranges
count: groups
regularExpression: self];
stop = YES;
});
return result;
}
- (NSArray*)matchesInString: (NSString*)string
options:(NSMatchingOptions)opts
range:(NSRange)range
- (NSArray*) matchesInString: (NSString*)string
options: (NSMatchingOptions)opts
range: (NSRange)range
{
NSMutableArray *array = [NSMutableArray array];
NSUInteger groups = [self numberOfCaptureGroups] + 1;
NSRange ranges[groups];
FAKE_BLOCK_HACK(array,
{
NSTextCheckingResult *result = NULL;
prepareResult(self, r, ranges, groups, &s);
result =
[NSTextCheckingResult regularExpressionCheckingResultWithRanges: ranges
result = [NSTextCheckingResult
regularExpressionCheckingResultWithRanges: ranges
count: groups
regularExpression: self];
[array addObject: result];
});
return array;
}
- (NSRange)rangeOfFirstMatchInString: (NSString*)string
- (NSRange) rangeOfFirstMatchInString: (NSString*)string
options: (NSMatchingOptions)opts
range: (NSRange)range
{
NSRange result = {0,0};
FAKE_BLOCK_HACK(result,
{
prepareResult(self, r, &result, 1, &s);
@ -382,8 +461,10 @@ static uint32_t prepareResult(NSRegularExpression *regex,
});
return result;
}
#endif
- (NSUInteger)replaceMatchesInString: (NSMutableString*)string
- (NSUInteger) replaceMatchesInString: (NSMutableString*)string
options: (NSMatchingOptions)opts
range: (NSRange)range
withTemplate: (NSString*)template
@ -399,6 +480,7 @@ static uint32_t prepareResult(NSRegularExpression *regex,
GSUTextString *ret = [GSUTextString new];
URegularExpression *r = setupRegex(regex, string, &txt, opts, range, 0);
UText *output = NULL;
UTextInitWithNSString(&replacement, template);
output = uregex_replaceAllUText(r, &replacement, NULL, &s);
@ -413,7 +495,7 @@ static uint32_t prepareResult(NSRegularExpression *regex,
return results;
}
- (NSString*)stringByReplacingMatchesInString: (NSString*)string
- (NSString*) stringByReplacingMatchesInString: (NSString*)string
options: (NSMatchingOptions)opts
range: (NSRange)range
withTemplate: (NSString*)template
@ -424,8 +506,8 @@ static uint32_t prepareResult(NSRegularExpression *regex,
UText *output = NULL;
GSUTextString *ret = [GSUTextString new];
URegularExpression *r = setupRegex(regex, string, &txt, opts, range, 0);
UTextInitWithNSString(&replacement, template);
UTextInitWithNSString(&replacement, template);
output = uregex_replaceAllUText(r, &replacement, NULL, &s);
utext_clone(&ret->txt, output, TRUE, TRUE, &s);
@ -437,7 +519,7 @@ static uint32_t prepareResult(NSRegularExpression *regex,
return ret;
}
- (NSString*)replacementStringForResult: (NSTextCheckingResult*)result
- (NSString*) replacementStringForResult: (NSTextCheckingResult*)result
inString: (NSString*)string
offset: (NSInteger)offset
template: (NSString*)template
@ -454,8 +536,8 @@ static uint32_t prepareResult(NSRegularExpression *regex,
0,
NSMakeRange(0, range.length),
0);
UTextInitWithNSString(&replacement, template);
UTextInitWithNSString(&replacement, template);
output = uregex_replaceFirstUText(r, &replacement, NULL, &s);
utext_clone(&ret->txt, output, TRUE, TRUE, &s);
@ -466,21 +548,25 @@ static uint32_t prepareResult(NSRegularExpression *regex,
utext_close(&replacement);
return ret;
}
- (NSRegularExpressionOptions)options
- (NSRegularExpressionOptions) options
{
return options;
}
- (NSUInteger)numberOfCaptureGroups
- (NSUInteger) numberOfCaptureGroups
{
UErrorCode s = 0;
return uregex_groupCount(regex, &s);
}
- (void)dealloc
- (void) dealloc
{
uregex_close(regex);
[super dealloc];
}
- (void)encodeWithCoder: (NSCoder*)aCoder
- (void) encodeWithCoder: (NSCoder*)aCoder
{
if ([aCoder allowsKeyedCoding])
{
@ -489,13 +575,16 @@ static uint32_t prepareResult(NSRegularExpression *regex,
}
else
{
[aCoder encodeValueOfObjCType: @encode(NSRegularExpressionOptions) at: &options];
[aCoder encodeValueOfObjCType: @encode(NSRegularExpressionOptions)
at: &options];
[aCoder encodeObject: [self pattern]];
}
}
- initWithCoder: (NSCoder*)aCoder
- (id) initWithCoder: (NSCoder*)aCoder
{
NSString *pattern;
if ([aCoder allowsKeyedCoding])
{
options = [aCoder decodeIntegerForKey: @"options"];
@ -503,20 +592,29 @@ static uint32_t prepareResult(NSRegularExpression *regex,
}
else
{
[aCoder decodeValueOfObjCType: @encode(NSRegularExpressionOptions) at: &options];
[aCoder decodeValueOfObjCType: @encode(NSRegularExpressionOptions)
at: &options];
pattern = [aCoder decodeObject];
}
return [self initWithPattern: pattern options: options error: NULL];
}
- copyWithZone: (NSZone*)aZone
- (id) copyWithZone: (NSZone*)aZone
{
NSRegularExpressionOptions opts = options;
UErrorCode s = 0;
URegularExpression *r = uregex_clone(regex, &s);
if (0 != s) { return nil; }
if (0 != s)
{
return nil;
}
self = [[self class] allocWithZone: aZone];
if (nil == self) { return nil; }
if (nil == self)
{
return nil;
}
options = opts;
regex = r;
return self;