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"
27 @implementation NSString(ICalCString)
29 - (const char *)icalCString {
32 enc = [[self class] libicalStringEncoding];
34 if (enc == NSUTF8StringEncoding)
35 return [self UTF8String];
36 else if (enc == [NSString defaultCStringEncoding])
37 return [self cString];
39 return [[self dataUsingEncoding:enc] bytes];
42 - (NSString *)icalString {
46 @end /* NSString(ICalCString) */
48 @implementation NSObject(TemporaryStringInit)
50 + (NSStringEncoding)libicalStringEncoding {
51 return NSUTF8StringEncoding;
54 - (id)initWithICalCString:(const char *)_cstr {
62 enc = [[self class] libicalStringEncoding];
64 if (enc == NSUTF8StringEncoding)
65 return [(NSString *)self initWithUTF8String:_cstr];
66 else if (enc == [[self class] defaultCStringEncoding])
67 return [(NSString *)self initWithCString:_cstr];
71 d = [[NSData alloc] initWithBytes:_cstr length:strlen(_cstr)];
72 self = [(NSString *)self initWithData:d encoding:enc];
81 - (id)initWithICalValueHandle:(icalvalue *)_handle {
84 if (_handle == NULL) {
88 if ((s = icalvalue_as_ical_string(_handle)) == NULL) {
92 return [self initWithICalCString:s];
95 - (id)initWithICalValueOfProperty:(icalproperty *)_prop {
103 if ((val = icalproperty_get_value(_prop)) == NULL) {
104 NSLog(@"%s: ical property has no value ??", __PRETTY_FUNCTION__);
109 return [self initWithICalValueHandle:val];
112 @end /* NSObject(TemporaryStringInit) */