Skip to content

Commit

Permalink
fixed warnings in FMStatementSplitter when compiling for mac 64-bit
Browse files Browse the repository at this point in the history
  • Loading branch information
V01dZer0 committed Apr 16, 2014
1 parent 3691599 commit bf22880
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 63 deletions.
4 changes: 2 additions & 2 deletions src/extra/FMStatementSplitter/FMStatementKeywordRecogniser.m
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,11 @@ - (NSRange)recogniseRangeWithScanner:(NSScanner *)scanner currentTokenPosition:(
NSUInteger remainingChars = [[scanner string] length] - *tokenPosition;
if (remainingChars >= kwLength)
{
if (CFStringFindWithOptions((CFStringRef)[scanner string], (CFStringRef)keyword, CFRangeMake(*tokenPosition, kwLength), kCFCompareAnchored | kCFCompareCaseInsensitive, NULL))
if (CFStringFindWithOptions((CFStringRef)[scanner string], (CFStringRef)keyword, CFRangeMake((CFIndex)*tokenPosition, (CFIndex)kwLength), kCFCompareAnchored | kCFCompareCaseInsensitive, NULL))
{
if (remainingChars == kwLength ||
nil == self.invalidFollowingCharacters ||
!CFStringFindCharacterFromSet((CFStringRef)[scanner string], (CFCharacterSetRef)self.invalidFollowingCharacters, CFRangeMake(*tokenPosition + kwLength, 1), kCFCompareAnchored, NULL))
!CFStringFindCharacterFromSet((CFStringRef)[scanner string], (CFCharacterSetRef)self.invalidFollowingCharacters, CFRangeMake((CFIndex)(*tokenPosition + kwLength), 1), kCFCompareAnchored, NULL))
{
NSRange result = NSMakeRange(*tokenPosition, kwLength);
*tokenPosition = *tokenPosition + kwLength;
Expand Down
14 changes: 7 additions & 7 deletions src/extra/FMStatementSplitter/FMStatementQuotedRecogniser.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,40 +91,40 @@
*
* @see endQuote
*/
@property (readwrite,copy) NSString *startQuote;
@property (readwrite,nonatomic,copy) NSString *startQuote;

/**
* Determines the string used to indicate the end of the quoted literal.
*
* @see startQuote
*/
@property (readwrite,copy) NSString *endQuote;
@property (readwrite,nonatomic,copy) NSString *endQuote;

/**
* Determines the string used to indicate an escaped character in the quoted literal.
*/
@property (readwrite,copy) NSString *escapeSequence;
@property (readwrite,nonatomic,copy) NSString *escapeSequence;

/**
* If `YES`, quoted string will contains `escapeSequence`.
* If `NO`, quoted string will not contains `escapeSequence`.
* Default is `NO`.
*/
@property (nonatomic, assign) BOOL shouldQuoteEscapeSequence;
@property (nonatomic,assign) BOOL shouldQuoteEscapeSequence;

/**
* Determines how much of the input string to consume when an escaped literal is found, and what to replace it with.
*/
@property (readwrite,copy) NSString *(^escapeReplacer)(NSString *tokenStream, NSUInteger *quotePosition);
@property (readwrite,nonatomic,copy) NSString *(^escapeReplacer)(NSString *tokenStream, NSUInteger *quotePosition);

/**
* Determines the maximum length of the quoted literal not including quotes. To indicate the literal can be any length specify NSNotFound.
*/
@property (readwrite,assign) NSUInteger maximumLength;
@property (readwrite,nonatomic,assign) NSUInteger maximumLength;

/**
* Determines the name of the token produced.
*/
@property (readwrite,copy) NSString *name;
@property (readwrite,nonatomic,copy) NSString *name;

@end
63 changes: 10 additions & 53 deletions src/extra/FMStatementSplitter/FMStatementQuotedRecogniser.m
Original file line number Diff line number Diff line change
Expand Up @@ -54,62 +54,19 @@ - (id)initWithStartQuote:(NSString *)initStartQuote endQuote:(NSString *)initEnd
return self;
}

#define CPQuotedRecogniserStartQuoteKey @"Q.s"
#define CPQuotedRecogniserEndQuoteKey @"Q.e"
#define CPQuotedRecogniserEscapeSequenceKey @"Q.es"
#define CPQuotedRecogniserMaximumLengthKey @"Q.m"
#define CPQuotedRecogniserNameKey @"Q.n"

- (id)initWithCoder:(NSCoder *)aDecoder
{
self = [super init];

if (nil != self)
{
[self setStartQuote:[aDecoder decodeObjectForKey:CPQuotedRecogniserStartQuoteKey]];
[self setEndQuote:[aDecoder decodeObjectForKey:CPQuotedRecogniserEndQuoteKey]];
[self setEscapeSequence:[aDecoder decodeObjectForKey:CPQuotedRecogniserEscapeSequenceKey]];
@try
{
[self setMaximumLength:[aDecoder decodeIntegerForKey:CPQuotedRecogniserMaximumLengthKey]];
}
@catch (NSException *exception)
{
NSLog(@"Warning, value for maximum length too long for this platform, allowing infinite lengths");
[self setMaximumLength:NSNotFound];
}
[self setName:[aDecoder decodeObjectForKey:CPQuotedRecogniserNameKey]];
}

return self;
}

- (void)encodeWithCoder:(NSCoder *)aCoder
{
if (nil != [self escapeReplacer])
{
NSLog(@"Warning: encoding CPQuoteRecogniser with an escapeReplacer set. This will not be recreated when decoded.");
}
[aCoder encodeObject:[self startQuote] forKey:CPQuotedRecogniserStartQuoteKey];
[aCoder encodeObject:[self endQuote] forKey:CPQuotedRecogniserEndQuoteKey];
[aCoder encodeObject:[self escapeSequence] forKey:CPQuotedRecogniserEscapeSequenceKey];
[aCoder encodeInteger:[self maximumLength] forKey:CPQuotedRecogniserMaximumLengthKey];
[aCoder encodeObject:[self name] forKey:CPQuotedRecogniserNameKey];
}

- (NSRange)recogniseRangeWithScanner:(NSScanner *)scanner currentTokenPosition:(NSUInteger *)tokenPosition
{
NSString *(^er)(NSString *tokenStream, NSUInteger *quotePosition) = [self escapeReplacer];
NSUInteger startQuoteLength = [self.startQuote length];
NSUInteger endQuoteLength = [self.endQuote length];
NSString *tokenString = [scanner string];

long inputLength = [tokenString length];
NSUInteger inputLength = [tokenString length];
NSUInteger rangeLength = [FMStatementQuotedRecogniser minWithLeftParam:inputLength - *tokenPosition
rightParam:startQuoteLength + endQuoteLength + self.maximumLength];
CFRange searchRange = CFRangeMake(*tokenPosition, rangeLength);
CFRange searchRange = CFRangeMake((CFIndex)*tokenPosition, (CFIndex)rangeLength);
CFRange range;
BOOL matched = CFStringFindWithOptions((CFStringRef)tokenString, (CFStringRef)self.startQuote, searchRange, kCFCompareAnchored, &range);
Boolean matched = CFStringFindWithOptions((CFStringRef)tokenString, (CFStringRef)self.startQuote, searchRange, kCFCompareAnchored, &range);

CFMutableStringRef outputString = CFStringCreateMutable(kCFAllocatorDefault, 0);

Expand All @@ -120,22 +77,22 @@ - (NSRange)recogniseRangeWithScanner:(NSScanner *)scanner currentTokenPosition:(

CFRange endRange;
CFRange escapeRange;
BOOL matchedEndSequence = CFStringFindWithOptions((CFStringRef)tokenString, (CFStringRef)self.endQuote, searchRange, 0L, &endRange);
BOOL matchedEscapeSequence = nil == self.escapeSequence ? NO : CFStringFindWithOptions((CFStringRef)tokenString, (CFStringRef)self.escapeSequence, searchRange, 0L, &escapeRange);
Boolean matchedEndSequence = CFStringFindWithOptions((CFStringRef)tokenString, (CFStringRef)self.endQuote, searchRange, 0L, &endRange);
Boolean matchedEscapeSequence = nil == self.escapeSequence ? NO : CFStringFindWithOptions((CFStringRef)tokenString, (CFStringRef)self.escapeSequence, searchRange, 0L, &escapeRange);

while (matchedEndSequence && searchRange.location < inputLength)
while (matchedEndSequence && (NSUInteger)searchRange.location < inputLength)
{
if (!matchedEscapeSequence || endRange.location < escapeRange.location)//End quote is not escaped by escape sequence.
{
NSUInteger resultRangeBegin = *tokenPosition;
*tokenPosition = endRange.location + endRange.length;
*tokenPosition = (NSUInteger)(endRange.location + endRange.length);
NSUInteger resultRangeLength = *tokenPosition - resultRangeBegin;
CFRelease(outputString);
return NSMakeRange(resultRangeBegin, resultRangeLength);
}
else//End quote is escaped by escape sequence
{
NSUInteger quotedPosition = escapeRange.location + escapeRange.length;
NSUInteger quotedPosition = (NSUInteger)(escapeRange.location + escapeRange.length);
CFRange subStrRange = CFRangeMake(searchRange.location,
escapeRange.location + (self.shouldQuoteEscapeSequence ? escapeRange.length : 0) - searchRange.location);
CFStringRef substr = CFStringCreateWithSubstring(kCFAllocatorDefault, (CFStringRef)tokenString, subStrRange);
Expand All @@ -158,8 +115,8 @@ - (NSRange)recogniseRangeWithScanner:(NSScanner *)scanner currentTokenPosition:(
CFRelease(substr);
quotedPosition += 1;
}
searchRange.length = searchRange.location + searchRange.length - quotedPosition;
searchRange.location = quotedPosition;
searchRange.length = searchRange.location + searchRange.length - (CFIndex)quotedPosition;
searchRange.location = (CFIndex)quotedPosition;

if (endRange.location < searchRange.location)
{
Expand Down
2 changes: 1 addition & 1 deletion src/extra/FMStatementSplitter/FMStatementTokenRecogniser.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#import <Foundation/Foundation.h>

@protocol FMStatementTokenRecogniser <NSObject, NSCoding>
@protocol FMStatementTokenRecogniser <NSObject>

@required
- (NSRange)recogniseRangeWithScanner:(NSScanner *)scanner currentTokenPosition:(NSUInteger *)tokenPosition;
Expand Down

0 comments on commit bf22880

Please sign in to comment.