Revision: 13997
http://sourceforge.net/p/skim-app/code/13997
Author: hofman
Date: 2023-12-27 00:08:22 +0000 (Wed, 27 Dec 2023)
Log Message:
-----------
use __kindof SKTemplateTag * instead of SKTemplateTag * to avoid typecasts
Modified Paths:
--------------
trunk/SKTemplateParser.h
trunk/SKTemplateParser.m
trunk/SKTemplateTag.h
Modified: trunk/SKTemplateParser.h
===================================================================
--- trunk/SKTemplateParser.h 2023-12-26 23:45:11 UTC (rev 13996)
+++ trunk/SKTemplateParser.h 2023-12-27 00:08:22 UTC (rev 13997)
@@ -45,14 +45,14 @@
@interface SKTemplateParser : NSObject
+ (NSString *)stringByParsingTemplateString:(NSString *)templateString
usingObject:(id)object;
-+ (NSArray<SKTemplateTag *> *)arrayByParsingTemplateString:(NSString
*)templateString;
-+ (NSArray<SKTemplateTag *> *)arrayByParsingTemplateString:(NSString
*)templateString isSubtemplate:(BOOL)isSubtemplate;
-+ (NSString *)stringFromTemplateArray:(NSArray<SKTemplateTag *>
*)templateArray usingObject:(id)object atIndex:(NSInteger)anIndex;
++ (NSArray<__kindof SKTemplateTag *> *)arrayByParsingTemplateString:(NSString
*)templateString;
++ (NSArray<__kindof SKTemplateTag *> *)arrayByParsingTemplateString:(NSString
*)templateString isSubtemplate:(BOOL)isSubtemplate;
++ (NSString *)stringFromTemplateArray:(NSArray<__kindof SKTemplateTag *>
*)templateArray usingObject:(id)object atIndex:(NSInteger)anIndex;
+ (NSAttributedString
*)attributedStringByParsingTemplateAttributedString:(NSAttributedString
*)templateAttrString usingObject:(id)object;
-+ (NSArray<SKTemplateTag *>
*)arrayByParsingTemplateAttributedString:(NSAttributedString
*)templateAttrString;
-+ (NSArray<SKTemplateTag *>
*)arrayByParsingTemplateAttributedString:(NSAttributedString
*)templateAttrString isSubtemplate:(BOOL)isSubtemplate;
-+ (NSAttributedString
*)attributedStringFromTemplateArray:(NSArray<SKTemplateTag *> *)templateArray
usingObject:(id)object atIndex:(NSInteger)anIndex;
++ (NSArray<__kindof SKTemplateTag *>
*)arrayByParsingTemplateAttributedString:(NSAttributedString
*)templateAttrString;
++ (NSArray<__kindof SKTemplateTag *>
*)arrayByParsingTemplateAttributedString:(NSAttributedString
*)templateAttrString isSubtemplate:(BOOL)isSubtemplate;
++ (NSAttributedString *)attributedStringFromTemplateArray:(NSArray<__kindof
SKTemplateTag *> *)templateArray usingObject:(id)object
atIndex:(NSInteger)anIndex;
@end
Modified: trunk/SKTemplateParser.m
===================================================================
--- trunk/SKTemplateParser.m 2023-12-26 23:45:11 UTC (rev 13996)
+++ trunk/SKTemplateParser.m 2023-12-27 00:08:22 UTC (rev 13997)
@@ -355,7 +355,7 @@
+ (NSArray *)arrayByParsingTemplateString:(NSString *)template
isSubtemplate:(BOOL)isSubtemplate {
NSScanner *scanner = [[NSScanner alloc] initWithString:template];
NSMutableArray *result = [[NSMutableArray alloc] init];
- id currentTag = nil;
+ __kindof SKTemplateTag *currentTag = nil;
[scanner setCharactersToBeSkipped:nil];
@@ -365,8 +365,8 @@
NSInteger start;
if ([scanner scanUpToString:START_TAG_OPEN_DELIM
intoString:&beforeText]) {
- if (currentTag && [(SKTemplateTag *)currentTag type] ==
SKTemplateTagText) {
- [(SKTextTemplateTag *)currentTag appendText:beforeText];
+ if (currentTag && [currentTag type] == SKTemplateTagText) {
+ [currentTag appendText:beforeText];
} else {
currentTag = [[SKTextTemplateTag alloc]
initWithText:beforeText];
[result addObject:currentTag];
@@ -403,7 +403,7 @@
itemTemplate = [itemTemplate
substringToIndex:sepTagRange.location];
}
- currentTag = [(SKCollectionTemplateTag
*)[SKCollectionTemplateTag alloc] initWithKeyPath:keyPath
itemTemplateString:itemTemplate separatorTemplateString:separatorTemplate];
+ currentTag = [[SKCollectionTemplateTag alloc]
initWithKeyPath:keyPath itemTemplateString:itemTemplate
separatorTemplateString:separatorTemplate];
[result addObject:currentTag];
}
@@ -452,8 +452,8 @@
} else {
// an open delimiter without a close delimiter, so no
template tag. Rewind
- if (currentTag && [(SKTemplateTag *)currentTag type] ==
SKTemplateTagText) {
- [(SKTextTemplateTag *)currentTag
appendText:START_TAG_OPEN_DELIM];
+ if (currentTag && [currentTag type] == SKTemplateTagText) {
+ [currentTag appendText:START_TAG_OPEN_DELIM];
} else {
currentTag = [[SKTextTemplateTag alloc]
initWithText:START_TAG_OPEN_DELIM];
[result addObject:currentTag];
@@ -469,17 +469,17 @@
NSInteger i, count = [result count];
for (i = count - 1; i >= 0; i--) {
- SKTemplateTag *tag = [result objectAtIndex:i];
+ __kindof SKTemplateTag *tag = [result objectAtIndex:i];
if ([tag type] != SKTemplateTagText) continue;
- NSString *string = [(SKTextTemplateTag *)tag text];
+ NSString *string = [tag text];
NSRange range = rangeAfterRemovingEmptyLines(string, i > 0 ?
[(SKTemplateTag *)[result objectAtIndex:i - 1] type] : SKNoTemplateTagType, i <
count - 1 ? [(SKTemplateTag *)[result objectAtIndex:i + 1] type] :
SKNoTemplateTagType, isSubtemplate);
if (range.length == 0)
[result removeObjectAtIndex:i];
else if (range.length != [string length])
- [(SKTextTemplateTag *)tag setText:[string
substringWithRange:range]];
+ [tag setText:[string substringWithRange:range]];
}
return result;
@@ -488,12 +488,12 @@
+ (NSString *)stringFromTemplateArray:(NSArray *)template
usingObject:(id)object atIndex:(NSInteger)anIndex {
NSMutableString *result = [[NSMutableString alloc] init];
- for (id tag in template) {
- SKTemplateTagType type = [(SKTemplateTag *)tag type];
+ for (__kindof SKTemplateTag *tag in template) {
+ SKTemplateTagType type = [tag type];
if (type == SKTemplateTagText) {
- [result appendString:[(SKTextTemplateTag *)tag text]];
+ [result appendString:[tag text]];
} else {
@@ -578,7 +578,7 @@
NSString *templateString = [template string];
NSScanner *scanner = [[NSScanner alloc] initWithString:templateString];
NSMutableArray *result = [[NSMutableArray alloc] init];
- id currentTag = nil;
+ __kindof SKTemplateTag *currentTag = nil;
[scanner setCharactersToBeSkipped:nil];
@@ -591,8 +591,8 @@
start = [scanner scanLocation];
if ([scanner scanUpToString:START_TAG_OPEN_DELIM
intoString:&beforeText]) {
- if (currentTag && [(SKTemplateTag *)currentTag type] ==
SKTemplateTagText) {
- [(SKRichTextTemplateTag *)currentTag
appendAttributedText:[template attributedSubstringFromRange:NSMakeRange(start,
[beforeText length])]];
+ if (currentTag && [currentTag type] == SKTemplateTagText) {
+ [currentTag appendAttributedText:[template
attributedSubstringFromRange:NSMakeRange(start, [beforeText length])]];
} else {
currentTag = [[SKRichTextTemplateTag alloc]
initWithAttributedText:[template
attributedSubstringFromRange:NSMakeRange(start, [beforeText length])]];
[result addObject:currentTag];
@@ -636,7 +636,7 @@
itemTemplate = [itemTemplate
attributedSubstringFromRange:NSMakeRange(0, sepTagRange.location)];
}
- currentTag = [(SKRichCollectionTemplateTag
*)[SKRichCollectionTemplateTag alloc] initWithKeyPath:keyPath
itemTemplateAttributedString:itemTemplate
separatorTemplateAttributedString:separatorTemplate];
+ currentTag = [[SKRichCollectionTemplateTag alloc]
initWithKeyPath:keyPath itemTemplateAttributedString:itemTemplate
separatorTemplateAttributedString:separatorTemplate];
[result addObject:currentTag];
}
@@ -689,8 +689,8 @@
} else {
// a START_TAG_OPEN_DELIM without
COLLECTION_TAG_CLOSE_DELIM, so no template tag. Rewind
- if (currentTag && [(SKTemplateTag *)currentTag type] ==
SKTemplateTagText) {
- [(SKRichTextTemplateTag *)currentTag
appendAttributedText:[template attributedSubstringFromRange:NSMakeRange(start -
[START_TAG_OPEN_DELIM length], [START_TAG_OPEN_DELIM length])]];
+ if (currentTag && [currentTag type] == SKTemplateTagText) {
+ [currentTag appendAttributedText:[template
attributedSubstringFromRange:NSMakeRange(start - [START_TAG_OPEN_DELIM length],
[START_TAG_OPEN_DELIM length])]];
} else {
currentTag = [[SKRichTextTemplateTag alloc]
initWithAttributedText:[template attributedSubstringFromRange:NSMakeRange(start
- [START_TAG_OPEN_DELIM length], [START_TAG_OPEN_DELIM length])]];
[result addObject:currentTag];
@@ -707,11 +707,11 @@
NSInteger i, count = [result count];
for (i = count - 1; i >= 0; i--) {
- SKTemplateTag *tag = [result objectAtIndex:i];
+ __kindof SKTemplateTag *tag = [result objectAtIndex:i];
if ([tag type] != SKTemplateTagText) continue;
- NSAttributedString *attrString = [(SKRichTextTemplateTag *)tag
attributedText];
+ NSAttributedString *attrString = [tag attributedText];
NSString *string = [attrString string];
NSRange range = rangeAfterRemovingEmptyLines(string, i > 0 ?
[(SKTemplateTag *)[result objectAtIndex:i - 1] type] : SKNoTemplateTagType, i <
count - 1 ? [(SKTemplateTag *)[result objectAtIndex:i + 1] type] :
SKNoTemplateTagType, isSubtemplate);
@@ -718,7 +718,7 @@
if (range.length == 0)
[result removeObjectAtIndex:i];
else if (range.length != [string length])
- [(SKRichTextTemplateTag *)tag setAttributedText:[attrString
attributedSubstringFromRange:range]];
+ [tag setAttributedText:[attrString
attributedSubstringFromRange:range]];
}
return result;
@@ -736,13 +736,13 @@
+ (NSAttributedString *)attributedStringFromTemplateArray:(NSArray *)template
usingObject:(id)object atIndex:(NSInteger)anIndex {
NSMutableAttributedString *result = [[NSMutableAttributedString alloc]
init];
- for (id tag in template) {
- SKTemplateTagType type = [(SKTemplateTag *)tag type];
+ for (__kindof SKTemplateTag *tag in template) {
+ SKTemplateTagType type = [tag type];
if (type == SKTemplateTagText) {
- NSAttributedString *tmpAttrStr = [(SKRichTextTemplateTag *)tag
attributedText];
- NSArray *linkTemplates = [(SKRichTextTemplateTag *)tag
linkTemplates];
+ NSAttributedString *tmpAttrStr = [tag attributedText];
+ NSArray *linkTemplates = [tag linkTemplates];
if ([linkTemplates count]) {
NSMutableAttributedString *tmpMutAttrStr = [tmpAttrStr
mutableCopy];
@@ -768,8 +768,8 @@
if (keyValue) {
NSAttributedString *tmpAttrStr;
- NSDictionary *attrs = [(SKRichValueTemplateTag *)tag
attributes];
- SKAttributeTemplate *linkTemplate =
[(SKRichValueTemplateTag *)tag linkTemplate];
+ NSDictionary *attrs = [tag attributes];
+ SKAttributeTemplate *linkTemplate = [tag linkTemplate];
if (linkTemplate) {
NSMutableDictionary *tmpAttrs = [attrs mutableCopy];
id aLink = [self attributeFromTemplate:linkTemplate
usingObject:object atIndex:anIndex];
Modified: trunk/SKTemplateTag.h
===================================================================
--- trunk/SKTemplateTag.h 2023-12-26 23:45:11 UTC (rev 13996)
+++ trunk/SKTemplateTag.h 2023-12-27 00:08:22 UTC (rev 13997)
@@ -98,13 +98,13 @@
@interface SKCollectionTemplateTag : SKValueTemplateTag {
NSString *itemTemplateString;
NSString *separatorTemplateString;
- NSArray<SKTemplateTag *> *itemTemplate;
- NSArray<SKTemplateTag *> *separatorTemplate;
+ NSArray<__kindof SKTemplateTag *> *itemTemplate;
+ NSArray<__kindof SKTemplateTag *> *separatorTemplate;
}
- (instancetype)initWithKeyPath:(NSString *)aKeyPath
itemTemplateString:(NSString *)anItemTemplateString
separatorTemplateString:(nullable NSString *)aSeparatorTemplateString;
-@property (nonatomic, nullable, readonly) NSArray<SKTemplateTag *>
*itemTemplate, *separatorTemplate;
+@property (nonatomic, nullable, readonly) NSArray<__kindof SKTemplateTag *>
*itemTemplate, *separatorTemplate;
@end
@@ -113,13 +113,13 @@
@interface SKRichCollectionTemplateTag : SKValueTemplateTag {
NSAttributedString *itemTemplateAttributedString;
NSAttributedString *separatorTemplateAttributedString;
- NSArray<SKTemplateTag *> *itemTemplate;
- NSArray<SKTemplateTag *> *separatorTemplate;
+ NSArray<__kindof SKTemplateTag *> *itemTemplate;
+ NSArray<__kindof SKTemplateTag *> *separatorTemplate;
}
- (instancetype)initWithKeyPath:(NSString *)aKeyPath
itemTemplateAttributedString:(NSAttributedString
*)anItemTemplateAttributedString separatorTemplateAttributedString:(nullable
NSAttributedString *)aSeparatorTemplateAttributedString;
-@property (nonatomic, nullable, readonly) NSArray<SKTemplateTag *>
*itemTemplate, *separatorTemplate;
+@property (nonatomic, nullable, readonly) NSArray<__kindof SKTemplateTag *>
*itemTemplate, *separatorTemplate;
@end
@@ -137,7 +137,7 @@
@property (nonatomic, readonly) NSArray<NSString *> *matchStrings;
- (NSUInteger)countOfSubtemplates;
-- (NSArray<SKTemplateTag *> *)objectInSubtemplatesAtIndex:(NSUInteger)anIndex;
+- (NSArray<__kindof SKTemplateTag *>
*)objectInSubtemplatesAtIndex:(NSUInteger)anIndex;
@end
@@ -164,7 +164,7 @@
@interface SKRichTextTemplateTag : SKTemplateTag {
NSAttributedString *attributedText;
- NSArray<NSArray<SKTemplateTag *> *> *linkTemplates;
+ NSArray<NSArray<__kindof SKTemplateTag *> *> *linkTemplates;
}
- (instancetype)initWithAttributedText:(NSAttributedString *)anAttributedText;
@@ -173,7 +173,7 @@
- (void)appendAttributedText:(NSAttributedString *)newAttributedText;
-@property (nonatomic, nullable, readonly) NSArray<NSArray<SKTemplateTag *> *>
*linkTemplates;
+@property (nonatomic, nullable, readonly) NSArray<NSArray<__kindof
SKTemplateTag *> *> *linkTemplates;
@end
@@ -180,14 +180,14 @@
#pragma mark -
@interface SKAttributeTemplate : NSObject {
- NSArray<SKTemplateTag *> *template;
+ NSArray<__kindof SKTemplateTag *> *template;
NSRange range;
Class attributeClass;
}
-- (instancetype)initWithTemplate:(nullable NSArray<SKTemplateTag *>
*)aTemplate range:(NSRange)aRange attributeClass:(Class)aClass;
+- (instancetype)initWithTemplate:(nullable NSArray<__kindof SKTemplateTag *>
*)aTemplate range:(NSRange)aRange attributeClass:(Class)aClass;
-@property (nonatomic, nullable, readonly) NSArray<SKTemplateTag *> *template;
+@property (nonatomic, nullable, readonly) NSArray<__kindof SKTemplateTag *>
*template;
@property (nonatomic, readonly) NSRange range;
@property (nonatomic, readonly) Class attributeClass;
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
_______________________________________________
Skim-app-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skim-app-commit