
// Fri Oct 23 02:58:47 MET DST 1998 	dave@turbocat.de
// cStringNoCopy -> cString

/* For demo of Strings as Collections of char's. */
#include <Foundation/NSString.h>
#include <Foundation/NSAutoreleasePool.h>
#include <Foundation/NSString.h>

void
print_string(NSString* s)
{
	printf("string: [%s], length %d\n", [s cString], [s length]);
}

int main()
{
NSAutoreleasePool *arp = [NSAutoreleasePool new];
id s = @"This is a test string";
id s2, s3;
NSString *a = @"/usr/src";
NSString *b = @"/usr/src/";
NSString *p = @"/mySTEP";
NSString *m = @"mySTEP";

NSString *c = @".tar";
NSString *d = @"tar";

	print_string(s);
	
	s2 = [s copy];
	print_string(s2);
	s3 = [s2 mutableCopy];
	[s2 release];
	s2 = [s3 copy];
	[s3 release];
	[s2 release];
	
	s2 = [s copy];
	print_string(s2);
	
	s2 = [s stringByAppendingString:@" with something added"];
	print_string(s2);
	
	s2 = [s mutableCopy];
	[s2 replaceCharactersInRange:((NSRange){10,4})
		withString:@"changed"];
	print_string(s2);
	
	/* Test the use of the `%@' format directive. */
	s2 = [NSString stringWithFormat: @"foo %@ bar", @"test"];
	print_string(s2);
	
	print_string([a stringByAppendingPathComponent: p]);
	print_string([a stringByAppendingPathComponent: m]);
	print_string([b stringByAppendingPathComponent: p]);
	print_string([b stringByAppendingPathComponent: m]);

	print_string([m stringByAppendingPathExtension: c]);
	print_string(a = [m stringByAppendingPathExtension: d]);
	print_string(a = [a stringByAppendingPathExtension: @"gz"]);
	print_string([a stringByDeletingPathExtension]);

	[arp release];
	printf("string test complete\n");
	exit(0);
}
