2
Copyright (C) 2000-2005 SKYRIX Software AG
4
This file is part of SOPE.
6
SOPE 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
SOPE 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 SOPE; see the file COPYING. If not, write to the
18
Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
22
#include <NGExtensions/EOSortOrdering+plist.h>
25
@implementation EOSortOrdering(plist)
28
Initialize a sort-ordering with information contained in the dictionary.
29
The following keys are recognized: "key" is required and specifies the
30
key to be sorted on, "selector" is optional and specifies the sort
31
selector as a string. The default for "selector" is EOCompareAscending
32
and the following "special" values are recognized: "compareAscending",
33
"compareDescending", "compareCaseInsensitiveAscending",
34
"compareCaseInsensitiveDescending".
36
- (id)initWithDictionary:(NSDictionary *)_dict {
38
SEL sel = EOCompareAscending;
46
k = [_dict objectForKey:@"key"];
47
if ([k length] == 0) {
48
NSLog(@"%s: invalid key %@ (dict=%@)", __PRETTY_FUNCTION__, k, _dict);
53
if ((tmp = [[_dict objectForKey:@"selector"] stringValue])) {
54
if ([tmp isEqualToString:@"compareAscending"])
55
sel = EOCompareAscending;
56
else if ([tmp isEqualToString:@"compareDescending"])
57
sel = EOCompareDescending;
58
else if ([tmp isEqualToString:@"compareCaseInsensitiveAscending"])
59
sel = EOCompareCaseInsensitiveAscending;
60
else if ([tmp isEqualToString:@"compareCaseInsensitiveDescending"])
61
sel = EOCompareCaseInsensitiveDescending;
63
sel = NSSelectorFromString(tmp);
65
return [self initWithKey:k selector:sel];
69
Initialize/parse a sort-ordering from a string. Usually the string is
70
taken as the key of the ordering and the sorting EOCompareAscending. This
71
can be modified by adding ".reverse" to the key, eg "name.reverse" sorts
72
on the "name" key using EOCompareDescending.
74
- (id)initWithString:(NSString *)_string {
79
if ([_string length] == 0) {
84
r = [_string rangeOfString:@".reverse"];
87
sel = EOCompareAscending;
90
k = [_string substringToIndex:r.location];
91
sel = EOCompareDescending;
94
return [self initWithKey:k selector:sel];
97
- (id)initWithPropertyList:(id)_plist owner:(id)_owner {
103
if ([_plist isKindOfClass:[NSDictionary class]])
104
return [self initWithDictionary:_plist];
105
if ([_plist isKindOfClass:[NSString class]])
106
return [self initWithString:_plist];
108
if ([_plist isKindOfClass:[self class]]) {
110
return [_plist copy];
116
- (id)initWithPropertyList:(id)_plist {
117
return [self initWithPropertyList:_plist owner:nil];
120
@end /* EOSortOrdering(plist) */