Standardize and update all copyright statements to name "ZXing authors" as suggested...
[zxing.git] / iphone / Classes / AddressBookDoCoMoParsedResult.m
1 //
2 //  AddressBookDoCoMoParsedResult.m
3 //  ZXing
4 //
5 //  Created by Christian Brunschen on 29/05/2008.
6 /*
7  * Copyright 2008 ZXing authors
8  *
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  */
21
22 #import "AddressBookDoCoMoParsedResult.h"
23 #import "AddContactAction.h"
24
25 @implementation AddressBookDoCoMoParsedResult
26
27 @synthesize name;
28 @synthesize phoneNumbers;
29 @synthesize note;
30 @synthesize email;
31 @synthesize urlString;
32 @synthesize address;
33
34 + parsedResultForString:(NSString *)s {
35   NSRange foundRange = [s rangeOfString:@"MECARD:"];
36   if (foundRange.location == NSNotFound) {
37     return nil;
38   }
39   
40   NSString *name = [s fieldWithPrefix:@"N:"];
41   if (name == nil) {
42     return nil;
43   }
44   
45   AddressBookDoCoMoParsedResult *result = [[self alloc] init];
46   result.name = name;
47   result.phoneNumbers = [s fieldsWithPrefix:@"TEL:"];
48   result.email = [s fieldWithPrefix:@"EMAIL:"];
49   result.note = [s fieldWithPrefix:@"NOTE:"];
50   result.urlString = [s fieldWithPrefix:@"URL:"];
51   result.address = [s fieldWithPrefix:@"ADR:"];
52   
53   return [result autorelease];
54 }
55
56 - (NSString *)stringForDisplay {
57   NSMutableString *result = [NSMutableString stringWithString:self.name];
58   if (self.phoneNumbers) {
59     for (NSString *number in self.phoneNumbers) {
60       [result appendFormat:@"\n%@", number];
61     }
62   }
63   
64   if (self.email) {
65     [result appendFormat:@"\n%@", self.email];
66   }
67   if (self.urlString) {
68     [result appendFormat:@"\n%@", self.urlString];
69   }
70   if (self.note) {
71     [result appendFormat:@"\n%@", self.note];
72   }
73   if (self.address) {
74     [result appendFormat:@"\n%@", self.address];
75   }
76   return [NSString stringWithString:result];
77 }
78
79 - (NSString *)typeName {
80   return @"DoCoMo MeCard";
81 }
82
83 - (void)populateActions {
84   [actions addObject:[AddContactAction actionWithName:self.name
85                                          phoneNumbers:self.phoneNumbers 
86                                                 email:self.email 
87                                                   url:self.urlString 
88                                               address:self.address 
89                                                  note:self.note]];
90 }
91
92 - (void) dealloc {
93   [name release];
94   [phoneNumbers release];
95   [email release];
96   [urlString release];
97   [address release];
98   [note release];
99   [super dealloc];
100 }
101
102 @end