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
27 - (id)initWithArray:(NSArray *)_plist group:(NSString *)_group
28 types:(NSArray *)_types arguments:(NSDictionary *)_a
30 if ((self = [super initWithGroup:_group types:_types arguments:_a]) != nil) {
31 self->values = [_plist copy];
36 - (id)initWithString:(NSString *)_plist group:(NSString *)_group
37 types:(NSArray *)_types arguments:(NSDictionary *)_a
39 // TODO: unescaping of commas?
40 return [self initWithArray:[_plist componentsSeparatedByString:@","]
41 group:_group types:_types arguments:_a];
44 - (id)initWithPropertyList:(id)_plist group:(NSString *)_group
45 types:(NSArray *)_types arguments:(NSDictionary *)_a
47 if ([_plist isKindOfClass:[NSString class]]) {
48 return [self initWithString:_plist
49 group:_group types:_types arguments:_a];
51 if ([_plist isKindOfClass:[NSArray class]]) {
52 return [self initWithArray:_plist
53 group:_group types:_types arguments:_a];
56 [self logWithFormat:@"ERROR: unexpected property list type: %@",
61 - (id)initWithPropertyList:(id)_plist {
62 return [self initWithPropertyList:_plist group:nil types:nil arguments:nil];
65 - (id)initWithGroup:(NSString *)_group types:(NSArray *)_types
66 arguments:(NSDictionary *)_a
68 return [self initWithArray:nil
69 group:_group types:_types arguments:_a];
72 return [self initWithPropertyList:nil group:nil types:nil arguments:nil];
76 [self->values release];
88 - (NSString *)stringValue {
89 return [self vCardString];
92 - (NSString *)xmlString {
93 return [[self stringValue] stringByEscapingXMLString];
96 - (NSString *)vCardString {
97 return [[self values] componentsJoinedByString:@","];
101 return [self values];
104 - (NSArray *)asArray {
108 /* fake being an array */
110 - (id)objectAtIndex:(unsigned)_idx {
111 return [self->values objectAtIndex:_idx];
114 return [self->values count];
117 /* fake being a string */
119 - (unichar)characterAtIndex:(unsigned)_idx {
120 return [[self stringValue] characterAtIndex:_idx];
123 return [[self stringValue] length];
128 - (void)encodeWithCoder:(NSCoder *)_coder {
129 [super encodeWithCoder:_coder];
130 [_coder encodeObject:self->values];
132 - (id)initWithCoder:(NSCoder *)_coder {
133 if ((self = [super initWithCoder:_coder]) != nil) {
134 self->values = [[_coder decodeObject] copy];
141 - (void)appendAttributesToDescription:(NSMutableString *)_ms {
142 [super appendAttributesToDescription:_ms];
143 [_ms appendFormat:@" vcard=%@", [self vCardString]];
146 @end /* NGVCardStrArrayValue */