2 Copyright (C) 2000-2005 SKYRIX Software AG
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 "NSString+ICal.h"
26 @implementation NSString(ICalCString)
28 - (const char *)icalCString {
31 enc = [[self class] libicalStringEncoding];
33 if (enc == NSUTF8StringEncoding)
34 return [self UTF8String];
35 else if (enc == [NSString defaultCStringEncoding])
36 return [self cString];
38 return [[self dataUsingEncoding:enc] bytes];
41 - (NSString *)icalString {
45 @end /* NSString(ICalCString) */
47 @implementation NSObject(TemporaryStringInit)
49 + (NSStringEncoding)libicalStringEncoding {
50 return NSUTF8StringEncoding;
53 - (id)initWithICalCString:(const char *)_cstr {
61 enc = [[self class] libicalStringEncoding];
63 if (enc == NSUTF8StringEncoding)
64 return [(NSString *)self initWithUTF8String:_cstr];
65 else if (enc == [[self class] defaultCStringEncoding])
66 return [(NSString *)self initWithCString:_cstr];
70 d = [[NSData alloc] initWithBytes:_cstr length:strlen(_cstr)];
71 self = [(NSString *)self initWithData:d encoding:enc];
80 - (id)initWithICalValueHandle:(icalvalue *)_handle {
83 if (_handle == NULL) {
87 if ((s = icalvalue_as_ical_string(_handle)) == NULL) {
91 return [self initWithICalCString:s];
94 - (id)initWithICalValueOfProperty:(icalproperty *)_prop {
102 if ((val = icalproperty_get_value(_prop)) == NULL) {
103 NSLog(@"%s: ical property has no value ??", __PRETTY_FUNCTION__);
108 return [self initWithICalValueHandle:val];
111 @end /* NSObject(TemporaryStringInit) */