mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-30 08:21:25 +00:00
Implement -isEqual: and -hash on NSRegularExpression, so that copies are
actually equal git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@39871 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
491474cbf3
commit
ac2d08d2a1
4 changed files with 115 additions and 1 deletions
|
@ -133,6 +133,42 @@ NSRegularExpressionOptionsToURegexpFlags(NSRegularExpressionOptions opts)
|
|||
return self;
|
||||
}
|
||||
|
||||
- (BOOL) isEqual: (id)obj
|
||||
{
|
||||
if ([obj isKindOfClass: [NSRegularExpression class]])
|
||||
{
|
||||
if (self == obj)
|
||||
{
|
||||
return YES;
|
||||
}
|
||||
else if (options != ((NSRegularExpression*)obj)->options)
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
else
|
||||
{
|
||||
UErrorCode myErr = 0;
|
||||
UErrorCode theirErr = 0;
|
||||
const UText *myText = uregex_patternUText(regex, &myErr);
|
||||
const UText *theirText =
|
||||
uregex_patternUText(((NSRegularExpression*)obj)->regex, &theirErr);
|
||||
if (U_FAILURE(myErr) != U_FAILURE(theirErr))
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
else if (U_FAILURE(myErr) && U_FAILURE(theirErr))
|
||||
{
|
||||
return YES;
|
||||
}
|
||||
return utext_equals(myText, theirText);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return [super isEqual: obj];
|
||||
}
|
||||
}
|
||||
|
||||
- (NSString*) pattern
|
||||
{
|
||||
UErrorCode s = 0;
|
||||
|
@ -178,12 +214,58 @@ NSRegularExpressionOptionsToURegexpFlags(NSRegularExpressionOptions opts)
|
|||
return self;
|
||||
}
|
||||
|
||||
- (BOOL) isEqual: (id)obj
|
||||
{
|
||||
if ([obj isKindOfClass: [NSRegularExpression class]])
|
||||
{
|
||||
if (self == obj)
|
||||
{
|
||||
return YES;
|
||||
}
|
||||
else if (options != ((NSRegularExpression*)obj)->options)
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
else
|
||||
{
|
||||
UErrorCode myErr = 0;
|
||||
UErrorCode theirErr = 0;
|
||||
int32_t myLen = 0;
|
||||
int32_t theirLen = 0;
|
||||
const UChar *myText = uregex_pattern(regex, &myLen, &myErr);
|
||||
const UChar *theirText = uregex_pattern(
|
||||
((NSRegularExpression*)obj)->regex,
|
||||
&theirLen, &theirErr);
|
||||
if (U_FAILURE(myErr) != U_FAILURE(theirErr))
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
else if (U_FAILURE(myErr) && U_FAILURE(theirErr))
|
||||
{
|
||||
return YES;
|
||||
}
|
||||
if (myLen != theirLen)
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
return
|
||||
(0 == memcmp((const void*)myText, (const void*)theirText, myLen));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return [super isEqual: obj];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
- (NSString*) pattern
|
||||
{
|
||||
UErrorCode s = 0;
|
||||
int32_t length;
|
||||
const unichar *pattern = uregex_pattern(regex, &length, &s);
|
||||
|
||||
|
||||
if (U_FAILURE(s))
|
||||
{
|
||||
return nil;
|
||||
|
@ -192,6 +274,11 @@ NSRegularExpressionOptionsToURegexpFlags(NSRegularExpressionOptions opts)
|
|||
}
|
||||
#endif
|
||||
|
||||
- (NSUInteger) hash
|
||||
{
|
||||
return [[self pattern] hash] ^ options;
|
||||
}
|
||||
|
||||
static UBool
|
||||
callback(const void *context, int32_t steps)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue