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 "NGVCardName.h"
25 @implementation NGVCardName
28 [self->family release];
29 [self->given release];
30 [self->other release];
31 [self->prefix release];
32 [self->suffix release];
38 - (NSString *)family {
47 - (NSString *)prefix {
50 - (NSString *)suffix {
54 /* fake being an array */
56 - (id)objectAtIndex:(unsigned)_idx {
60 case 0: return (s = [self family]) ? s : (NSString *)[NSNull null];
61 case 1: return (s = [self given]) ? s : (NSString *)[NSNull null];
62 case 2: return (s = [self other]) ? s : (NSString *)[NSNull null];
63 case 3: return (s = [self prefix]) ? s : (NSString *)[NSNull null];
64 case 4: return (s = [self suffix]) ? s : (NSString *)[NSNull null];
67 // TODO: throw exception
76 - (NSString *)stringValue {
77 return [self vCardString];
80 - (NSString *)xmlString {
84 ms = [[NSMutableString alloc] initWithCapacity:256];
85 [self appendXMLTag:@"family" value:[self family] to:ms];
86 [self appendXMLTag:@"given" value:[self given] to:ms];
87 [self appendXMLTag:@"other" value:[self other] to:ms];
88 [self appendXMLTag:@"prefix" value:[self prefix] to:ms];
89 [self appendXMLTag:@"suffix" value:[self suffix] to:ms];
90 s = [[ms copy] autorelease];
95 - (NSString *)vCardString {
99 ms = [[NSMutableString alloc] initWithCapacity:256];
100 [self appendVCardValue:[self family] to:ms]; [ms appendString:@";"];
101 [self appendVCardValue:[self given] to:ms]; [ms appendString:@";"];
102 [self appendVCardValue:[self other] to:ms]; [ms appendString:@";"];
103 [self appendVCardValue:[self prefix] to:ms]; [ms appendString:@";"];
104 [self appendVCardValue:[self suffix] to:ms];
105 s = [[ms copy] autorelease];
110 - (NSDictionary *)asDictionary {
111 static NSString *keys[] = {
112 @"family", @"given", @"other", @"prefix", @"suffix", nil
114 id values[[self count] + 1];
117 for (i = 0; i < [self count]; i++)
118 values[i] = [self objectAtIndex:i];
120 return [NSDictionary dictionaryWithObjects:values forKeys:keys
124 - (NSArray *)asArray {
125 id values[[self count] + 1];
128 for (i = 0; i < [self count]; i++)
129 values[i] = [self objectAtIndex:i];
131 return [NSArray arrayWithObjects:values count:[self count]];
135 return [self asDictionary];
140 - (void)encodeWithCoder:(NSCoder *)_coder {
141 [super encodeWithCoder:_coder];
143 [_coder encodeObject:self->family];
144 [_coder encodeObject:self->given];
145 [_coder encodeObject:self->other];
146 [_coder encodeObject:self->prefix];
147 [_coder encodeObject:self->suffix];
149 - (id)initWithCoder:(NSCoder *)_coder {
150 if ((self = [super initWithCoder:_coder]) != nil) {
151 self->family = [[_coder decodeObject] copy];
152 self->given = [[_coder decodeObject] copy];
153 self->other = [[_coder decodeObject] copy];
154 self->prefix = [[_coder decodeObject] copy];
155 self->suffix = [[_coder decodeObject] copy];
160 @end /* NGVCardName */