Index: src/Makefile ================================================================== --- src/Makefile +++ src/Makefile @@ -1,19 +1,21 @@ LIB = ${LIB_PREFIX}objfw${LIB_SUFFIX} LIB_MAJOR = 1 LIB_MINOR = 0 -SRCS = OFList.m \ +SRCS = OFConstString.m \ + OFList.m \ OFListObject.m \ OFObject.m \ OFString.m OBJCFLAGS += -fPIC -DPIC -fno-nil-recivers -fconstant-string-class=OFConstString -INCLUDES = OFList.h \ +INCLUDES = OFConstString.h \ + OFList.h \ OFListObject.h \ OFObject.h \ OFString.h include ../buildsys.mk LD = ${OBJC} LIBS += -lobjc ADDED src/OFConstString.h Index: src/OFConstString.h ================================================================== --- src/OFConstString.h +++ src/OFConstString.h @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2008 + * Jonathan Schleifer + * + * 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 +#import "OFObject.h" + +@interface OFConstString: OFObject +{ + const char *string; + size_t length; +} + ++ new:(const char*)str; +- init; +- init:(const char*)str; +- (const char*)cString; +- (size_t)length; +@end + +/* vim: se syn=objc: */ ADDED src/OFConstString.m Index: src/OFConstString.m ================================================================== --- src/OFConstString.m +++ src/OFConstString.m @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2008 + * Jonathan Schleifer + * + * 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 +#import +#import "OFConstString.h" + +@implementation OFConstString ++ new:(const char*)str +{ + return [[OFConstString alloc] init:str]; +} + +- init +{ + return [self init:NULL]; +} + +- init:(const char*)str +{ + if ((self = [super init])) { + if (str == NULL) { + length = 0; + string = NULL; + } else { + length = strlen(string); + string = str; + } + } + return self; +} + +- (const char*)cString +{ + return string; +} + +- (size_t)length +{ + return length; +} +@end Index: src/OFString.m ================================================================== --- src/OFString.m +++ src/OFString.m @@ -11,12 +11,10 @@ #import #import #import "OFString.h" -/* TODO: Use getMem / resizeMem */ - @implementation OFString + new:(const char*)str { return [[OFString alloc] init:str]; }