mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-30 08:21:25 +00:00
Remove some of the compiler warnings on system without clang or ICU.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@33680 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
999a0cb544
commit
dafc3301e5
4 changed files with 84 additions and 53 deletions
|
@ -27,17 +27,19 @@
|
|||
#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))
|
||||
|
||||
#define NSRegularExpressionWorks
|
||||
|
||||
#define GSREGEXTYPE URegularExpression
|
||||
#import "GSICUString.h"
|
||||
#import "Foundation/NSRegularExpression.h"
|
||||
#import "Foundation/NSTextCheckingResult.h"
|
||||
#endif //U_ICU_VERSION_MAJOR_NUM > 4 || (U_ICU_VERSION_MAJOR_NUM == 4 && U_ICU_VERSION_MINOR_NUM >= 4))
|
||||
#endif //HAV_ICU
|
||||
|
||||
#import "Foundation/NSArray.h"
|
||||
#import "Foundation/NSCoder.h"
|
||||
#import "Foundation/NSException.h"
|
||||
#import "Foundation/NSRegularExpression.h"
|
||||
#import "Foundation/NSTextCheckingResult.h"
|
||||
|
||||
|
||||
#ifdef NSRegularExpressionWorks
|
||||
/**
|
||||
* To be helpful, Apple decided to define a set of flags that mean exactly the
|
||||
* same thing as the URegexpFlags enum in libicu, but have different values.
|
||||
|
@ -80,6 +82,7 @@ NSRegularExpressionOptionsToURegexpFlags(NSRegularExpressionOptions opts)
|
|||
}
|
||||
return flags;
|
||||
}
|
||||
#endif
|
||||
|
||||
@implementation NSRegularExpression
|
||||
|
||||
|
@ -96,6 +99,7 @@ NSRegularExpressionOptionsToURegexpFlags(NSRegularExpressionOptions opts)
|
|||
options: (NSRegularExpressionOptions)opts
|
||||
error: (NSError**)e
|
||||
{
|
||||
#ifdef NSRegularExpressionWorks
|
||||
uint32_t flags = NSRegularExpressionOptionsToURegexpFlags(opts);
|
||||
UText p = UTEXT_INITIALIZER;
|
||||
UParseError pe = {0};
|
||||
|
@ -110,26 +114,18 @@ NSRegularExpressionOptionsToURegexpFlags(NSRegularExpressionOptions opts)
|
|||
[self release];
|
||||
return nil;
|
||||
}
|
||||
#endif
|
||||
ASSIGN(pattern, aPattern);
|
||||
options = opts;
|
||||
return self;
|
||||
}
|
||||
|
||||
- (NSString*) pattern
|
||||
{
|
||||
UErrorCode s = 0;
|
||||
UText *t = uregex_patternUText(regex, &s);
|
||||
GSUTextString *str = NULL;
|
||||
|
||||
if (U_FAILURE(s))
|
||||
{
|
||||
return nil;
|
||||
}
|
||||
str = [GSUTextString new];
|
||||
utext_clone(&str->txt, t, FALSE, TRUE, &s);
|
||||
utext_close(t);
|
||||
return [str autorelease];
|
||||
return pattern;
|
||||
}
|
||||
|
||||
#ifdef NSRegularExpressionWorks
|
||||
static UBool
|
||||
callback(const void *context, int32_t steps)
|
||||
{
|
||||
|
@ -217,12 +213,14 @@ prepareResult(NSRegularExpression *regex,
|
|||
}
|
||||
return flags;
|
||||
}
|
||||
#endif
|
||||
|
||||
- (void) enumerateMatchesInString: (NSString*)string
|
||||
options: (NSMatchingOptions)opts
|
||||
range: (NSRange)range
|
||||
usingBlock: (GSRegexBlock)block
|
||||
{
|
||||
#ifdef NSRegularExpressionWorks
|
||||
UErrorCode s = 0;
|
||||
UText txt = UTEXT_INITIALIZER;
|
||||
BOOL stop = NO;
|
||||
|
@ -272,6 +270,11 @@ prepareResult(NSRegularExpression *regex,
|
|||
}
|
||||
utext_close(&txt);
|
||||
uregex_close(r);
|
||||
#else
|
||||
//FIXME
|
||||
[NSException raise: NSInvalidArgumentException
|
||||
format: @"NSRegularExpression requires ICU 4.4 or later"];
|
||||
#endif
|
||||
}
|
||||
|
||||
/* The remaining methods are all meant to be wrappers around the primitive
|
||||
|
@ -371,6 +374,8 @@ prepareResult(NSRegularExpression *regex,
|
|||
# ifdef __clang__
|
||||
# warning Your compiler would support blocks if you added -fblocks to your OBJCFLAGS
|
||||
# endif
|
||||
|
||||
#ifdef NSRegularExpressionWorks
|
||||
#define FAKE_BLOCK_HACK(failRet, code) \
|
||||
UErrorCode s = 0;\
|
||||
UText txt = UTEXT_INITIALIZER;\
|
||||
|
@ -393,6 +398,11 @@ prepareResult(NSRegularExpression *regex,
|
|||
}\
|
||||
utext_close(&txt);\
|
||||
uregex_close(r);
|
||||
#else
|
||||
#define FAKE_BLOCK_HACK(failRet, code) \
|
||||
[NSException raise: NSInvalidArgumentException \
|
||||
format: @"NSRegularExpression requires ICU 4.4 or later"]
|
||||
#endif
|
||||
|
||||
- (NSUInteger) numberOfMatchesInString: (NSString*)string
|
||||
options: (NSMatchingOptions)opts
|
||||
|
@ -476,6 +486,7 @@ prepareResult(NSRegularExpression *regex,
|
|||
NSInteger results = [self numberOfMatchesInString: string
|
||||
options: opts
|
||||
range: range];
|
||||
#ifdef NSRegularExpressionWorks
|
||||
UErrorCode s = 0;
|
||||
UText txt = UTEXT_INITIALIZER;
|
||||
UText replacement = UTEXT_INITIALIZER;
|
||||
|
@ -494,6 +505,7 @@ prepareResult(NSRegularExpression *regex,
|
|||
utext_close(&txt);
|
||||
utext_close(output);
|
||||
utext_close(&replacement);
|
||||
#endif
|
||||
return results;
|
||||
}
|
||||
|
||||
|
@ -502,6 +514,7 @@ prepareResult(NSRegularExpression *regex,
|
|||
range: (NSRange)range
|
||||
withTemplate: (NSString*)template
|
||||
{
|
||||
#ifdef NSRegularExpressionWorks
|
||||
UErrorCode s = 0;
|
||||
UText txt = UTEXT_INITIALIZER;
|
||||
UText replacement = UTEXT_INITIALIZER;
|
||||
|
@ -519,6 +532,10 @@ prepareResult(NSRegularExpression *regex,
|
|||
utext_close(output);
|
||||
utext_close(&replacement);
|
||||
return ret;
|
||||
#else
|
||||
// FIXME
|
||||
return nil;
|
||||
#endif
|
||||
}
|
||||
|
||||
- (NSString*) replacementStringForResult: (NSTextCheckingResult*)result
|
||||
|
@ -526,6 +543,7 @@ prepareResult(NSRegularExpression *regex,
|
|||
offset: (NSInteger)offset
|
||||
template: (NSString*)template
|
||||
{
|
||||
#ifdef NSRegularExpressionWorks
|
||||
UErrorCode s = 0;
|
||||
UText txt = UTEXT_INITIALIZER;
|
||||
UText replacement = UTEXT_INITIALIZER;
|
||||
|
@ -549,6 +567,10 @@ prepareResult(NSRegularExpression *regex,
|
|||
utext_close(output);
|
||||
utext_close(&replacement);
|
||||
return ret;
|
||||
#else
|
||||
//FIXME
|
||||
return nil;
|
||||
#endif
|
||||
}
|
||||
|
||||
- (NSRegularExpressionOptions) options
|
||||
|
@ -558,13 +580,21 @@ prepareResult(NSRegularExpression *regex,
|
|||
|
||||
- (NSUInteger) numberOfCaptureGroups
|
||||
{
|
||||
#ifdef NSRegularExpressionWorks
|
||||
UErrorCode s = 0;
|
||||
return uregex_groupCount(regex, &s);
|
||||
#else
|
||||
// FIXME
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
- (void) dealloc
|
||||
{
|
||||
#ifdef NSRegularExpressionWorks
|
||||
uregex_close(regex);
|
||||
#endif
|
||||
RELEASE(pattern);
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
|
@ -585,24 +615,26 @@ prepareResult(NSRegularExpression *regex,
|
|||
|
||||
- (id) initWithCoder: (NSCoder*)aCoder
|
||||
{
|
||||
NSString *pattern;
|
||||
NSString *aPattern;
|
||||
NSRegularExpressionOptions opts;
|
||||
|
||||
if ([aCoder allowsKeyedCoding])
|
||||
{
|
||||
options = [aCoder decodeIntegerForKey: @"options"];
|
||||
pattern = [aCoder decodeObjectForKey: @"pattern"];
|
||||
opts = [aCoder decodeIntegerForKey: @"options"];
|
||||
aPattern = [aCoder decodeObjectForKey: @"pattern"];
|
||||
}
|
||||
else
|
||||
{
|
||||
[aCoder decodeValueOfObjCType: @encode(NSRegularExpressionOptions)
|
||||
at: &options];
|
||||
pattern = [aCoder decodeObject];
|
||||
at: &opts];
|
||||
aPattern = [aCoder decodeObject];
|
||||
}
|
||||
return [self initWithPattern: pattern options: options error: NULL];
|
||||
return [self initWithPattern: aPattern options: opts error: NULL];
|
||||
}
|
||||
|
||||
- (id) copyWithZone: (NSZone*)aZone
|
||||
{
|
||||
#ifdef NSRegularExpressionWorks
|
||||
NSRegularExpressionOptions opts = options;
|
||||
UErrorCode s = 0;
|
||||
URegularExpression *r = uregex_clone(regex, &s);
|
||||
|
@ -620,20 +652,10 @@ prepareResult(NSRegularExpression *regex,
|
|||
options = opts;
|
||||
regex = r;
|
||||
return self;
|
||||
}
|
||||
@end
|
||||
#endif //U_ICU_VERSION_MAJOR_NUM > 4 || (U_ICU_VERSION_MAJOR_NUM == 4 && U_ICU_VERSION_MINOR_NUM >= 4))
|
||||
#endif //HAV_ICU
|
||||
|
||||
#ifndef NSRegularExpressionWorks
|
||||
#import "Foundation/NSRegularExpression.h"
|
||||
#import "Foundation/NSZone.h"
|
||||
#import "Foundation/NSException.h"
|
||||
@implementation NSRegularExpression
|
||||
+ (id)allocWithZone: (NSZone*)aZone
|
||||
{
|
||||
[NSException raise: NSInvalidArgumentException
|
||||
format: @"NSRegularExpression requires ICU 4.4 or later"];
|
||||
}
|
||||
@end
|
||||
#else
|
||||
return [[[self class] allocWithZone: aZone] initWithPattern: [self pattern]
|
||||
options: [self options]
|
||||
error: NULL];
|
||||
#endif
|
||||
}
|
||||
@end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue