ObjFW  Artifact [59a339f3e5]

Artifact 59a339f3e513b9fbdfe147af11a2b18c82821de19a634200f8d2a35b66953a3c:


/*
 * 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 <string.h>
#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(str);
			string = str;
		}
	}
	return self;
}

- (const char*)cString
{
	return string;
}

- (size_t)length
{
	return length;
}

- (int)compare: (OFConstString*)str
{
	return strcmp(string, [str cString]);
}
@end