Revision: 5044
http://skim-app.svn.sourceforge.net/skim-app/?rev=5044&view=rev
Author: hofman
Date: 2008-12-10 18:17:47 +0000 (Wed, 10 Dec 2008)
Log Message:
-----------
simplify template parsing
Modified Paths:
--------------
trunk/SKTemplateParser.m
Modified: trunk/SKTemplateParser.m
===================================================================
--- trunk/SKTemplateParser.m 2008-12-10 17:59:55 UTC (rev 5043)
+++ trunk/SKTemplateParser.m 2008-12-10 18:17:47 UTC (rev 5044)
@@ -200,6 +200,21 @@
return altTagRange;
}
+static inline BOOL matchesCondition(NSString *keyValue, NSString *matchString,
SKTemplateTagMatchType matchType) {
+ switch (matchType) {
+ case SKTemplateTagMatchEqual:
+ return [matchString isEqualToString:@""] ? NO == [keyValue
isNotEmpty] : [[keyValue templateStringValue] ?: @""
caseInsensitiveCompare:matchString] == NSOrderedSame;
+ case SKTemplateTagMatchContain:
+ return [matchString isEqualToString:@""] ? NO == [keyValue
isNotEmpty] : [[keyValue templateStringValue] ?: @"" rangeOfString:matchString
options:NSCaseInsensitiveSearch].location != NSNotFound;
+ case SKTemplateTagMatchSmaller:
+ return [matchString isEqualToString:@""] ? NO : [[keyValue
templateStringValue] ?: @"" localizedCaseInsensitiveNumericCompare:matchString]
== NSOrderedAscending;
+ case SKTemplateTagMatchSmallerOrEqual:
+ return [matchString isEqualToString:@""] ? NO == [keyValue
isNotEmpty] : [[keyValue templateStringValue] ?: @""
localizedCaseInsensitiveNumericCompare:matchString] != NSOrderedDescending;
+ default:
+ return [keyValue isNotEmpty];
+ }
+}
+
static inline NSRange rangeAfterRemovingEmptyLines(NSString *string,
SKTemplateTagType typeBefore, SKTemplateTagType typeAfter, BOOL isSubtemplate) {
NSRange range = NSMakeRange(0, [string length]);
@@ -456,44 +471,24 @@
} else {
NSString *matchString = nil;
- BOOL isMatch;
NSArray *matchStrings = [tag matchStrings];
unsigned int i, count = [matchStrings count];
NSArray *subtemplate = nil;
for (i = 0; i < count; i++) {
matchString = [matchStrings objectAtIndex:i];
- if ([matchString hasPrefix:@"$"]) {
+ if ([matchString hasPrefix:@"$"])
matchString = [[object
templateValueForKeyPath:[matchString substringFromIndex:1]]
templateStringValue] ?: @"";
- }
- switch ([tag matchType]) {
- case SKTemplateTagMatchEqual:
- isMatch = [matchString isEqualToString:@""] ? NO
== [keyValue isNotEmpty] : [[keyValue templateStringValue] ?: @""
caseInsensitiveCompare:matchString] == NSOrderedSame;
- break;
- case SKTemplateTagMatchContain:
- isMatch = [matchString isEqualToString:@""] ? NO
== [keyValue isNotEmpty] : [[keyValue templateStringValue] ?: @""
rangeOfString:matchString options:NSCaseInsensitiveSearch].location !=
NSNotFound;
- break;
- case SKTemplateTagMatchSmaller:
- isMatch = [matchString isEqualToString:@""] ? NO :
[[keyValue templateStringValue] ?: @""
localizedCaseInsensitiveNumericCompare:matchString] == NSOrderedAscending;
- break;
- case SKTemplateTagMatchSmallerOrEqual:
- isMatch = [matchString isEqualToString:@""] ? NO
== [keyValue isNotEmpty] : [[keyValue templateStringValue] ?: @""
localizedCaseInsensitiveNumericCompare:matchString] != NSOrderedDescending;
- break;
- default:
- isMatch = [keyValue isNotEmpty];
- break;
- }
- if (isMatch) {
+ if (matchesCondition(keyValue, matchString, [tag
matchType])) {
subtemplate = [tag subtemplateAtIndex:i];
break;
}
}
- if (subtemplate == nil && [[tag subtemplates] count] > count) {
+ if (subtemplate == nil && [[tag subtemplates] count] > count)
subtemplate = [tag subtemplateAtIndex:count];
- }
if (subtemplate != nil) {
- keyValue = [self stringFromTemplateArray:subtemplate
usingObject:object atIndex:anIndex];
- [result appendString:keyValue];
+ if (keyValue = [self stringFromTemplateArray:subtemplate
usingObject:object atIndex:anIndex])
+ [result appendString:keyValue];
}
}
@@ -747,7 +742,6 @@
} else {
NSString *matchString = nil;
- BOOL isMatch;
NSArray *matchStrings = [tag matchStrings];
unsigned int i, count = [matchStrings count];
NSArray *subtemplate = nil;
@@ -756,37 +750,18 @@
subtemplate = nil;
for (i = 0; i < count; i++) {
matchString = [matchStrings objectAtIndex:i];
- if ([matchString hasPrefix:@"$"]) {
+ if ([matchString hasPrefix:@"$"])
matchString = [[object
templateValueForKeyPath:[matchString substringFromIndex:1]]
templateStringValue] ?: @"";
- }
- switch ([tag matchType]) {
- case SKTemplateTagMatchEqual:
- isMatch = [matchString isEqualToString:@""] ? NO
== [keyValue isNotEmpty] : [[keyValue templateStringValue] ?: @""
caseInsensitiveCompare:matchString] == NSOrderedSame;
- break;
- case SKTemplateTagMatchContain:
- isMatch = [matchString isEqualToString:@""] ? NO
== [keyValue isNotEmpty] : [[keyValue templateStringValue] ?: @""
rangeOfString:matchString options:NSCaseInsensitiveSearch].location !=
NSNotFound;
- break;
- case SKTemplateTagMatchSmaller:
- isMatch = [matchString isEqualToString:@""] ? NO :
[[keyValue templateStringValue] ?: @""
localizedCaseInsensitiveNumericCompare:matchString] == NSOrderedAscending;
- break;
- case SKTemplateTagMatchSmallerOrEqual:
- isMatch = [matchString isEqualToString:@""] ? NO
== [keyValue isNotEmpty] : [[keyValue templateStringValue] ?: @""
localizedCaseInsensitiveNumericCompare:matchString] != NSOrderedDescending;
- break;
- default:
- isMatch = [keyValue isNotEmpty];
- break;
- }
- if (isMatch) {
+ if (matchesCondition(keyValue, matchString, [tag
matchType])) {
subtemplate = [tag subtemplateAtIndex:i];
break;
}
}
- if (subtemplate == nil && [[tag subtemplates] count] > count) {
+ if (subtemplate == nil && [[tag subtemplates] count] > count)
subtemplate = [tag subtemplateAtIndex:count];
- }
if (subtemplate != nil) {
- tmpAttrStr = [self
attributedStringFromTemplateArray:subtemplate usingObject:object
atIndex:anIndex];
- [result appendAttributedString:tmpAttrStr];
+ if (tmpAttrStr = [self
attributedStringFromTemplateArray:subtemplate usingObject:object
atIndex:anIndex])
+ [result appendAttributedString:tmpAttrStr];
}
}
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
SF.Net email is Sponsored by MIX09, March 18-20, 2009 in Las Vegas, Nevada.
The future of the web can't happen without you. Join us at MIX09 to help
pave the way to the Next Web now. Learn more and register at
http://ad.doubleclick.net/clk;208669438;13503038;i?http://2009.visitmix.com/
_______________________________________________
Skim-app-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skim-app-commit