~ubuntu-branches/ubuntu/edgy/sope/edgy

« back to all changes in this revision

Viewing changes to sope-ical/NGiCal/NGVCardStrArrayValue.m

  • Committer: Bazaar Package Importer
  • Author(s): Sebastian Ley
  • Date: 2005-08-19 16:53:31 UTC
  • Revision ID: james.westby@ubuntu.com-20050819165331-hs683wz1osm708pw
Tags: upstream-4.4rc.2
ImportĀ upstreamĀ versionĀ 4.4rc.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
  Copyright (C) 2005 Helge Hess
 
3
 
 
4
  This file is part of SOPE.
 
5
 
 
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
 
9
  later version.
 
10
 
 
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.
 
15
 
 
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
 
19
  02111-1307, USA.
 
20
*/
 
21
 
 
22
#include "NGVCardStrArrayValue.h"
 
23
#include "common.h"
 
24
 
 
25
@implementation NGVCardStrArrayValue
 
26
 
 
27
- (id)initWithArray:(NSArray *)_plist group:(NSString *)_group 
 
28
  types:(NSArray *)_types arguments:(NSDictionary *)_a
 
29
{
 
30
  if ((self = [super initWithGroup:_group types:_types arguments:_a]) != nil) {
 
31
    self->values = [_plist copy];
 
32
  }
 
33
  return self;
 
34
}
 
35
 
 
36
- (id)initWithString:(NSString *)_plist group:(NSString *)_group 
 
37
  types:(NSArray *)_types arguments:(NSDictionary *)_a
 
38
{
 
39
  // TODO: unescaping of commas?
 
40
  return [self initWithArray:[_plist componentsSeparatedByString:@","]
 
41
               group:_group types:_types arguments:_a];
 
42
}
 
43
 
 
44
- (id)initWithPropertyList:(id)_plist group:(NSString *)_group 
 
45
  types:(NSArray *)_types arguments:(NSDictionary *)_a
 
46
{
 
47
  if ([_plist isKindOfClass:[NSString class]]) {
 
48
    return [self initWithString:_plist
 
49
                 group:_group types:_types arguments:_a];
 
50
  }
 
51
  if ([_plist isKindOfClass:[NSArray class]]) {
 
52
    return [self initWithArray:_plist
 
53
                 group:_group types:_types arguments:_a];
 
54
  }
 
55
 
 
56
  [self logWithFormat:@"ERROR: unexpected property list type: %@",
 
57
          [_plist class]];
 
58
  [self release];
 
59
  return nil;
 
60
}
 
61
- (id)initWithPropertyList:(id)_plist {
 
62
  return [self initWithPropertyList:_plist group:nil types:nil arguments:nil];
 
63
}
 
64
 
 
65
- (id)initWithGroup:(NSString *)_group types:(NSArray *)_types
 
66
  arguments:(NSDictionary *)_a
 
67
{
 
68
  return [self initWithArray:nil 
 
69
               group:_group types:_types arguments:_a];
 
70
}
 
71
- (id)init {
 
72
  return [self initWithPropertyList:nil group:nil types:nil arguments:nil];
 
73
}
 
74
 
 
75
- (void)dealloc {
 
76
  [self->values release];
 
77
  [super dealloc];
 
78
}
 
79
 
 
80
/* accessors */
 
81
 
 
82
- (NSArray *)values {
 
83
  return self->values;
 
84
}
 
85
 
 
86
/* values */
 
87
 
 
88
- (NSString *)stringValue {
 
89
  return [self vCardString];
 
90
}
 
91
 
 
92
- (NSString *)xmlString {
 
93
  return [[self stringValue] stringByEscapingXMLString];
 
94
}
 
95
 
 
96
- (NSString *)vCardString {
 
97
  return [[self values] componentsJoinedByString:@","];
 
98
}
 
99
 
 
100
- (id)propertyList {
 
101
  return [self values];
 
102
}
 
103
 
 
104
- (NSArray *)asArray {
 
105
  return self->values;
 
106
}
 
107
 
 
108
/* fake being an array */
 
109
 
 
110
- (id)objectAtIndex:(unsigned)_idx {
 
111
  return [self->values objectAtIndex:_idx];
 
112
}
 
113
- (unsigned)count {
 
114
  return [self->values count];
 
115
}
 
116
 
 
117
/* fake being a string */
 
118
 
 
119
- (unichar)characterAtIndex:(unsigned)_idx {
 
120
  return [[self stringValue] characterAtIndex:_idx];
 
121
}
 
122
- (unsigned)length {
 
123
  return [[self stringValue] length];
 
124
}
 
125
 
 
126
/* NSCoding */
 
127
 
 
128
- (void)encodeWithCoder:(NSCoder *)_coder {
 
129
  [super encodeWithCoder:_coder];
 
130
  [_coder encodeObject:self->values];
 
131
}
 
132
- (id)initWithCoder:(NSCoder *)_coder {
 
133
  if ((self = [super initWithCoder:_coder]) != nil) {
 
134
    self->values = [[_coder decodeObject] copy];
 
135
  }
 
136
  return self;
 
137
}
 
138
 
 
139
/* description */
 
140
 
 
141
- (void)appendAttributesToDescription:(NSMutableString *)_ms {
 
142
  [super appendAttributesToDescription:_ms];
 
143
  [_ms appendFormat:@" vcard=%@", [self vCardString]];
 
144
}
 
145
 
 
146
@end /* NGVCardStrArrayValue */