2 Copyright (C) 2000-2004 SKYRIX Software AG
4 This file is part of OpenGroupware.org.
6 OGo is free software; you can redistribute it and/or modify it under
7 the terms of the GNU Lesser General Public License as published by the
8 Free Software Foundation; either version 2, or (at your option) any
11 OGo is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
14 License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with OGo; see the file COPYING. If not, write to the
18 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
23 #include <NGExtensions/EOSortOrdering+plist.h>
26 @implementation EOSortOrdering(plist)
29 Initialize a sort-ordering with information contained in the dictionary.
30 The following keys are recognized: "key" is required and specifies the
31 key to be sorted on, "selector" is optional and specifies the sort
32 selector as a string. The default for "selector" is EOCompareAscending
33 and the following "special" values are recognized: "compareAscending",
34 "compareDescending", "compareCaseInsensitiveAscending",
35 "compareCaseInsensitiveDescending".
37 - (id)initWithDictionary:(NSDictionary *)_dict {
39 SEL sel = EOCompareAscending;
47 k = [_dict objectForKey:@"key"];
48 if ([k length] == 0) {
49 NSLog(@"%s: invalid key %@ (dict=%@)", __PRETTY_FUNCTION__, k, _dict);
54 if ((tmp = [[_dict objectForKey:@"selector"] stringValue])) {
55 if ([tmp isEqualToString:@"compareAscending"])
56 sel = EOCompareAscending;
57 else if ([tmp isEqualToString:@"compareDescending"])
58 sel = EOCompareDescending;
59 else if ([tmp isEqualToString:@"compareCaseInsensitiveAscending"])
60 sel = EOCompareCaseInsensitiveAscending;
61 else if ([tmp isEqualToString:@"compareCaseInsensitiveDescending"])
62 sel = EOCompareCaseInsensitiveDescending;
64 sel = NSSelectorFromString(tmp);
66 return [self initWithKey:k selector:sel];
70 Initialize/parse a sort-ordering from a string. Usually the string is
71 taken as the key of the ordering and the sorting EOCompareAscending. This
72 can be modified by adding ".reverse" to the key, eg "name.reverse" sorts
73 on the "name" key using EOCompareDescending.
75 - (id)initWithString:(NSString *)_string {
80 if ([_string length] == 0) {
85 r = [_string rangeOfString:@".reverse"];
88 sel = EOCompareAscending;
91 k = [_string substringToIndex:r.location];
92 sel = EOCompareDescending;
95 return [self initWithKey:k selector:sel];
98 - (id)initWithPropertyList:(id)_plist owner:(id)_owner {
104 if ([_plist isKindOfClass:[NSDictionary class]])
105 return [self initWithDictionary:_plist];
106 if ([_plist isKindOfClass:[NSString class]])
107 return [self initWithString:_plist];
109 if ([_plist isKindOfClass:[self class]]) {
111 return [_plist copy];
117 - (id)initWithPropertyList:(id)_plist {
118 return [self initWithPropertyList:_plist owner:nil];
121 @end /* EOSortOrdering(plist) */