Revision: 5028
http://skim-app.svn.sourceforge.net/skim-app/?rev=5028&view=rev
Author: hofman
Date: 2008-12-08 17:35:47 +0000 (Mon, 08 Dec 2008)
Log Message:
-----------
Don't remove empty line fragments in subtemplate strings for collection and
condition tags
Modified Paths:
--------------
trunk/SKTemplateParser.h
trunk/SKTemplateParser.m
trunk/SKTemplateTag.m
Modified: trunk/SKTemplateParser.h
===================================================================
--- trunk/SKTemplateParser.h 2008-12-07 12:38:58 UTC (rev 5027)
+++ trunk/SKTemplateParser.h 2008-12-08 17:35:47 UTC (rev 5028)
@@ -38,15 +38,21 @@
#import <Cocoa/Cocoa.h>
+enum {
+ SKTemplateInlineAtStart = 1,
+ SKTemplateInlineAtEnd = 2
+};
@interface SKTemplateParser : NSObject
+ (NSString *)stringByParsingTemplate:(NSString *)template
usingObject:(id)object;
+ (NSArray *)arrayByParsingTemplateString:(NSString *)template;
++ (NSArray *)arrayByParsingTemplateString:(NSString *)template
isSubtemplate:(BOOL)isSubtemplate;
+ (NSString *)stringFromTemplateArray:(NSArray *)template
usingObject:(id)object atIndex:(int)anIndex;
+ (NSAttributedString *)attributedStringByParsingTemplate:(NSAttributedString
*)template usingObject:(id)object;
+ (NSArray *)arrayByParsingTemplateAttributedString:(NSAttributedString
*)template;
++ (NSArray *)arrayByParsingTemplateAttributedString:(NSAttributedString
*)template isSubtemplate:(BOOL)isSubtemplate;
+ (NSAttributedString *)attributedStringFromTemplateArray:(NSArray *)template
usingObject:(id)object atIndex:(int)anIndex;
@end
@@ -70,6 +76,7 @@
@interface NSScanner (SKTemplateParser)
- (BOOL)scanEmptyLine;
+- (BOOL)scanEmptyLineRequiringNewline:(BOOL)requireNL;
@end
Modified: trunk/SKTemplateParser.m
===================================================================
--- trunk/SKTemplateParser.m 2008-12-07 12:38:58 UTC (rev 5027)
+++ trunk/SKTemplateParser.m 2008-12-08 17:35:47 UTC (rev 5028)
@@ -217,6 +217,10 @@
}
+ (NSArray *)arrayByParsingTemplateString:(NSString *)template {
+ return [self arrayByParsingTemplateString:template isSubtemplate:NO];
+}
+
++ (NSArray *)arrayByParsingTemplateString:(NSString *)template
isSubtemplate:(BOOL)isSubtemplate {
NSScanner *scanner = [[NSScanner alloc] initWithString:template];
NSMutableArray *result = [[NSMutableArray alloc] init];
id currentTag = nil;
@@ -262,7 +266,7 @@
// collection template tag
// ignore whitespace before the tag. Should we also remove a
newline?
if (currentTag && [(SKTemplateTag *)currentTag type] ==
SKTextTemplateTagType) {
- wsRange = [[(SKTextTemplateTag *)currentTag text]
rangeOfTrailingEmptyLineRequiringNewline:[result count] != 1];
+ wsRange = [[(SKTextTemplateTag *)currentTag text]
rangeOfTrailingEmptyLineRequiringNewline:[result count] > 1 || isSubtemplate];
if (wsRange.location != NSNotFound) {
if (wsRange.length == [[currentTag text] length]) {
[result removeLastObject];
@@ -275,7 +279,7 @@
endTag = endCollectionTagWithTag(tag);
// ignore the rest of an empty line after the tag
- [scanner scanEmptyLine];
+ [scanner scanEmptyLineRequiringNewline:isSubtemplate];
if ([scanner scanString:endTag intoString:nil])
continue;
if ([scanner scanUpToString:endTag intoString:&itemTemplate]
&& [scanner scanString:endTag intoString:nil]) {
@@ -295,7 +299,7 @@
[currentTag release];
// ignore the the rest of an empty line after the
currentTag
- [scanner scanEmptyLine];
+ [scanner scanEmptyLineRequiringNewline:isSubtemplate];
}
@@ -332,7 +336,7 @@
// condition template tag
// ignore whitespace before the tag. Should we also remove
a newline?
if (currentTag && [(SKTemplateTag *)currentTag type] ==
SKTextTemplateTagType) {
- wsRange = [[(SKTextTemplateTag *)currentTag text]
rangeOfTrailingEmptyLineRequiringNewline:[result count] != 1];
+ wsRange = [[(SKTextTemplateTag *)currentTag text]
rangeOfTrailingEmptyLineRequiringNewline:[result count] > 1 || isSubtemplate];
if (wsRange.location != NSNotFound) {
if (wsRange.length == [[currentTag text] length]) {
[result removeLastObject];
@@ -345,7 +349,7 @@
endTag = endConditionTagWithTag(tag);
// ignore the rest of an empty line after the tag
- [scanner scanEmptyLine];
+ [scanner scanEmptyLineRequiringNewline:isSubtemplate];
if ([scanner scanString:endTag intoString:nil])
continue;
if ([scanner scanUpToString:endTag
intoString:&subTemplate] && [scanner scanString:endTag intoString:nil]) {
@@ -382,7 +386,7 @@
[subTemplates release];
[matchStrings release];
// ignore the the rest of an empty line after the
currentTag
- [scanner scanEmptyLine];
+ [scanner scanEmptyLineRequiringNewline:isSubtemplate];
}
@@ -512,6 +516,10 @@
}
+ (NSArray *)arrayByParsingTemplateAttributedString:(NSAttributedString
*)template {
+ return [self arrayByParsingTemplateAttributedString:template
isSubtemplate:NO];
+}
+
++ (NSArray *)arrayByParsingTemplateAttributedString:(NSAttributedString
*)template isSubtemplate:(BOOL)isSubtemplate {
NSString *templateString = [template string];
NSScanner *scanner = [[NSScanner alloc] initWithString:templateString];
NSMutableArray *result = [[NSMutableArray alloc] init];
@@ -568,7 +576,7 @@
// collection template tag
// ignore whitespace before the tag. Should we also remove a
newline?
if (currentTag && [(SKTemplateTag *)currentTag type] ==
SKTextTemplateTagType) {
- wsRange = [[[(SKRichTextTemplateTag *)currentTag
attributedText] string] rangeOfTrailingEmptyLineRequiringNewline:[result count]
!= 1];
+ wsRange = [[[(SKRichTextTemplateTag *)currentTag
attributedText] string] rangeOfTrailingEmptyLineRequiringNewline:[result count]
> 1 || isSubtemplate];
if (wsRange.location != NSNotFound) {
if (wsRange.length == [[(SKRichTextTemplateTag
*)currentTag attributedText] length]) {
[result removeLastObject];
@@ -581,7 +589,7 @@
endTag = endCollectionTagWithTag(tag);
// ignore the rest of an empty line after the tag
- [scanner scanEmptyLine];
+ [scanner scanEmptyLineRequiringNewline:isSubtemplate];
if ([scanner scanString:endTag intoString:nil])
continue;
start = [scanner scanLocation];
@@ -601,7 +609,7 @@
[currentTag release];
// ignore the the rest of an empty line after the tag
- [scanner scanEmptyLine];
+ [scanner scanEmptyLineRequiringNewline:isSubtemplate];
}
@@ -639,7 +647,7 @@
// condition template tag
// ignore whitespace before the tag. Should we also remove
a newline?
if (currentTag && [(SKTemplateTag *)currentTag type] ==
SKTextTemplateTagType) {
- wsRange = [[[(SKRichTextTemplateTag *)currentTag
attributedText] string] rangeOfTrailingEmptyLineRequiringNewline:[result count]
!= 1];
+ wsRange = [[[(SKRichTextTemplateTag *)currentTag
attributedText] string] rangeOfTrailingEmptyLineRequiringNewline:[result count]
> 1 || isSubtemplate];
if (wsRange.location != NSNotFound) {
if (wsRange.length == [[(SKRichTextTemplateTag
*)currentTag attributedText] length]) {
[result removeLastObject];
@@ -653,7 +661,7 @@
endTag = endConditionTagWithTag(tag);
altTag = altConditionTagWithTag(tag);
// ignore the rest of an empty line after the tag
- [scanner scanEmptyLine];
+ [scanner scanEmptyLineRequiringNewline:isSubtemplate];
if ([scanner scanString:endTag intoString:nil])
continue;
start = [scanner scanLocation];
@@ -690,7 +698,7 @@
[subTemplates release];
[matchStrings release];
// ignore the the rest of an empty line after the tag
- [scanner scanEmptyLine];
+ [scanner scanEmptyLineRequiringNewline:isSubtemplate];
}
@@ -880,6 +888,10 @@
@implementation NSScanner (SKTemplateParser)
- (BOOL)scanEmptyLine {
+ return [self scanEmptyLineRequiringNewline:NO];
+}
+
+- (BOOL)scanEmptyLineRequiringNewline:(BOOL)requireNL {
BOOL foundEndOfLine = NO;
BOOL foundWhitespace = NO;
int startLoc = [self scanLocation];
@@ -897,7 +909,7 @@
[self setScanLocation:[self scanLocation] + 1];
}
}
- if (foundEndOfLine == NO && foundWhitespace == YES)
+ if (foundEndOfLine == NO && (requireNL == YES || foundWhitespace == YES))
[self setScanLocation:startLoc];
return foundEndOfLine;
}
Modified: trunk/SKTemplateTag.m
===================================================================
--- trunk/SKTemplateTag.m 2008-12-07 12:38:58 UTC (rev 5027)
+++ trunk/SKTemplateTag.m 2008-12-08 17:35:47 UTC (rev 5028)
@@ -116,13 +116,13 @@
- (NSArray *)itemTemplate {
if (itemTemplate == nil && itemTemplateString)
- itemTemplate = [[SKTemplateParser
arrayByParsingTemplateString:itemTemplateString] retain];
+ itemTemplate = [[SKTemplateParser
arrayByParsingTemplateString:itemTemplateString isSubtemplate:YES] retain];
return itemTemplate;
}
- (NSArray *)separatorTemplate {
if (separatorTemplate == nil && separatorTemplateString)
- separatorTemplate = [[SKTemplateParser
arrayByParsingTemplateString:separatorTemplateString] retain];
+ separatorTemplate = [[SKTemplateParser
arrayByParsingTemplateString:separatorTemplateString isSubtemplate:YES] retain];
return separatorTemplate;
}
@@ -154,13 +154,13 @@
- (NSArray *)itemTemplate {
if (itemTemplate == nil && itemTemplateAttributedString)
- itemTemplate = [[SKTemplateParser
arrayByParsingTemplateAttributedString:itemTemplateAttributedString] retain];
+ itemTemplate = [[SKTemplateParser
arrayByParsingTemplateAttributedString:itemTemplateAttributedString
isSubtemplate:YES] retain];
return itemTemplate;
}
- (NSArray *)separatorTemplate {
if (separatorTemplate == nil && separatorTemplateAttributedString)
- separatorTemplate = [[SKTemplateParser
arrayByParsingTemplateAttributedString:separatorTemplateAttributedString]
retain];
+ separatorTemplate = [[SKTemplateParser
arrayByParsingTemplateAttributedString:separatorTemplateAttributedString
isSubtemplate:YES] retain];
return separatorTemplate;
}
@@ -202,7 +202,7 @@
- (NSArray *)subtemplateAtIndex:(unsigned)anIndex {
id subtemplate = [subtemplates objectAtIndex:anIndex];
if ([subtemplate isKindOfClass:[NSArray class]] == NO) {
- subtemplate = [[SKTemplateParser
arrayByParsingTemplateString:subtemplate] retain];
+ subtemplate = [[SKTemplateParser
arrayByParsingTemplateString:subtemplate isSubtemplate:YES] retain];
[subtemplates replaceObjectAtIndex:anIndex withObject:subtemplate];
}
return subtemplate;
@@ -217,7 +217,7 @@
- (NSArray *)subtemplateAtIndex:(unsigned)anIndex {
id subtemplate = [subtemplates objectAtIndex:anIndex];
if ([subtemplate isKindOfClass:[NSArray class]] == NO) {
- subtemplate = [[SKTemplateParser
arrayByParsingTemplateAttributedString:subtemplate] retain];
+ subtemplate = [[SKTemplateParser
arrayByParsingTemplateAttributedString:subtemplate isSubtemplate:YES] retain];
[subtemplates replaceObjectAtIndex:anIndex withObject:subtemplate];
}
return subtemplate;
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