Revision: 2815
http://skim-app.svn.sourceforge.net/skim-app/?rev=2815&view=rev
Author: hofman
Date: 2007-09-03 08:23:18 -0700 (Mon, 03 Sep 2007)
Log Message:
-----------
Simplification: add try/catch in a category method.
Modified Paths:
--------------
trunk/SKTemplateParser.h
trunk/SKTemplateParser.m
Modified: trunk/SKTemplateParser.h
===================================================================
--- trunk/SKTemplateParser.h 2007-09-03 11:09:11 UTC (rev 2814)
+++ trunk/SKTemplateParser.h 2007-09-03 15:23:18 UTC (rev 2815)
@@ -60,6 +60,7 @@
@interface NSObject (SKTemplateParser)
- (NSString *)stringDescription;
- (BOOL)isNotEmpty;
+- (id)safeValueForKeyPath:(NSString *)keyPath;
@end
Modified: trunk/SKTemplateParser.m
===================================================================
--- trunk/SKTemplateParser.m 2007-09-03 11:09:11 UTC (rev 2814)
+++ trunk/SKTemplateParser.m 2007-09-03 15:23:18 UTC (rev 2815)
@@ -210,9 +210,7 @@
if ([scanner scanString:SINGLETAG_CLOSE_DELIM intoString:nil]) {
// simple template tag
- @try{ keyValue = [object valueForKeyPath:tag]; }
- @catch (id exception) { keyValue = nil; }
- if (keyValue != nil)
+ if (keyValue = [object safeValueForKeyPath:tag])
[result appendString:[keyValue stringDescription]];
} else if ([scanner scanString:MULTITAG_CLOSE_DELIM
intoString:nil]) {
@@ -249,8 +247,7 @@
lastItemTemplate = nil;
}
- @try{ keyValue = [object valueForKeyPath:tag]; }
- @catch (id exception) { keyValue = nil; }
+ keyValue = [object safeValueForKeyPath:tag];
if ([keyValue
respondsToSelector:@selector(objectEnumerator)]) {
NSEnumerator *itemE = [keyValue objectEnumerator];
id nextItem, item = [itemE nextObject];
@@ -334,8 +331,7 @@
}
[subTemplates addObject:subTemplate];
- @try{ keyValue = [object valueForKeyPath:tag]; }
- @catch (id exception) { keyValue = nil; }
+ keyValue = [object safeValueForKeyPath:tag];
count = [matchStrings count];
subTemplate = nil;
for (i = 0; i < count; i++) {
@@ -415,9 +411,7 @@
if ([scanner scanString:SINGLETAG_CLOSE_DELIM intoString:nil]) {
// simple template tag
- @try{ keyValue = [object valueForKeyPath:tag]; }
- @catch (id exception) { keyValue = nil; }
- if (keyValue != nil) {
+ if (keyValue = [object safeValueForKeyPath:tag]) {
if ([keyValue isKindOfClass:[NSAttributedString class]]) {
tmpAttrStr = [[NSAttributedString alloc]
initWithAttributedString:keyValue attributes:attr];
} else {
@@ -461,8 +455,7 @@
lastItemTemplate = nil;
}
- @try{ keyValue = [object valueForKeyPath:tag]; }
- @catch (id exception) { keyValue = nil; }
+ keyValue = [object safeValueForKeyPath:tag];
if ([keyValue
respondsToSelector:@selector(objectEnumerator)]) {
NSEnumerator *itemE = [keyValue objectEnumerator];
id nextItem, item = [itemE nextObject];
@@ -549,8 +542,7 @@
[subTemplates addObject:subTemplate];
- @try{ keyValue = [object valueForKeyPath:tag]; }
- @catch (id exception) { keyValue = nil; }
+ keyValue = [object safeValueForKeyPath:tag];
count = [matchStrings count];
subTemplate = nil;
for (i = 0; i < count; i++) {
@@ -614,6 +606,13 @@
return YES;
}
+- (id)safeValueForKeyPath:(NSString *)keyPath {
+ id value = nil;
+ @try{ value = [self valueForKeyPath:keyPath]; }
+ @catch (id exception) { value = nil; }
+ return value;
+}
+
@end
#pragma mark -
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
Skim-app-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skim-app-commit