mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-29 16:01:38 +00:00
Various fixes in NSTextCheckingResult class.
Add copyright notice to header and implementation files. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@34349 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
9ed632dcdb
commit
4e79a89139
3 changed files with 143 additions and 50 deletions
|
@ -1,20 +1,42 @@
|
|||
/* Copyright (C) 2011 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of the GNUstep 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.
|
||||
*/
|
||||
|
||||
#import "Foundation/NSException.h"
|
||||
#import "Foundation/NSTextCheckingResult.h"
|
||||
#import "Foundation/NSRegularExpression.h"
|
||||
#import "GNUstepBase/NSObject+GNUstepBase.h"
|
||||
|
||||
/**
|
||||
* Private class encapsulating a regular expression match.
|
||||
*/
|
||||
@interface GSRegularExpressionCheckingResult : NSTextCheckingResult
|
||||
{
|
||||
// TODO: This could be made more efficient by adding a variant that only
|
||||
// contained a single range.
|
||||
@public
|
||||
/** The number of ranges matched */
|
||||
NSUInteger rangeCount;
|
||||
/** The array of ranges. */
|
||||
NSRange *ranges;
|
||||
/** The regular expression object that generated this match. */
|
||||
NSRegularExpression *regularExpression;
|
||||
// TODO: This could be made more efficient by adding a variant that only
|
||||
// contained a single range.
|
||||
@public
|
||||
/** The number of ranges matched */
|
||||
NSUInteger rangeCount;
|
||||
/** The array of ranges. */
|
||||
NSRange *ranges;
|
||||
/** The regular expression object that generated this match. */
|
||||
NSRegularExpression *regularExpression;
|
||||
}
|
||||
@end
|
||||
|
||||
|
@ -23,57 +45,90 @@
|
|||
count: (NSUInteger)count
|
||||
regularExpression: (NSRegularExpression*)regularExpression
|
||||
{
|
||||
GSRegularExpressionCheckingResult *result = [GSRegularExpressionCheckingResult new];
|
||||
result->rangeCount = count;
|
||||
result->ranges = calloc(sizeof(NSRange), count);
|
||||
memcpy(result->ranges, ranges, (sizeof(NSRange) * count));
|
||||
ASSIGN(result->regularExpression, regularExpression);
|
||||
return [result autorelease];
|
||||
GSRegularExpressionCheckingResult *result =
|
||||
[GSRegularExpressionCheckingResult new];
|
||||
|
||||
result->rangeCount = count;
|
||||
result->ranges = calloc(sizeof(NSRange), count);
|
||||
memcpy(result->ranges, ranges, (sizeof(NSRange) * count));
|
||||
ASSIGN(result->regularExpression, regularExpression);
|
||||
return [result autorelease];
|
||||
}
|
||||
- (NSDictionary*)addressComponents { return 0; }
|
||||
- (NSDictionary*)components { return 0; }
|
||||
- (NSDate*)date { return 0; }
|
||||
|
||||
- (NSDictionary*)addressComponents { return nil; }
|
||||
- (NSDictionary*)components { return nil; }
|
||||
- (NSDate*)date { return nil; }
|
||||
- (NSTimeInterval) duration { return 0; }
|
||||
- (NSArray*)grammarDetails { return 0; }
|
||||
- (NSUInteger) numberOfRanges { return 0; }
|
||||
- (NSOrthography*)orthography { return 0; }
|
||||
- (NSString*)phoneNumber { return 0; }
|
||||
- (NSRange) range { return NSMakeRange(0, NSNotFound); }
|
||||
- (NSRegularExpression*)regularExpression { return 0; }
|
||||
- (NSString*)replacementString { return 0; }
|
||||
- (NSTextCheckingType)resultType { return -1; }
|
||||
- (NSTimeZone*)timeZone { return 0; }
|
||||
- (NSURL*)URL { return 0; }
|
||||
- (NSUInteger) numberOfRanges { return 1; }
|
||||
- (NSOrthography*)orthography { return nil; }
|
||||
- (NSString*)phoneNumber { return nil; }
|
||||
- (NSRange)range
|
||||
{
|
||||
[self subclassResponsibility: _cmd];
|
||||
return NSMakeRange(NSNotFound, 0);
|
||||
}
|
||||
- (NSRegularExpression*)regularExpression { return nil; }
|
||||
- (NSString*)replacementString { return nil; }
|
||||
- (NSTextCheckingType)resultType
|
||||
{
|
||||
[self subclassResponsibility: _cmd];
|
||||
return -1;
|
||||
}
|
||||
- (NSTimeZone*)timeZone { return nil; }
|
||||
- (NSURL*)URL { return nil; }
|
||||
|
||||
- (NSRange)rangeAtIndex: (NSUInteger)idx
|
||||
{
|
||||
if (idx >= [self numberOfRanges])
|
||||
{
|
||||
[NSException raise: NSInvalidArgumentException
|
||||
format: @"index %lu out of range", (unsigned long)idx];
|
||||
}
|
||||
return [self range];
|
||||
}
|
||||
@end
|
||||
|
||||
|
||||
|
||||
@implementation GSRegularExpressionCheckingResult
|
||||
- (NSUInteger)rangeCount
|
||||
{
|
||||
return rangeCount;
|
||||
}
|
||||
- (NSRange)range
|
||||
{
|
||||
return ranges[0];
|
||||
}
|
||||
- (NSRange)rangeAtIndex: (NSUInteger)idx
|
||||
{
|
||||
if (idx >= rangeCount)
|
||||
{
|
||||
return NSMakeRange(0, NSNotFound);
|
||||
}
|
||||
return ranges[idx];
|
||||
}
|
||||
- (NSTextCheckingType)resultType
|
||||
{
|
||||
return NSTextCheckingTypeRegularExpression;
|
||||
}
|
||||
|
||||
- (void)dealloc
|
||||
{
|
||||
[regularExpression release];
|
||||
free(ranges);
|
||||
[super dealloc];
|
||||
[regularExpression release];
|
||||
free(ranges);
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
- (NSUInteger)numberOfRanges
|
||||
{
|
||||
return rangeCount;
|
||||
}
|
||||
|
||||
- (NSRange)range
|
||||
{
|
||||
return ranges[0];
|
||||
}
|
||||
|
||||
- (NSRange)rangeAtIndex: (NSUInteger)idx
|
||||
{
|
||||
if (idx >= rangeCount)
|
||||
{
|
||||
[NSException raise: NSInvalidArgumentException
|
||||
format: @"index %lu out of range", (unsigned long)idx];
|
||||
}
|
||||
return ranges[idx];
|
||||
}
|
||||
|
||||
- (NSRegularExpression *)regularExpression
|
||||
{
|
||||
return regularExpression;
|
||||
}
|
||||
|
||||
- (NSTextCheckingType)resultType
|
||||
{
|
||||
return NSTextCheckingTypeRegularExpression;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue