2 Copyright (C) 2005 Helge Hess
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 "NGVCardStrArrayValue.h"
25 @implementation NGVCardStrArrayValue
28 return [super version] + 0 /* v0 */;
31 NSAssert2([super version] == 0,
32 @"invalid superclass (%@) version %i !",
33 NSStringFromClass([self superclass]), [super version]);
36 - (id)initWithArray:(NSArray *)_plist group:(NSString *)_group
37 types:(NSArray *)_types arguments:(NSDictionary *)_a
39 if ((self = [super initWithGroup:_group types:_types arguments:_a]) != nil) {
40 self->values = [_plist copy];
45 - (id)initWithString:(NSString *)_plist group:(NSString *)_group
46 types:(NSArray *)_types arguments:(NSDictionary *)_a
48 // TODO: unescaping of commas?
49 return [self initWithArray:[_plist componentsSeparatedByString:@","]
50 group:_group types:_types arguments:_a];
53 - (id)initWithPropertyList:(id)_plist group:(NSString *)_group
54 types:(NSArray *)_types arguments:(NSDictionary *)_a
56 if ([_plist isKindOfClass:[NSString class]]) {
57 return [self initWithString:_plist
58 group:_group types:_types arguments:_a];
60 if ([_plist isKindOfClass:[NSArray class]]) {
61 return [self initWithArray:_plist
62 group:_group types:_types arguments:_a];
65 [self logWithFormat:@"ERROR: unexpected property list type: %@",
70 - (id)initWithPropertyList:(id)_plist {
71 return [self initWithPropertyList:_plist group:nil types:nil arguments:nil];
74 - (id)initWithGroup:(NSString *)_group types:(NSArray *)_types
75 arguments:(NSDictionary *)_a
77 return [self initWithArray:nil
78 group:_group types:_types arguments:_a];
81 return [self initWithPropertyList:nil group:nil types:nil arguments:nil];
85 [self->values release];
97 - (NSString *)stringValue {
98 return [self vCardString];
101 - (NSString *)xmlString {
102 return [[self stringValue] stringByEscapingXMLString];
105 - (NSString *)vCardString {
106 return [[self values] componentsJoinedByString:@","];
110 return [self values];
113 - (NSArray *)asArray {
117 /* fake being an array */
119 - (id)objectAtIndex:(unsigned)_idx {
120 return [self->values objectAtIndex:_idx];
123 return [self->values count];
126 /* fake being a string */
128 - (unichar)characterAtIndex:(unsigned)_idx {
129 return [[self stringValue] characterAtIndex:_idx];
132 return [[self stringValue] length];
137 - (void)encodeWithCoder:(NSCoder *)_coder {
138 [super encodeWithCoder:_coder];
139 [_coder encodeObject:self->values];
141 - (id)initWithCoder:(NSCoder *)_coder {
142 if ((self = [super initWithCoder:_coder]) != nil) {
143 self->values = [[_coder decodeObject] copy];
150 - (void)appendAttributesToDescription:(NSMutableString *)_ms {
151 [super appendAttributesToDescription:_ms];
152 [_ms appendFormat:@" vcard=%@", [self vCardString]];
155 @end /* NGVCardStrArrayValue */