Revision: 5029
http://skim-app.svn.sourceforge.net/skim-app/?rev=5029&view=rev
Author: hofman
Date: 2008-12-08 19:54:22 +0000 (Mon, 08 Dec 2008)
Log Message:
-----------
Correct fix for ignoring partial empty lines around template tags
Modified Paths:
--------------
trunk/SKTemplateParser.h
trunk/SKTemplateParser.m
trunk/SKTemplateTag.h
trunk/SKTemplateTag.m
Modified: trunk/SKTemplateParser.h
===================================================================
--- trunk/SKTemplateParser.h 2008-12-08 17:35:47 UTC (rev 5028)
+++ trunk/SKTemplateParser.h 2008-12-08 19:54:22 UTC (rev 5029)
@@ -47,12 +47,12 @@
+ (NSString *)stringByParsingTemplate:(NSString *)template
usingObject:(id)object;
+ (NSArray *)arrayByParsingTemplateString:(NSString *)template;
-+ (NSArray *)arrayByParsingTemplateString:(NSString *)template
isSubtemplate:(BOOL)isSubtemplate;
++ (NSArray *)arrayByParsingTemplateString:(NSString *)template
inlineOptions:(int)inlineOptions;
+ (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;
++ (NSArray *)arrayByParsingTemplateAttributedString:(NSAttributedString
*)template inlineOptions:(int)inlineOptions;
+ (NSAttributedString *)attributedStringFromTemplateArray:(NSArray *)template
usingObject:(id)object atIndex:(int)anIndex;
@end
Modified: trunk/SKTemplateParser.m
===================================================================
--- trunk/SKTemplateParser.m 2008-12-08 17:35:47 UTC (rev 5028)
+++ trunk/SKTemplateParser.m 2008-12-08 19:54:22 UTC (rev 5029)
@@ -185,11 +185,11 @@
return altTag;
}
-static inline NSRange altTemplateTagRange(NSString *template, NSString
*altTag, NSString *endDelim, NSString **argString) {
+static inline NSRange altTemplateTagRange(NSString *template, NSString
*altTag, NSString *endDelim, BOOL requireNL, NSString **argString, BOOL
*foundNL) {
NSRange altTagRange = [template rangeOfString:altTag];
if (altTagRange.location != NSNotFound) {
// ignore whitespaces before the tag
- NSRange wsRange = [template
rangeOfTrailingEmptyLineInRange:NSMakeRange(0, altTagRange.location)];
+ NSRange wsRange = [template
rangeOfTrailingEmptyLineRequiringNewline:requireNL range:NSMakeRange(0,
altTagRange.location)];
if (wsRange.location != NSNotFound)
altTagRange = NSMakeRange(wsRange.location,
NSMaxRange(altTagRange) - wsRange.location);
if (nil != endDelim) {
@@ -203,9 +203,12 @@
}
}
// ignore whitespaces after the tag, including a trailing newline
- wsRange = [template
rangeOfLeadingEmptyLineInRange:NSMakeRange(NSMaxRange(altTagRange), [template
length] - NSMaxRange(altTagRange))];
+ wsRange = [template rangeOfLeadingEmptyLineRequiringNewline:requireNL
range:NSMakeRange(NSMaxRange(altTagRange), [template length] -
NSMaxRange(altTagRange))];
if (wsRange.location != NSNotFound)
altTagRange.length = NSMaxRange(wsRange) - altTagRange.location;
+ if (foundNL) *foundNL = wsRange.location != NSNotFound;
+ } else {
+ if (foundNL) *foundNL = NO;
}
return altTagRange;
}
@@ -217,13 +220,15 @@
}
+ (NSArray *)arrayByParsingTemplateString:(NSString *)template {
- return [self arrayByParsingTemplateString:template isSubtemplate:NO];
+ return [self arrayByParsingTemplateString:template inlineOptions:0];
}
-+ (NSArray *)arrayByParsingTemplateString:(NSString *)template
isSubtemplate:(BOOL)isSubtemplate {
++ (NSArray *)arrayByParsingTemplateString:(NSString *)template
inlineOptions:(int)inlineOptions {
NSScanner *scanner = [[NSScanner alloc] initWithString:template];
NSMutableArray *result = [[NSMutableArray alloc] init];
id currentTag = nil;
+ BOOL inlineAtStart = (inlineOptions & SKTemplateInlineAtStart) != 0;
+ BOOL inlineAtEnd = (inlineOptions & SKTemplateInlineAtEnd) != 0;
[scanner setCharactersToBeSkipped:nil];
@@ -259,14 +264,16 @@
} else if ([scanner scanString:COLLECTION_TAG_CLOSE_DELIM
intoString:nil]) {
- NSString *itemTemplate = nil, *separatorTemplate = nil;
+ SKPlaceholderTemplateTag *itemTemplate = nil,
*separatorTemplate = nil;
+ NSString *itemTemplateString = nil;
NSString *endTag;
NSRange sepTagRange, wsRange;
+ BOOL foundNL, nextFoundNL = NO;
// 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 || isSubtemplate];
+ wsRange = [[(SKTextTemplateTag *)currentTag text]
rangeOfTrailingEmptyLineRequiringNewline:[result count] > 1 || inlineAtStart];
if (wsRange.location != NSNotFound) {
if (wsRange.length == [[currentTag text] length]) {
[result removeLastObject];
@@ -279,27 +286,31 @@
endTag = endCollectionTagWithTag(tag);
// ignore the rest of an empty line after the tag
- [scanner scanEmptyLineRequiringNewline:isSubtemplate];
+ foundNL = [scanner scanEmptyLineRequiringNewline:inlineAtEnd];
if ([scanner scanString:endTag intoString:nil])
continue;
- if ([scanner scanUpToString:endTag intoString:&itemTemplate]
&& [scanner scanString:endTag intoString:nil]) {
+ if ([scanner scanUpToString:endTag
intoString:&itemTemplateString] && [scanner scanString:endTag intoString:nil]) {
// ignore whitespace before the tag. Should we also remove
a newline?
- wsRange = [itemTemplate rangeOfTrailingEmptyLine];
+ wsRange = [itemTemplateString rangeOfTrailingEmptyLine];
if (wsRange.location != NSNotFound)
- itemTemplate = [itemTemplate
substringToIndex:wsRange.location];
+ itemTemplateString = [itemTemplateString
substringToIndex:wsRange.location];
- sepTagRange = altTemplateTagRange(itemTemplate,
sepCollectionTagWithTag(tag), nil, NULL);
+ sepTagRange = altTemplateTagRange(itemTemplateString,
sepCollectionTagWithTag(tag), nil, foundNL == NO, NULL, &nextFoundNL);
if (sepTagRange.location != NSNotFound) {
- separatorTemplate = [itemTemplate
substringFromIndex:NSMaxRange(sepTagRange)];
- itemTemplate = [itemTemplate
substringToIndex:sepTagRange.location];
+ separatorTemplate = [[SKPlaceholderTemplateTag alloc]
initWithString:[itemTemplateString substringFromIndex:NSMaxRange(sepTagRange)]
atStartOfLine:nextFoundNL];
+ itemTemplate = [[SKPlaceholderTemplateTag alloc]
initWithString:[itemTemplateString substringToIndex:sepTagRange.location]
atStartOfLine:foundNL];
+ } else {
+ itemTemplate = [[SKPlaceholderTemplateTag alloc]
initWithString:[itemTemplateString substringToIndex:sepTagRange.location]
atStartOfLine:foundNL];
}
- currentTag = [[SKCollectionTemplateTag alloc]
initWithKeyPath:tag itemTemplateString:itemTemplate
separatorTemplateString:separatorTemplate];
+ currentTag = [(SKCollectionTemplateTag
*)[SKCollectionTemplateTag alloc] initWithKeyPath:tag itemTemplate:itemTemplate
separatorTemplate:separatorTemplate];
[result addObject:currentTag];
[currentTag release];
+ [itemTemplate release];
+ [separatorTemplate release];
// ignore the the rest of an empty line after the
currentTag
- [scanner scanEmptyLineRequiringNewline:isSubtemplate];
+ [scanner scanEmptyLineRequiringNewline:inlineAtEnd];
}
@@ -329,14 +340,16 @@
if ([scanner scanString:CONDITION_TAG_CLOSE_DELIM
intoString:nil]) {
NSMutableArray *subTemplates, *matchStrings;
- NSString *subTemplate = nil;
+ SKPlaceholderTemplateTag *subTemplate = nil;
+ NSString *subTemplateString = nil;
NSString *endTag, *altTag;
NSRange altTagRange, wsRange;
+ BOOL foundNL, nextFoundNL = NO;
// 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 || isSubtemplate];
+ wsRange = [[(SKTextTemplateTag *)currentTag text]
rangeOfTrailingEmptyLineRequiringNewline:[result count] > 1 || inlineAtStart];
if (wsRange.location != NSNotFound) {
if (wsRange.length == [[currentTag text] length]) {
[result removeLastObject];
@@ -349,35 +362,43 @@
endTag = endConditionTagWithTag(tag);
// ignore the rest of an empty line after the tag
- [scanner scanEmptyLineRequiringNewline:isSubtemplate];
+ foundNL = [scanner
scanEmptyLineRequiringNewline:inlineAtEnd];
if ([scanner scanString:endTag intoString:nil])
continue;
- if ([scanner scanUpToString:endTag
intoString:&subTemplate] && [scanner scanString:endTag intoString:nil]) {
+ if ([scanner scanUpToString:endTag
intoString:&subTemplateString] && [scanner scanString:endTag intoString:nil]) {
// ignore whitespace before the currentTag. Should we
also remove a newline?
- wsRange = [subTemplate rangeOfTrailingEmptyLine];
+ wsRange = [subTemplateString rangeOfTrailingEmptyLine];
if (wsRange.location != NSNotFound)
- subTemplate = [subTemplate
substringToIndex:wsRange.location];
+ subTemplateString = [subTemplateString
substringToIndex:wsRange.location];
subTemplates = [[NSMutableArray alloc] init];
matchStrings = [[NSMutableArray alloc]
initWithObjects:matchString ?: @"", nil];
if (matchType != SKTemplateTagMatchOther) {
altTag = compareConditionTagWithTag(tag,
matchType);
- altTagRange = altTemplateTagRange(subTemplate,
altTag, CONDITION_TAG_CLOSE_DELIM, &matchString);
+ altTagRange =
altTemplateTagRange(subTemplateString, altTag, CONDITION_TAG_CLOSE_DELIM,
foundNL == NO, &matchString, &nextFoundNL);
while (altTagRange.location != NSNotFound) {
- [subTemplates addObject:[subTemplate
substringToIndex:altTagRange.location]];
+ subTemplate = [[SKPlaceholderTemplateTag
alloc] initWithString:[subTemplateString substringToIndex:altTagRange.location]
atStartOfLine:foundNL];
+ [subTemplates addObject:subTemplate];
+ [subTemplate release];
[matchStrings addObject:matchString ?: @""];
- subTemplate = [subTemplate
substringFromIndex:NSMaxRange(altTagRange)];
- altTagRange = altTemplateTagRange(subTemplate,
altTag, CONDITION_TAG_CLOSE_DELIM, &matchString);
+ subTemplateString = [subTemplateString
substringFromIndex:NSMaxRange(altTagRange)];
+ foundNL = nextFoundNL;
+ altTagRange =
altTemplateTagRange(subTemplateString, altTag, CONDITION_TAG_CLOSE_DELIM,
foundNL == NO, &matchString, &nextFoundNL);
}
}
- altTagRange = altTemplateTagRange(subTemplate,
altConditionTagWithTag(tag), nil, NULL);
+ altTagRange = altTemplateTagRange(subTemplateString,
altConditionTagWithTag(tag), nil, foundNL == NO, NULL, &nextFoundNL);
if (altTagRange.location != NSNotFound) {
- [subTemplates addObject:[subTemplate
substringToIndex:altTagRange.location]];
- subTemplate = [subTemplate
substringFromIndex:NSMaxRange(altTagRange)];
+ subTemplate = [[SKPlaceholderTemplateTag alloc]
initWithString:[subTemplateString substringToIndex:altTagRange.location]
atStartOfLine:foundNL];
+ [subTemplates addObject:subTemplate];
+ [subTemplate release];
+ subTemplateString = [subTemplateString
substringFromIndex:NSMaxRange(altTagRange)];
+ foundNL = nextFoundNL;
}
+ subTemplate = [[SKPlaceholderTemplateTag alloc]
initWithString:subTemplateString atStartOfLine:foundNL];
[subTemplates addObject:subTemplate];
+ [subTemplate release];
currentTag = [[SKConditionTemplateTag alloc]
initWithKeyPath:tag matchType:matchType matchStrings:matchStrings
subtemplates:subTemplates];
[result addObject:currentTag];
@@ -386,7 +407,7 @@
[subTemplates release];
[matchStrings release];
// ignore the the rest of an empty line after the
currentTag
- [scanner scanEmptyLineRequiringNewline:isSubtemplate];
+ [scanner scanEmptyLineRequiringNewline:inlineAtEnd];
}
@@ -516,14 +537,16 @@
}
+ (NSArray *)arrayByParsingTemplateAttributedString:(NSAttributedString
*)template {
- return [self arrayByParsingTemplateAttributedString:template
isSubtemplate:NO];
+ return [self arrayByParsingTemplateAttributedString:template
inlineOptions:0];
}
-+ (NSArray *)arrayByParsingTemplateAttributedString:(NSAttributedString
*)template isSubtemplate:(BOOL)isSubtemplate {
++ (NSArray *)arrayByParsingTemplateAttributedString:(NSAttributedString
*)template inlineOptions:(int)inlineOptions {
NSString *templateString = [template string];
NSScanner *scanner = [[NSScanner alloc] initWithString:templateString];
NSMutableArray *result = [[NSMutableArray alloc] init];
id currentTag = nil;
+ BOOL inlineAtStart = (inlineOptions & SKTemplateInlineAtStart) != 0;
+ BOOL inlineAtEnd = (inlineOptions & SKTemplateInlineAtEnd) != 0;
[scanner setCharactersToBeSkipped:nil];
@@ -569,14 +592,16 @@
} else if ([scanner scanString:COLLECTION_TAG_CLOSE_DELIM
intoString:nil]) {
NSString *itemTemplateString = nil;
- NSAttributedString *itemTemplate = nil, *separatorTemplate =
nil;
+ SKRichPlaceholderTemplateTag *itemTemplate = nil,
*separatorTemplate = nil;
+ NSAttributedString *itemTemplateAttrString = nil;
NSString *endTag;
NSRange sepTagRange, wsRange;
+ BOOL foundNL, nextFoundNL = NO;
// 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 || isSubtemplate];
+ wsRange = [[[(SKRichTextTemplateTag *)currentTag
attributedText] string] rangeOfTrailingEmptyLineRequiringNewline:[result count]
> 1 || inlineAtStart];
if (wsRange.location != NSNotFound) {
if (wsRange.length == [[(SKRichTextTemplateTag
*)currentTag attributedText] length]) {
[result removeLastObject];
@@ -589,27 +614,31 @@
endTag = endCollectionTagWithTag(tag);
// ignore the rest of an empty line after the tag
- [scanner scanEmptyLineRequiringNewline:isSubtemplate];
+ foundNL = [scanner scanEmptyLineRequiringNewline:inlineAtEnd];
if ([scanner scanString:endTag intoString:nil])
continue;
start = [scanner scanLocation];
if ([scanner scanUpToString:endTag
intoString:&itemTemplateString] && [scanner scanString:endTag intoString:nil]) {
// ignore whitespace before the tag. Should we also remove
a newline?
wsRange = [itemTemplateString rangeOfTrailingEmptyLine];
- itemTemplate = [template
attributedSubstringFromRange:NSMakeRange(start, [itemTemplateString length] -
wsRange.length)];
+ itemTemplateAttrString = [template
attributedSubstringFromRange:NSMakeRange(start, [itemTemplateString length] -
wsRange.length)];
- sepTagRange = altTemplateTagRange([itemTemplate string],
sepCollectionTagWithTag(tag), nil, NULL);
+ sepTagRange = altTemplateTagRange([itemTemplateAttrString
string], sepCollectionTagWithTag(tag), nil, foundNL == NO, NULL, &nextFoundNL);
if (sepTagRange.location != NSNotFound) {
- separatorTemplate = [itemTemplate
attributedSubstringFromRange:NSMakeRange(NSMaxRange(sepTagRange), [itemTemplate
length] - NSMaxRange(sepTagRange))];
- itemTemplate = [itemTemplate
attributedSubstringFromRange:NSMakeRange(0, sepTagRange.location)];
+ separatorTemplate = [[SKRichPlaceholderTemplateTag
alloc] initWithAttributedString:[itemTemplateAttrString
attributedSubstringFromRange:NSMakeRange(NSMaxRange(sepTagRange),
[itemTemplateAttrString length] - NSMaxRange(sepTagRange))]
atStartOfLine:nextFoundNL];
+ itemTemplate = [[SKRichPlaceholderTemplateTag alloc]
initWithAttributedString:[itemTemplateAttrString
attributedSubstringFromRange:NSMakeRange(0, sepTagRange.location)]
atStartOfLine:foundNL];
+ } else {
+ itemTemplate = [[SKRichPlaceholderTemplateTag alloc]
initWithAttributedString:itemTemplateAttrString atStartOfLine:foundNL];
}
- currentTag = [[SKRichCollectionTemplateTag alloc]
initWithKeyPath:tag itemTemplateAttributedString:itemTemplate
separatorTemplateAttributedString:separatorTemplate];
+ currentTag = [(SKRichCollectionTemplateTag
*)[SKRichCollectionTemplateTag alloc] initWithKeyPath:tag
itemTemplate:itemTemplate separatorTemplate:separatorTemplate];
[result addObject:currentTag];
[currentTag release];
+ [itemTemplate release];
+ [separatorTemplate release];
// ignore the the rest of an empty line after the tag
- [scanner scanEmptyLineRequiringNewline:isSubtemplate];
+ [scanner scanEmptyLineRequiringNewline:inlineAtEnd];
}
@@ -640,14 +669,16 @@
NSMutableArray *subTemplates, *matchStrings;
NSString *subTemplateString = nil;
- NSAttributedString *subTemplate = nil;
+ SKRichPlaceholderTemplateTag *subTemplate = nil;
+ NSAttributedString *subTemplateAttrString = nil;
NSString *endTag, *altTag;
NSRange altTagRange, wsRange;
+ BOOL foundNL, nextFoundNL = NO;
// 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 || isSubtemplate];
+ wsRange = [[[(SKRichTextTemplateTag *)currentTag
attributedText] string] rangeOfTrailingEmptyLineRequiringNewline:[result count]
> 1 || inlineAtStart];
if (wsRange.location != NSNotFound) {
if (wsRange.length == [[(SKRichTextTemplateTag
*)currentTag attributedText] length]) {
[result removeLastObject];
@@ -661,35 +692,43 @@
endTag = endConditionTagWithTag(tag);
altTag = altConditionTagWithTag(tag);
// ignore the rest of an empty line after the tag
- [scanner scanEmptyLineRequiringNewline:isSubtemplate];
+ foundNL = [scanner
scanEmptyLineRequiringNewline:inlineAtEnd];
if ([scanner scanString:endTag intoString:nil])
continue;
start = [scanner scanLocation];
if ([scanner scanUpToString:endTag
intoString:&subTemplateString] && [scanner scanString:endTag intoString:nil]) {
// ignore whitespace before the tag. Should we also
remove a newline?
wsRange = [subTemplateString rangeOfTrailingEmptyLine];
- subTemplate = [template
attributedSubstringFromRange:NSMakeRange(start, [subTemplateString length] -
wsRange.length)];
+ subTemplateAttrString = [template
attributedSubstringFromRange:NSMakeRange(start, [subTemplateString length] -
wsRange.length)];
subTemplates = [[NSMutableArray alloc] init];
matchStrings = [[NSMutableArray alloc]
initWithObjects:matchString ?: @"", nil];
if (matchType != SKTemplateTagMatchOther) {
altTag = compareConditionTagWithTag(tag,
matchType);
- altTagRange = altTemplateTagRange([subTemplate
string], altTag, CONDITION_TAG_CLOSE_DELIM, &matchString);
+ altTagRange =
altTemplateTagRange([subTemplateAttrString string], altTag,
CONDITION_TAG_CLOSE_DELIM, foundNL == NO, &matchString, &nextFoundNL);
while (altTagRange.location != NSNotFound) {
- [subTemplates addObject:[subTemplate
attributedSubstringFromRange:NSMakeRange(0, altTagRange.location)]];
+ subTemplate = [[SKRichPlaceholderTemplateTag
alloc] initWithAttributedString:[subTemplateAttrString
attributedSubstringFromRange:NSMakeRange(0, altTagRange.location)]
atStartOfLine:foundNL];
+ [subTemplates addObject:subTemplate];
+ [subTemplate release];
[matchStrings addObject:matchString ?: @""];
- subTemplate = [subTemplate
attributedSubstringFromRange:NSMakeRange(NSMaxRange(altTagRange), [subTemplate
length] - NSMaxRange(altTagRange))];
- altTagRange = altTemplateTagRange([subTemplate
string], altTag, CONDITION_TAG_CLOSE_DELIM, &matchString);
+ subTemplateAttrString = [subTemplateAttrString
attributedSubstringFromRange:NSMakeRange(NSMaxRange(altTagRange),
[subTemplateAttrString length] - NSMaxRange(altTagRange))];
+ foundNL = nextFoundNL;
+ altTagRange =
altTemplateTagRange([subTemplateAttrString string], altTag,
CONDITION_TAG_CLOSE_DELIM, foundNL == NO, &matchString, &nextFoundNL);
}
}
- altTagRange = altTemplateTagRange([subTemplate
string], altConditionTagWithTag(tag), nil, NULL);
+ altTagRange =
altTemplateTagRange([subTemplateAttrString string],
altConditionTagWithTag(tag), nil, foundNL == NO, NULL, &nextFoundNL);
if (altTagRange.location != NSNotFound) {
- [subTemplates addObject:[subTemplate
attributedSubstringFromRange:NSMakeRange(0, altTagRange.location)]];
- subTemplate = [subTemplate
attributedSubstringFromRange:NSMakeRange(NSMaxRange(altTagRange), [subTemplate
length] - NSMaxRange(altTagRange))];
+ subTemplate = [[SKRichPlaceholderTemplateTag
alloc] initWithAttributedString:[subTemplateAttrString
attributedSubstringFromRange:NSMakeRange(0, altTagRange.location)]
atStartOfLine:foundNL];
+ [subTemplates addObject:subTemplate];
+ [subTemplate release];
+ subTemplateAttrString = [subTemplateAttrString
attributedSubstringFromRange:NSMakeRange(NSMaxRange(altTagRange),
[subTemplateAttrString length] - NSMaxRange(altTagRange))];
+ foundNL = nextFoundNL;
}
+ subTemplate = [[SKRichPlaceholderTemplateTag alloc]
initWithAttributedString:subTemplateAttrString atStartOfLine:foundNL];
[subTemplates addObject:subTemplate];
+ [subTemplate release];
currentTag = [[SKRichConditionTemplateTag alloc]
initWithKeyPath:tag matchType:matchType matchStrings:matchStrings
subtemplates:subTemplates];
[result addObject:currentTag];
@@ -698,7 +737,7 @@
[subTemplates release];
[matchStrings release];
// ignore the the rest of an empty line after the tag
- [scanner scanEmptyLineRequiringNewline:isSubtemplate];
+ [scanner scanEmptyLineRequiringNewline:inlineAtEnd];
}
Modified: trunk/SKTemplateTag.h
===================================================================
--- trunk/SKTemplateTag.h 2008-12-08 17:35:47 UTC (rev 5028)
+++ trunk/SKTemplateTag.h 2008-12-08 19:54:22 UTC (rev 5029)
@@ -62,6 +62,34 @@
#pragma mark -
[EMAIL PROTECTED] SKPlaceholderTemplateTag : SKTemplateTag {
+ NSString *string;
+ int inlineOptions;
+}
+
+- (id)initWithString:(NSString *)aString atStartOfLine:(BOOL)flag;
+
+- (NSString *)string;
+- (NSArray *)templateArray;
+
[EMAIL PROTECTED]
+
+#pragma mark -
+
[EMAIL PROTECTED] SKRichPlaceholderTemplateTag : SKTemplateTag {
+ NSAttributedString *attributedString;
+ int inlineOptions;
+}
+
+- (id)initWithAttributedString:(NSAttributedString *)anAttributedString
atStartOfLine:(BOOL)flag;
+
+- (NSAttributedString *)attributedString;
+- (NSArray *)templateArray;
+
[EMAIL PROTECTED]
+
+#pragma mark -
+
@interface SKValueTemplateTag : SKTemplateTag {
NSString *keyPath;
}
@@ -87,13 +115,13 @@
#pragma mark -
@interface SKCollectionTemplateTag : SKValueTemplateTag {
- NSString *itemTemplateString;
- NSString *separatorTemplateString;
- NSMutableArray *itemTemplate;
- NSMutableArray *separatorTemplate;
+ SKPlaceholderTemplateTag *itemPlaceholderTemplate;
+ SKPlaceholderTemplateTag *separatorPlaceholderTemplate;
+ NSArray *itemTemplate;
+ NSArray *separatorTemplate;
}
-- (id)initWithKeyPath:(NSString *)aKeyPath itemTemplateString:(NSString
*)anItemTemplateString separatorTemplateString:(NSString
*)aSeparatorTemplateString;
+- (id)initWithKeyPath:(NSString *)aKeyPath
itemTemplate:(SKPlaceholderTemplateTag *)anItemTemplate
separatorTemplate:(SKPlaceholderTemplateTag *)aSeparatorTemplate;
- (NSArray *)itemTemplate;
- (NSArray *)separatorTemplate;
@@ -103,13 +131,13 @@
#pragma mark -
@interface SKRichCollectionTemplateTag : SKValueTemplateTag {
- NSAttributedString *itemTemplateAttributedString;
- NSAttributedString *separatorTemplateAttributedString;
- NSMutableArray *itemTemplate;
- NSMutableArray *separatorTemplate;
+ SKRichPlaceholderTemplateTag *itemPlaceholderTemplate;
+ SKRichPlaceholderTemplateTag *separatorPlaceholderTemplate;
+ NSArray *itemTemplate;
+ NSArray *separatorTemplate;
}
-- (id)initWithKeyPath:(NSString *)aKeyPath
itemTemplateAttributedString:(NSAttributedString *)anItemTemplateString
separatorTemplateAttributedString:(NSAttributedString
*)aSeparatorTemplateString;
+- (id)initWithKeyPath:(NSString *)aKeyPath
itemTemplate:(SKRichPlaceholderTemplateTag *)anItemTemplate
separatorTemplate:(SKRichPlaceholderTemplateTag *)aSeparatorTemplate;
- (NSArray *)itemTemplate;
- (NSArray *)separatorTemplate;
Modified: trunk/SKTemplateTag.m
===================================================================
--- trunk/SKTemplateTag.m 2008-12-08 17:35:47 UTC (rev 5028)
+++ trunk/SKTemplateTag.m 2008-12-08 19:54:22 UTC (rev 5029)
@@ -46,6 +46,64 @@
#pragma mark -
[EMAIL PROTECTED] SKPlaceholderTemplateTag
+
+- (id)initWithString:(NSString *)aString atStartOfLine:(BOOL)flag {
+ if (self = [super init]) {
+ string = [aString copy];
+ inlineOptions = SKTemplateInlineAtEnd;
+ if (flag)
+ inlineOptions = SKTemplateInlineAtStart;
+ }
+ return self;
+}
+
+- (void)dealloc {
+ [string release];
+ [super dealloc];
+}
+
+- (NSString *)string {
+ return string;
+}
+
+- (NSArray *)templateArray {
+ return [SKTemplateParser arrayByParsingTemplateString:string
inlineOptions:inlineOptions];
+}
+
[EMAIL PROTECTED]
+
+#pragma mark -
+
[EMAIL PROTECTED] SKRichPlaceholderTemplateTag
+
+- (id)initWithAttributedString:(NSAttributedString *)anAttributedString
atStartOfLine:(BOOL)flag {
+ if (self = [super init]) {
+ attributedString = [anAttributedString copy];
+ inlineOptions = SKTemplateInlineAtEnd;
+ if (flag)
+ inlineOptions = SKTemplateInlineAtStart;
+ }
+ return self;
+}
+
+- (void)dealloc {
+ [attributedString release];
+ [super dealloc];
+}
+
+- (NSAttributedString *)attributedString {
+ return attributedString;
+}
+
+- (NSArray *)templateArray {
+ return [SKTemplateParser
arrayByParsingTemplateAttributedString:attributedString
inlineOptions:inlineOptions];
+}
+
[EMAIL PROTECTED]
+
+#pragma mark -
+
@implementation SKValueTemplateTag
- (id)initWithKeyPath:(NSString *)aKeyPath {
@@ -94,10 +152,10 @@
@implementation SKCollectionTemplateTag
-- (id)initWithKeyPath:(NSString *)aKeyPath itemTemplateString:(NSString
*)anItemTemplateString separatorTemplateString:(NSString
*)aSeparatorTemplateString {
+- (id)initWithKeyPath:(NSString *)aKeyPath
itemTemplate:(SKPlaceholderTemplateTag *)anItemTemplate
separatorTemplate:(SKPlaceholderTemplateTag *)aSeparatorTemplate {
if (self = [super initWithKeyPath:aKeyPath]) {
- itemTemplateString = [anItemTemplateString retain];
- separatorTemplateString = [aSeparatorTemplateString retain];
+ itemPlaceholderTemplate = [anItemTemplate retain];
+ separatorPlaceholderTemplate = [aSeparatorTemplate retain];
itemTemplate = nil;
separatorTemplate = nil;
}
@@ -105,8 +163,8 @@
}
- (void)dealloc {
- [itemTemplateString release];
- [separatorTemplateString release];
+ [itemPlaceholderTemplate release];
+ [separatorPlaceholderTemplate release];
[itemTemplate release];
[separatorTemplate release];
[super dealloc];
@@ -115,14 +173,14 @@
- (SKTemplateTagType)type { return SKCollectionTemplateTagType; }
- (NSArray *)itemTemplate {
- if (itemTemplate == nil && itemTemplateString)
- itemTemplate = [[SKTemplateParser
arrayByParsingTemplateString:itemTemplateString isSubtemplate:YES] retain];
+ if (itemTemplate == nil && itemPlaceholderTemplate)
+ itemTemplate = [[itemPlaceholderTemplate templateArray] retain];
return itemTemplate;
}
- (NSArray *)separatorTemplate {
- if (separatorTemplate == nil && separatorTemplateString)
- separatorTemplate = [[SKTemplateParser
arrayByParsingTemplateString:separatorTemplateString isSubtemplate:YES] retain];
+ if (separatorTemplate == nil && separatorPlaceholderTemplate)
+ separatorTemplate = [[separatorPlaceholderTemplate templateArray]
retain];
return separatorTemplate;
}
@@ -132,10 +190,10 @@
@implementation SKRichCollectionTemplateTag
-- (id)initWithKeyPath:(NSString *)aKeyPath
itemTemplateAttributedString:(NSAttributedString *)anItemTemplateString
separatorTemplateAttributedString:(NSAttributedString
*)aSeparatorTemplateString {
+- (id)initWithKeyPath:(NSString *)aKeyPath
itemTemplate:(SKRichPlaceholderTemplateTag *)anItemTemplate
separatorTemplate:(SKRichPlaceholderTemplateTag *)aSeparatorTemplate {
if (self = [super initWithKeyPath:aKeyPath]) {
- itemTemplateAttributedString = [anItemTemplateString retain];
- separatorTemplateAttributedString = [aSeparatorTemplateString retain];
+ itemPlaceholderTemplate = [anItemTemplate retain];
+ separatorPlaceholderTemplate = [aSeparatorTemplate retain];
itemTemplate = nil;
separatorTemplate = nil;
}
@@ -143,8 +201,8 @@
}
- (void)dealloc {
- [itemTemplateAttributedString release];
- [separatorTemplateAttributedString release];
+ [itemPlaceholderTemplate release];
+ [separatorPlaceholderTemplate release];
[itemTemplate release];
[separatorTemplate release];
[super dealloc];
@@ -153,14 +211,14 @@
- (SKTemplateTagType)type { return SKCollectionTemplateTagType; }
- (NSArray *)itemTemplate {
- if (itemTemplate == nil && itemTemplateAttributedString)
- itemTemplate = [[SKTemplateParser
arrayByParsingTemplateAttributedString:itemTemplateAttributedString
isSubtemplate:YES] retain];
+ if (itemTemplate == nil && itemPlaceholderTemplate)
+ itemTemplate = [[itemPlaceholderTemplate templateArray] retain];
return itemTemplate;
}
- (NSArray *)separatorTemplate {
- if (separatorTemplate == nil && separatorTemplateAttributedString)
- separatorTemplate = [[SKTemplateParser
arrayByParsingTemplateAttributedString:separatorTemplateAttributedString
isSubtemplate:YES] retain];
+ if (separatorTemplate == nil && separatorPlaceholderTemplate)
+ separatorTemplate = [[separatorPlaceholderTemplate templateArray]
retain];
return separatorTemplate;
}
@@ -202,7 +260,7 @@
- (NSArray *)subtemplateAtIndex:(unsigned)anIndex {
id subtemplate = [subtemplates objectAtIndex:anIndex];
if ([subtemplate isKindOfClass:[NSArray class]] == NO) {
- subtemplate = [[SKTemplateParser
arrayByParsingTemplateString:subtemplate isSubtemplate:YES] retain];
+ subtemplate = [subtemplate templateArray];
[subtemplates replaceObjectAtIndex:anIndex withObject:subtemplate];
}
return subtemplate;
@@ -217,7 +275,7 @@
- (NSArray *)subtemplateAtIndex:(unsigned)anIndex {
id subtemplate = [subtemplates objectAtIndex:anIndex];
if ([subtemplate isKindOfClass:[NSArray class]] == NO) {
- subtemplate = [[SKTemplateParser
arrayByParsingTemplateAttributedString:subtemplate isSubtemplate:YES] retain];
+ subtemplate = [subtemplate templateArray];
[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