2 Copyright (C) 2000-2003 SKYRIX Software AG
4 This file is part of OGo
6 OGo 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 OGo 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 OGo; see the file COPYING. If not, write to the
18 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
23 #include "NSString+ICal.h"
26 #import <libical/ical.h>
31 @implementation NSString(ICalCString)
33 - (const char *)icalCString {
36 enc = [[self class] libicalStringEncoding];
38 if (enc == NSUTF8StringEncoding)
39 return [self UTF8String];
40 else if (enc == [NSString defaultCStringEncoding])
41 return [self cString];
43 return [[self dataUsingEncoding:enc] bytes];
46 - (NSString *)icalString {
50 @end /* NSString(ICalCString) */
52 @implementation NSObject(TemporaryStringInit)
54 + (NSStringEncoding)libicalStringEncoding {
55 return NSUTF8StringEncoding;
58 - (id)initWithICalCString:(const char *)_cstr {
66 enc = [[self class] libicalStringEncoding];
68 if (enc == NSUTF8StringEncoding)
69 return [(NSString *)self initWithUTF8String:_cstr];
70 else if (enc == [[self class] defaultCStringEncoding])
71 return [(NSString *)self initWithCString:_cstr];
75 d = [[NSData alloc] initWithBytes:_cstr length:strlen(_cstr)];
76 self = [(NSString *)self initWithData:d encoding:enc];
85 - (id)initWithICalValueHandle:(icalvalue *)_handle {
88 if (_handle == NULL) {
92 if ((s = icalvalue_as_ical_string(_handle)) == NULL) {
96 return [self initWithICalCString:s];
99 - (id)initWithICalValueOfProperty:(icalproperty *)_prop {
107 if ((val = icalproperty_get_value(_prop)) == NULL) {
108 NSLog(@"%s: ical property has no value ??", __PRETTY_FUNCTION__);
113 return [self initWithICalValueHandle:val];
116 @end /* NSObject(TemporaryStringInit) */