From a37f85fba7c28b3f6bf32cd7922271c93258e801 Mon Sep 17 00:00:00 2001 From: Wolfgang Sourdeau Date: Wed, 15 Aug 2007 19:48:35 +0000 Subject: [PATCH] Monotone-Parent: 04980f497e9c317b4d93db9ab0dae2f1e8e464ba Monotone-Revision: af5a859ee61b26ffd727e648f95c54ee60e3079e Monotone-Author: wsourdeau@inverse.ca Monotone-Date: 2007-08-15T19:48:35 Monotone-Branch: ca.inverse.sogo --- ChangeLog | 7 +++++++ SoObjects/SOGo/NSDictionary+Utilities.h | 1 + SoObjects/SOGo/NSDictionary+Utilities.m | 24 ++++++++++++++++++++++++ 3 files changed, 32 insertions(+) diff --git a/ChangeLog b/ChangeLog index 784684cfb..82a1907c8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2007-08-15 Wolfgang Sourdeau + + * SoObjects/SOGo/NSDictionary+Utilities.m ([NSDictionary + -keysWithFormat:keyFormat]): new method inspired by the python + string formatting system and which replaces occurences of "%{key}" + by the corresponding keys. + 2007-08-13 Wolfgang Sourdeau * Main/SOGo.m ([SOGo -run]): check for channel-type specific diff --git a/SoObjects/SOGo/NSDictionary+Utilities.h b/SoObjects/SOGo/NSDictionary+Utilities.h index df40a3427..bc054c813 100644 --- a/SoObjects/SOGo/NSDictionary+Utilities.h +++ b/SoObjects/SOGo/NSDictionary+Utilities.h @@ -30,6 +30,7 @@ @interface NSDictionary (SOGoDictionaryUtilities) - (NSString *) jsonRepresentation; +- (NSString *) keysWithFormat: (NSString *) keyFormat; @end diff --git a/SoObjects/SOGo/NSDictionary+Utilities.m b/SoObjects/SOGo/NSDictionary+Utilities.m index 5b21ce2c9..6caaeaa67 100644 --- a/SoObjects/SOGo/NSDictionary+Utilities.m +++ b/SoObjects/SOGo/NSDictionary+Utilities.m @@ -23,6 +23,7 @@ #import #import +#import "NSArray+Utilities.h" #import "NSObject+Utilities.h" #import "NSDictionary+Utilities.h" @@ -52,4 +53,27 @@ return representation; } +- (NSString *) keysWithFormat: (NSString *) keyFormat +{ + NSArray *keys, *allKeys; + unsigned int count, max; + NSMutableString *keysWithFormat; + id value; + + keysWithFormat = [NSMutableString stringWithString: keyFormat]; + + allKeys = [self allKeys]; + keys = [allKeys stringsWithFormat: @"%{%@}"]; + + max = [allKeys count]; + for (count = 0; count < max; count++) + { + value = [self objectForKey: [allKeys objectAtIndex: count]]; + [keysWithFormat replaceString: [keys objectAtIndex: count] + withString: [value description]]; + } + + return keysWithFormat; +} + @end