Revision: 3952
          http://skim-app.svn.sourceforge.net/skim-app/?rev=3952&view=rev
Author:   hofman
Date:     2008-06-02 05:11:16 -0700 (Mon, 02 Jun 2008)

Log Message:
-----------
Allow invalid key paths with properties of custom array operators by splitting 
these key paths after the array property.

Modified Paths:
--------------
    trunk/SKTemplateParser.m

Modified: trunk/SKTemplateParser.m
===================================================================
--- trunk/SKTemplateParser.m    2008-06-01 16:28:10 UTC (rev 3951)
+++ trunk/SKTemplateParser.m    2008-06-02 12:11:16 UTC (rev 3952)
@@ -860,13 +860,28 @@
     return YES;
 }
 
-- (id)safeValueForKeyPath:(NSString *)keyPath {
+- (id)valueForKeyPathOrNil:(NSString *)keyPath {
     id value = nil;
     @try{ value = [self valueForKeyPath:keyPath]; }
     @catch (id exception) { value = nil; }
     return value;
 }
 
+- (id)safeValueForKeyPath:(NSString *)keyPath {
+    unsigned int atIndex = [keyPath rangeOfString:@"@"].location;
+    if (atIndex != NSNotFound) {
+        unsigned int dotIndex = [keyPath rangeOfString:@"@" options:0 
range:NSMakeRange(atIndex + 1, [keyPath length])].location;
+        if (dotIndex != NSNotFound) {
+            static NSSet *arrayOperators = nil;
+            if (arrayOperators == nil)
+                arrayOperators = [[NSSet alloc] initWithObjects:@"@avg", 
@"@max", @"@min", @"@sum", @"@distinctUnionOfArrays", 
@"@distinctUnionOfObjects", @"@distinctUnionOfSets", @"@unionOfArrays", 
@"@unionOfObjects", @"@unionOfSets", nil];
+            if ([arrayOperators containsObject:[keyPath 
substringWithRange:NSMakeRange(atIndex, dotIndex - atIndex)]] == NO)
+                return [[self valueForKeyPathOrNil:[keyPath 
substringToIndex:dotIndex]] safeValueForKeyPath:[keyPath 
substringFromIndex:dotIndex + 1]];
+        }
+    }
+    return [self valueForKeyPathOrNil:keyPath];
+}
+
 @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: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Skim-app-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skim-app-commit

Reply via email to