diff --git a/Headers/gnustep/base/String.h b/Headers/gnustep/base/String.h deleted file mode 100644 index 17d381051..000000000 --- a/Headers/gnustep/base/String.h +++ /dev/null @@ -1,176 +0,0 @@ -/* Some preliminary ideas about what a String class might look like. - Copyright (C) 1993,1994, 1995, 1996 Free Software Foundation, Inc. - - Written by: Andrew Kachites McCallum - Date: May 1993 - - This file is part of the GNUstep Base Library. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -*/ - -#ifndef __String_h_GNUSTEP_BASE_INCLUDE -#define __String_h_GNUSTEP_BASE_INCLUDE - -/* xxx These method names need to be fixed because we will get - type conflicts with GNUSTEP. - I will do the work to merge NSString and GNU String in the same - manner as NSArray and GNU Array. */ - -#include -#include -#include -//#include -#include - -typedef unsigned short Character; - -@class String; -@class ConstantString; -@class MutableString; - -/* Like in SmallTalk, the String class is a subclass of Collection---a - collection of characters. So, all the collection methods are - available. Nice. */ - -/* Think about changing these names to avoid conflicts with OpenStep? */ - -@protocol String - -// INITIALIZING NEWLY ALLOCATED STRINGS. DON'T FORGET TO RELEASE THEM!; -- init; -- initWithString: (id )aString; -- initWithString: (id )aString range: (IndexRange)aRange; -- initWithFormat: (id )aFormatString, ...; -- initWithFormat: (id )aFormatString arguments: (va_list)arg; -- initWithCString: (const char*)aCharPtr; -- initWithCString: (const char*)aCharPtr range: (IndexRange)aRange; -//- initWithStream: (Stream*)aStream; -//- initWithStream: (Stream*)aStream length: (unsigned)aLength; - -// GETTING NEW, AUTORELEASED STRING OBJECTS, NO NEED TO RELEASE THESE; -+ stringWithString: (id )aString; -+ stringWithString: (id )aString range: (IndexRange)aRange; -+ stringWithFormat: (id )aFormatString, ...; -+ stringWithFormat: (id )aFormatString arguments: (va_list)arg; -+ stringWithCString: (const char*)aCharPtr; -+ stringWithCString: (const char*)aCharPtr range: (IndexRange)aRange; -+ stringWithCStringNoCopy: (const char*)aCharPtr - freeWhenDone: (BOOL) f; -+ stringWithCStringNoCopy: (const char*)aCharPtr; - -- stringByAppendingFormat: (id )aString, ...; -- stringByAppendingFormat: (id )aString arguments: (va_list)arg; -- stringByPrependingFormat: (id )aString, ...; -- stringByPrependingFormat: (id )aString arguments: (va_list)arg; -- stringByAppendingString: (id )aString; -- stringByPrependingString: (id )aString; - -//- substringWithRange: (IndexRange)aRange; -//- substringWithLength: (unsigned)l; -//- substringAfterIndex: (unsigned)i; -//- (id ) substringsSeparatedByString: (id )sep; - -//- capitalizedString; -//- lowercaseString; -//- uppercaseString; - -- mutableCopy; -- copy; - -// QUERYING -- (unsigned) length; -- (IndexRange) range; -- (BOOL) isEqual: anObject; -- (unsigned) hash; -- (int) compare: anObject; -- copy; -- (unsigned) indexOfString: (id )aString; -- (unsigned) indexOfChar: (char)aChar; -- (unsigned) indexOfLastChar: (char)aChar; -//- (unsigned) indexOfCharacter: (Character)aChar; -//- (unsigned) indexOfLastCharacter: (Character)aChar; - -// GETTING C CHARS; -- (char) charAtIndex: (unsigned)index; -- (const char *) cString; -- (const char *) cStringNoCopy; -- (unsigned) cStringLength; -- (void) getCString: (char*)buffer; -- (void) getCString: (char*)buffer range: (IndexRange)aRange; - -// FOR FILE NAMES (don't use the name "path", gnu will not use it for this); -//- (IndexRange) fileRange; -//- (IndexRange) directoriesRange; -//- (IndexRange) extensionRange; -//- (IndexRange) fileWithoutExtensionRange; -//- (BOOL) isAbsolute; -//- (BOOL) isRelative; - -@end - -@protocol MutableString - -+ stringWithCapacity: (unsigned)capacity; -- initWithCapacity: (unsigned)capacity; - -/* This from IndexedCollecting: - removeRange: (IndexRange)range; */ -- (void) insertString: (id )string atIndex: (unsigned)index; - -- (void) setString: (id )string; -- (void) appendString: (id )string; -- (void) replaceRange: (IndexRange)range withString: (id )string; - -@end - -/* Abstract string classes */ - -@interface String : IndexedCollection -@end - -/* To prevent complaints about protocol conformance. */ -@interface String (StringProtocol) -@end - -@interface MutableString : String -@end - -/* To prevent complaints about protocol conformance. */ -@interface MutableString (MutableStringProtocol) -@end - -/* Some concrete string classes */ - -@interface CString : String -{ - char * _contents_chars; - int _count; - BOOL _free_contents; -} -@end - -@interface MutableCString : MutableString -{ - char *_contents_chars; - int _count; - BOOL _free_contents; - int _capacity; -} -@end - -@interface ConstantString : CString -@end - -#endif /* __String_h_GNUSTEP_BASE_INCLUDE */ diff --git a/Source/CString.m b/Source/CString.m deleted file mode 100644 index b62c7d554..000000000 --- a/Source/CString.m +++ /dev/null @@ -1,126 +0,0 @@ -/* Implementation for GNU Objective-C CString object - Copyright (C) 1993,1994, 1995, 1996 Free Software Foundation, Inc. - - Written by: Andrew Kachites McCallum - Date: July 1994 - - This file is part of the GNUstep Base Library. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -*/ - -#include -#include -#include -#include -/* memcpy(), strlen(), strcmp() are gcc builtin's */ - -@implementation CString - -/* These next two methods are the two designated initializers for this class */ -- initWithCString: (const char*)aCharPtr range: (IndexRange)aRange -{ - _count = aRange.length; - OBJC_MALLOC(_contents_chars, char, _count+1); - memcpy(_contents_chars, aCharPtr + aRange.location, _count); - _contents_chars[_count] = '\0'; - _free_contents = YES; - return self; -} - -- initWithCStringNoCopy: (const char*)aCharPtr freeWhenDone: (BOOL)f -{ - _count = strlen(aCharPtr); - _contents_chars = (char *) aCharPtr; - _free_contents = f; - return self; -} - -- (void) _collectionReleaseContents -{ -} - -- (void) _collectionDealloc -{ - if (_free_contents) - OBJC_FREE(_contents_chars); -} - -- (Class) classForConnectedCoder: aRmc -{ - /* Make sure that Connection's always send us bycopy, - i.e. as our own class, not a Proxy class. */ - return [self class]; -} - -- (void) encodeWithCoder: aCoder -{ - [aCoder encodeValueOfObjCType: @encode(char*) - at: &_contents_chars - withName: @"Concrete String content_chars"]; -} - -- initWithCoder: aCoder -{ - [super initWithCoder:aCoder]; - [aCoder decodeValueOfObjCType: @encode(char*) - at: &_contents_chars - withName: NULL]; - _count = strlen(_contents_chars); - _free_contents = YES; - return self; -} - -/* Empty copy must empty an allocCopy'ed version of self */ -- emptyCopy -{ - CString *copy = [super emptyCopy]; - OBJC_MALLOC(copy->_contents_chars, char, _count+1); - copy->_count = 0; - copy->_contents_chars[0] = '\0'; - return copy; -} - -/* xxx This should return an autoreleased, malloc'ed copy */ -- (const char *) cString -{ - return _contents_chars; -} - -- (const char *) cStringNoCopy -{ - return _contents_chars; -} - -- (unsigned) count -{ - return _count; -} - -- (char) charAtIndex: (unsigned)index -{ - CHECK_INDEX_RANGE_ERROR(index, _count); - return _contents_chars[index]; -} - -// FOR IndexedCollection SUPPORT; - -- objectAtIndex: (unsigned)index -{ - CHECK_INDEX_RANGE_ERROR(index, _count); - return [NSNumber numberWithChar: _contents_chars[index]]; -} - -@end diff --git a/Source/MutableCString.m b/Source/MutableCString.m deleted file mode 100644 index 8308324db..000000000 --- a/Source/MutableCString.m +++ /dev/null @@ -1,205 +0,0 @@ -/* Implementation for GNU Objective-C MutableCString object - Copyright (C) 1995, 1996 Free Software Foundation, Inc. - - Written by: Andrew Kachites McCallum - Created: January 1995 - - This file is part of the GNUstep Base Library. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -*/ - -#include -#include -#include -/* memcpy(), strlen(), strcmp() are gcc builtin's */ - -typedef struct { - @defs(MutableCString) -} MutableCStringStruct; - -static inline void -stringIncrementCountAndMakeHoleAt(MutableCStringStruct *self, - unsigned index, unsigned size) -{ -#ifndef STABLE_MEMCPY - { - int i; - for (i = self->_count; i >= index; i--) - self->_contents_chars[i+size] = self->_contents_chars[i]; - } -#else - memcpy(self->_contents_chars + index, - self->_contents_chars + index + size, - self->_count - index); -#endif /* STABLE_MEMCPY */ - (self->_count) += size; -} - -static inline void -stringDecrementCountAndFillHoleAt(MutableCStringStruct *self, - unsigned index, unsigned size) -{ - (self->_count) -= size; -#ifndef STABLE_MEMCPY - { - int i; - for (i = index; i <= self->_count; i++) - self->_contents_chars[i] = self->_contents_chars[i+size]; - } -#else - memcpy(self->_contents_chars + index + size, - self->_contents_chars + index, - self->_count - index); -#endif /* STABLE_MEMCPY */ -} - -@implementation MutableCString - -/* This is the designated initializer for this class */ -- initWithCapacity: (unsigned)capacity -{ - _count = 0; - _capacity = capacity; - OBJC_MALLOC(_contents_chars, char, _capacity+1); - _contents_chars[0] = '\0'; - _free_contents = YES; - return self; -} - -- (void) dealloc -{ - if (_free_contents) - OBJC_FREE(_contents_chars); - [super dealloc]; -} - -/* xxx This should be made to return void, but we need to change - IndexedCollecting and its conformers */ -- (void) removeRange: (IndexRange)range -{ - stringDecrementCountAndFillHoleAt((MutableCStringStruct*)self, - range.location, range.length); -} - -- (void) insertString: (String*)string atIndex: (unsigned)index -{ - unsigned c = [string count]; - if (_count + c >= _capacity) - { - _capacity = MAX(_capacity*2, _count+c); - OBJC_REALLOC(_contents_chars, char, _capacity); - } - stringIncrementCountAndMakeHoleAt((MutableCStringStruct*)self, index, c); - memcpy(_contents_chars + index, [string cString], c); - _contents_chars[_count] = '\0'; -} - - -- (Class) classForConnectedCoder: aRmc -{ - /* Make sure that Connection's always send us bycopy, - i.e. as our own class, not a Proxy class. */ - return [self class]; -} - -- (void) encodeWithCoder: aCoder -{ - [aCoder encodeValueOfObjCType:@encode(unsigned) at:&_capacity - withName:@"String capacity"]; - [aCoder encodeValueOfObjCType:@encode(char*) at:&_contents_chars - withName:@"String content_chars"]; -} - -- initWithCoder: aCoder -{ - unsigned cap; - - [aCoder decodeValueOfObjCType:@encode(unsigned) at:&cap withName:NULL]; - [self initWithCapacity:cap]; - [aCoder decodeValueOfObjCType:@encode(char*) at:_contents_chars - withName:NULL]; - _count = strlen(_contents_chars); - _capacity = cap; - _free_contents = YES; - return self; -} - -/* Empty copy must empty an allocCopy'ed version of self */ -- emptyCopy -{ - MutableCString *copy = [super emptyCopy]; - OBJC_MALLOC(copy->_contents_chars, char, _count+1); - copy->_count = 0; - copy->_contents_chars[0] = '\0'; - return copy; -} - -- (const char *) cString -{ - return _contents_chars; -} - -- (unsigned) count -{ - return _count; -} - -- (char) charAtIndex: (unsigned)index -{ - CHECK_INDEX_RANGE_ERROR(index, _count); - return _contents_chars[index]; -} - -#if 0 -/* For IndexedCollecting protocol */ - -- insertElement: (elt)newElement atIndex: (unsigned)index -{ - CHECK_INDEX_RANGE_ERROR(index, _count+1); - // one for the next char, one for the '\0'; - if (_count+1 >= _capacity) - { - _capacity *= 2; - OBJC_REALLOC(_contents_chars, char, _capacity); - } - stringIncrementCountAndMakeHoleAt((MutableCStringStruct*)self, index, 1); - _contents_chars[index] = newElement.char_u; - _contents_chars[_count] = '\0'; - return self; -} - -- (elt) removeElementAtIndex: (unsigned)index -{ - elt ret; - - CHECK_INDEX_RANGE_ERROR(index, _count); - ret = _contents_chars[index]; - stringDecrementCountAndFillHoleAt((MutableCStringStruct*)self, index, 1); - _contents_chars[_count] = '\0'; - return ret; -} - -- (elt) elementAtIndex: (unsigned)index -{ - elt ret_elt; - CHECK_INDEX_RANGE_ERROR(index, _count); - ret_elt.char_u = _contents_chars[index]; - return ret_elt; -} - -#endif - -@end diff --git a/Source/MutableString.m b/Source/MutableString.m deleted file mode 100644 index 524961b66..000000000 --- a/Source/MutableString.m +++ /dev/null @@ -1,99 +0,0 @@ -/* Implementation for GNU Objective-C MutableString object - Copyright (C) 1993,1994, 1996 Free Software Foundation, Inc. - - Written by: Andrew Kachites McCallum - Date: July 1994 - - This file is part of the GNUstep Base Library. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -*/ - -#include -#include -#include -/* memcpy(), strlen(), strcmp() are gcc builtin's */ -#include - -@implementation MutableString - -/* This is the designated initializer */ -- initWithCapacity: (unsigned)capacity -{ - return [self subclassResponsibility:_cmd]; -} - -+ (MutableString*) stringWithCapacity: (unsigned)capacity -{ - MutableCString *n = [[MutableCString alloc] initWithCapacity:capacity]; - return [n autorelease]; -} - -/* Subclasses need to implemented the next two methods */ - -- (void) removeRange: (IndexRange)range -{ - [self subclassResponsibility:_cmd]; -} - -- (void) insertString: (String*)string atIndex: (unsigned)index -{ - [self subclassResponsibility:_cmd]; -} - -- (void) setString: (String*)string -{ - [self replaceRange:(IndexRange){0,INT_MAX} withString:string]; -} - -- (void) appendString: (String*)string -{ - [self insertString:string atIndex:[self count]]; -} - -- (void) replaceRange: (IndexRange)range withString: (String*)string -{ - [self removeRange:range]; - [self insertString:string atIndex:range.location]; -} - -// SETTING VALUES; - -- (void) setIntValue: (int)anInt -{ - [self setString:[String stringWithFormat:@"%d", anInt]]; -} - -- (void) setFloatValue: (float)aFloat -{ - [self setString:[String stringWithFormat:@"%f", aFloat]]; -} - -- (void) setDoubleValue: (double)aDouble -{ - [self setString:[String stringWithFormat:@"%f", aDouble]]; -} - -- (void) setCStringValue: (const char *)aCString -{ - [self setString:[String stringWithCString:aCString]]; -} - -- (void) setStringValue: (String*)aString -{ - [self setString:aString]; -} - -@end diff --git a/Source/String.m b/Source/String.m deleted file mode 100644 index 4efab848c..000000000 --- a/Source/String.m +++ /dev/null @@ -1,463 +0,0 @@ -/* Implementation for Objective-C String object - Copyright (C) 1993,1994,1995, 1996 Free Software Foundation, Inc. - - Written by: Andrew Kachites McCallum - Date: May 1993 - - This file is part of the GNUstep Base Library. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -*/ - -#include -#include -/* memcpy(), strlen(), strcmp() are gcc builtin's */ -#include -#include - -/* Deal with strchr: */ -#if STDC_HEADERS || HAVE_STRING_H -#include -/* An ANSI string.h and pre-ANSI memory.h might conflict. */ -#if !STDC_HEADERS && HAVE_MEMORY_H -#include -#endif /* not STDC_HEADERS and HAVE_MEMORY_H */ -#define rindex strrchr -#define bcopy(s, d, n) memcpy ((d), (s), (n)) -#define bcmp(s1, s2, n) memcmp ((s1), (s2), (n)) -#define bzero(s, n) memset ((s), 0, (n)) -#else /* not STDC_HEADERS and not HAVE_STRING_H */ -#include -/* memory.h and strings.h conflict on some systems. */ -#endif /* not STDC_HEADERS and not HAVE_STRING_H */ - - -@implementation String - -+ (void) initialize -{ - if (self == [String class]) - { - [self setVersion:0]; /* beta release */ - /* xxx eventually: class_add_behavior_category(NSStringStuff), - but we'll have to be careful about these methods overriding - the ones inherited in NSCString from NSString! */ - } -} - -// INITIALIZING; - -/* For now, this is the designated initializer for this class */ -- initWithCString: (const char*)aCharPtr range: (IndexRange)aRange -{ - [self subclassResponsibility:_cmd]; - return self; -} - -/* xxx This is a second "designated" initializer. */ -- initWithCStringNoCopy: (const char*) aCharPtr - freeWhenDone: (BOOL) f -{ - [self subclassResponsibility:_cmd]; - return self; -} - -/* This override in mutable string classes */ -- (void) empty -{ - [self subclassResponsibility:_cmd]; -} - -- initWithCString: (const char*)aCharPtr length: (unsigned)aLength -{ - return [self initWithCString:aCharPtr - range:((IndexRange){0,aLength})]; -} - -- initWithCString: (const char*)aCharPtr -{ - return [self initWithCString:aCharPtr - range:((IndexRange){0, strlen(aCharPtr)})]; -} - -#if HAVE_VSPRINTF -- initWithFormat: (id )aFormatString arguments: (va_list)arg -{ - char buf[128]; /* xxx horrible, disgusting, fix this */ - int len; - len = VSPRINTF_LENGTH (vsprintf(buf, [aFormatString cString], arg)); - assert (len < 128); - return [self initWithCString:buf]; -} - -- initWithCFormat: (const char*)formatCharPtr arguments: (va_list)arg -{ - char buf[128]; /* xxx horrible, disgusting, fix this */ - int len; - len = VSPRINTF_LENGTH (vsprintf(buf, formatCharPtr, arg)); - assert (len < 128); - return [self initWithCString:buf]; -} -#endif /* HAVE_VSPRINTF */ - -- initWithFormat: (id )aFormatString, ... -{ - va_list ap; - va_start(ap, aFormatString); - [self initWithCFormat:[aFormatString cString] arguments:ap]; - va_end(ap); - return self; -} - -- initWithCFormat: (const char*)formatCharPtr, ... -{ - va_list ap; - va_start(ap, formatCharPtr); - [self initWithCFormat:formatCharPtr arguments:ap]; - va_end(ap); - return self; -} - -- init -{ - return [self initWithCString:""]; -} - -- initWithString: (id )aString range: (IndexRange)aRange -{ - return [self initWithCString:[aString cString] range:aRange]; -} - -- initWithString: (id )aString length: (unsigned)aLength -{ - return [self initWithCString:[aString cString]]; -} - -- initWithString: (id )aString -{ - return [self initWithCString:[aString cString]]; -} - - -// GETTING NEW, AUTORELEASED STRING OBJECTS, NO NEED TO RELEASE THESE; - -+ stringWithString: (id )aString range: (IndexRange)aRange -{ - return [[[CString alloc] initWithString:aString range:aRange] - autorelease]; -} - -+ stringWithString: (id )aString -{ - return [[[CString alloc] initWithString:aString] - autorelease]; -} - -+ stringWithFormat: (id )aFormatString, ... -{ - va_list ap; - id ret; - - va_start(ap, aFormatString); - ret = [[self stringWithFormat:aFormatString arguments:ap] - autorelease]; - va_end(ap); - return ret; -} - -+ stringWithFormat: (id )aFormatString arguments: (va_list)arg -{ - return [[[CString alloc] initWithFormat:aFormatString arguments:arg] - autorelease]; -} - -+ stringWithCString: (const char*)cp range: (IndexRange)r -{ - return [[[CString alloc] initWithCString:cp range:r] - autorelease]; -} - -+ stringWithCString: (const char*)aCharPtr -{ - return [[[CString alloc] initWithCString:aCharPtr] - autorelease]; -} - -+ stringWithCStringNoCopy: (const char*)aCharPtr - freeWhenDone: (BOOL) f -{ - return [[[CString alloc] - initWithCStringNoCopy:aCharPtr - freeWhenDone: f] - autorelease]; -} - -+ stringWithCStringNoCopy: (const char*)aCharPtr -{ - return [self stringWithCStringNoCopy:aCharPtr - freeWhenDone: YES]; -} - -- stringByAppendingFormat: (id )aString, ... -{ - [self notImplemented:_cmd]; - return nil; -} - -- stringByAppendingFormat: (id )aString arguments: (va_list)arg -{ - [self notImplemented:_cmd]; - return nil; -} - -- stringByPrependingFormat: (id )aString, ... -{ - [self notImplemented:_cmd]; - return nil; -} - -- stringByPrependingFormat: (id )aString arguments: (va_list)arg -{ - [self notImplemented:_cmd]; - return nil; -} - -- stringByAppendingString: (id )aString -{ - [self notImplemented:_cmd]; - return nil; -} - -- stringByPrependingString: (id )aString -{ - [self notImplemented:_cmd]; - return nil; -} - - -// COPYING; - -/* This is the designated copier */ -- (char *) cStringCopyRange: (IndexRange)aRange; -{ - [self subclassResponsibility:_cmd]; - return ""; -} - -- (char *) cStringCopyLength: (unsigned)aLength -{ - // xxx need to check aLength against _count; - return [self cStringCopyRange:((IndexRange){0,aLength})]; -} - -/* xxx No longer necessary because -cString does the same thing? */ -- (char *) cStringCopy -{ - return [self cStringCopyRange:((IndexRange){0, [self count]})]; -} - -- copyWithZone: (NSZone*)z -{ - return [[[self class] allocWithZone:z] initWithString:(NSString*)self]; -} - -- mutableCopyWithZone: (NSZone*)z -{ - return [[MutableCString allocWithZone:z] initWithString:(NSString*)self]; -} - -// TESTING; - -- (unsigned) hash -{ - unsigned ret = 0; - unsigned ctr = 0; - unsigned char_count = 0; - const char *s = [self cStringNoCopy]; - - while (*s && char_count++ < NSHashStringLength) - { - ret ^= *s++ << ctr; - ctr = (ctr + 1) % sizeof (void*); - } - return ret; -} - -- (int) compare: anObject -{ - if ([anObject isKindOfClass:[String class]]) - return strcmp([self cString], [anObject cString]); - return [super compare:anObject]; -} - -- (BOOL) isEqual: anObject -{ - if (self == anObject) - return YES; - if (! [anObject isKindOf:[String class]] - || [self count] != [anObject count] - || [anObject hash] != [self hash] ) - return NO; - return ! [self compare:anObject]; -} - -- (unsigned) count -{ - /* Should be overridden for efficiency. */ - return strlen([self cString]); -} - -- (unsigned) length -{ - return [self count]; -} - -- (IndexRange) stringRange -{ - IndexRange r = {0, [self count]}; - return r; -} - -/* xxx These next three need error checking to handle the case in which - we're looking for never appears */ - -- (unsigned) indexOfChar: (char)aChar -{ - const char *s = [self cString]; - return (strchr(s, aChar) - s); -} - -- (unsigned) indexOfLastChar: (char)aChar -{ - const char *s = [self cString]; - return (strrchr(s, aChar) - s); -} - -- (unsigned) indexOfString: (id )aString -{ - const char *s = [self cString]; - return (strstr(s, [aString cString]) - s); -} - -- (char) charAtIndex: (unsigned)index -{ - [self subclassResponsibility:_cmd]; - return ' '; -} - -- (const char *) cString -{ - [self subclassResponsibility:_cmd]; - return NULL; -} - -- (const char *) cStringNoCopy -{ - [self subclassResponsibility:_cmd]; - return NULL; -} - -- (unsigned) cStringLength -{ - [self subclassResponsibility:_cmd]; - return 0; -} - -- (void) getCString: (char*)buffer -{ - strcpy(buffer, [self cString]); -} - -- (void) getCString: (char*)buffer range: (IndexRange)aRange -{ - memcpy(buffer, ([self cString] + aRange.location), aRange.length); -} - -- (IndexRange) range -{ - return (IndexRange){0, [self count]}; -} - -// GETTING VALUES; - -- (int) intValue -{ - return atoi([self cString]); -} - -- (float) floatValue -{ - return (float) atof([self cString]); -} - -- (double) doubleValue -{ - return atof([self cString]); -} - -- (const char *) cStringValue -{ - return [self cString]; -} - -- (String *) stringValue -{ - return self; -} - -// FOR FILE AND PATH NAMES; - -- (IndexRange) fileRange -{ - IndexRange r; - [self notImplemented:_cmd]; - return r; -} - -- (IndexRange) pathRange -{ - IndexRange r; - [self notImplemented:_cmd]; - return r; -} - -- (IndexRange) extensionRange -{ - IndexRange r; - [self notImplemented:_cmd]; - return r; -} - -- (IndexRange) fileWithOutExtentionRange -{ - IndexRange r; - [self notImplemented:_cmd]; - return r; -} - -- (BOOL) isAbsolute -{ - [self notImplemented:_cmd]; - return NO; -} - -- (BOOL) isRelative -{ - [self notImplemented:_cmd]; - return NO; -} - - -@end