Artifact dc3a9e9583f85971809326ae924dfa0fbee830d0204177b232c144384ec1e0f1:
- File
src/OFCString.m
— part of check-in
[e47ad44290]
at
2008-10-22 13:32:19
on branch trunk
— Reworked OFObject and added append(Wide)CString to OFString.
The reworked OFObject lets one test fail on the GNU runtime.
Unfortunately, I have no idea why... (user: js, size: 1385) [annotate] [blame] [check-ins using]
/* * Copyright (c) 2008 * Jonathan Schleifer <js@webkeks.org> * * All rights reserved. * * This file is part of libobjfw. It may be distributed under the terms of the * Q Public License 1.0, which can be found in the file LICENSE included in * the packaging of this file. */ #import "config.h" #import <stdlib.h> #import <string.h> #import "OFCString.h" #import "OFExceptions.h" @implementation OFCString - initWithCString: (char*)str { if ((self = [super init])) { if (str == NULL) { length = 0; string = NULL; } else { length = strlen(str); string = [self getMemWithSize: length + 1]; memcpy(string, str, length + 1); } } return self; } - (char*)cString { return string; } - (size_t)length { return length; } - (OFString*)clone { return [OFString newWithCString: string]; } - (int)compareTo: (OFString*)str { return strcmp(string, [str cString]); } - (OFString*)append: (OFString*)str { return [self appendCString: [str cString]]; } - (OFString*)appendCString: (const char*)str { char *newstr; size_t newlen, strlength; if (string == NULL) return [self setTo: [OFString newWithCString: (char*)str]]; strlength = strlen(str); newlen = length + strlength; newstr = [self resizeMem: string toSize: newlen + 1]; memcpy(newstr + length, str, strlength + 1); length = newlen; string = newstr; return self; } @end