1995-03-11 20:49:02 +00:00
|
|
|
/* Some preliminary ideas about what a String class might look like.
|
|
|
|
Copyright (C) 1993,1994 Free Software Foundation, Inc.
|
|
|
|
|
|
|
|
Written by: R. Andrew McCallum <mccallum@gnu.ai.mit.edu>
|
|
|
|
Date: May 1993
|
|
|
|
|
|
|
|
This file is part of the GNU Objective C Class 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_OBJECTS_INCLUDE
|
|
|
|
#define __String_h_OBJECTS_INCLUDE
|
|
|
|
|
|
|
|
#include <objects/objc-gnu2next.h>
|
|
|
|
#include <objects/IndexedCollection.h>
|
|
|
|
#include <objects/ValueHolding.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
|
|
|
|
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. */
|
|
|
|
|
1995-03-12 19:25:28 +00:00
|
|
|
@protocol String <ValueGetting>
|
1995-03-11 20:49:02 +00:00
|
|
|
|
|
|
|
// INITIALIZING NEWLY ALLOCATED STRINGS. DON'T FORGET TO RELEASE THEM!;
|
|
|
|
- init;
|
|
|
|
- initWithString: (String*)aString;
|
1995-03-12 19:25:28 +00:00
|
|
|
- initWithString: (String*)aString range: (IndexRange)aRange;
|
1995-03-11 20:49:02 +00:00
|
|
|
- initWithFormat: (String*)aFormatString, ...;
|
|
|
|
- initWithFormat: (String*)aFormatString arguments: (va_list)arg;
|
1995-03-12 15:45:31 +00:00
|
|
|
- initWithCString: (const char*)aCharPtr;
|
1995-03-12 19:25:28 +00:00
|
|
|
- initWithCString: (const char*)aCharPtr range: (IndexRange)aRange;
|
|
|
|
//- initWithStream: (Stream*)aStream;
|
|
|
|
//- initWithStream: (Stream*)aStream length: (unsigned)aLength;
|
1995-03-11 20:49:02 +00:00
|
|
|
|
|
|
|
// GETTING C CHARS;
|
|
|
|
- (char) charAtIndex: (unsigned)index;
|
|
|
|
- (const char *) cString;
|
|
|
|
- (unsigned) cStringLength;
|
|
|
|
- (void) getCString: (char*)buffer;
|
|
|
|
- (void) getCString: (char*)buffer range: (IndexRange)aRange;
|
|
|
|
|
|
|
|
// GETTING NEW, AUTORELEASED STRING OBJECTS, NO NEED TO RELEASE THESE;
|
|
|
|
+ (String*) stringWithString: (String*)aString;
|
1995-03-12 19:25:28 +00:00
|
|
|
+ (String*) stringWithString: (String*)aString range: (IndexRange)aRange;
|
1995-03-11 20:49:02 +00:00
|
|
|
+ (String*) stringWithFormat: (String*)aFormatString, ...;
|
|
|
|
+ (String*) stringWithFormat: (String*)aFormatString arguments: (va_list)arg;
|
1995-03-12 15:45:31 +00:00
|
|
|
+ (String*) stringWithCString: (const char*)aCharPtr;
|
1995-03-12 19:25:28 +00:00
|
|
|
+ (String*) stringWithCString: (const char*)aCharPtr range: (IndexRange)aRange;
|
1995-03-11 20:49:02 +00:00
|
|
|
|
|
|
|
- (String*) stringByAppendingFormat: (String*)aString, ...;
|
1995-03-12 15:45:31 +00:00
|
|
|
- (String*) stringByAppendingFormat: (String*)aString arguments: (va_list)arg;
|
1995-03-11 20:49:02 +00:00
|
|
|
- (String*) stringByPrependingFormat: (String*)aString, ...;
|
1995-03-12 15:45:31 +00:00
|
|
|
- (String*) stringByPrependingFormat: (String*)aString arguments: (va_list)arg;
|
1995-03-11 20:49:02 +00:00
|
|
|
- (String*) stringByAppendingString: (String*)aString;
|
|
|
|
- (String*) stringByPrependingString: (String*)aString;
|
|
|
|
|
1995-03-12 19:25:28 +00:00
|
|
|
//- (String*) substringWithRange: (IndexRange)aRange;
|
|
|
|
//- (String*) substringWithLength: (unsigned)l;
|
|
|
|
//- (String*) substringAfterIndex: (unsigned)i;
|
|
|
|
//- (id <IndexedCollecting>) substringsSeparatedByString: (String*)separator;
|
1995-03-11 20:49:02 +00:00
|
|
|
|
1995-03-12 19:25:28 +00:00
|
|
|
//- (String*) capitalizedString;
|
|
|
|
//- (String*) lowercaseString;
|
|
|
|
//- (String*) uppercaseString;
|
1995-03-11 20:49:02 +00:00
|
|
|
|
1995-03-12 19:25:28 +00:00
|
|
|
// QUERYING
|
|
|
|
- (unsigned) length;
|
|
|
|
- (IndexRange) range;
|
1995-03-11 20:49:02 +00:00
|
|
|
- (BOOL) isEqual: anObject;
|
|
|
|
- (unsigned) hash;
|
|
|
|
- (int) compare: anObject;
|
|
|
|
- copy;
|
|
|
|
- (unsigned) indexOfString: (String*)aString;
|
|
|
|
- (unsigned) indexOfChar: (char)aChar;
|
|
|
|
- (unsigned) indexOfLastChar: (char)aChar;
|
1995-03-12 19:25:28 +00:00
|
|
|
//- (unsigned) indexOfCharacter: (Character)aChar;
|
|
|
|
//- (unsigned) indexOfLastCharacter: (Character)aChar;
|
1995-03-11 20:49:02 +00:00
|
|
|
|
|
|
|
// FOR FILE NAMES (don't use the name "path", gnu will not use it for this);
|
1995-03-12 19:25:28 +00:00
|
|
|
//- (IndexRange) fileRange;
|
|
|
|
//- (IndexRange) directoriesRange;
|
|
|
|
//- (IndexRange) extensionRange;
|
|
|
|
//- (IndexRange) fileWithoutExtensionRange;
|
|
|
|
//- (BOOL) isAbsolute;
|
|
|
|
//- (BOOL) isRelative;
|
1995-03-11 20:49:02 +00:00
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
@protocol MutableString <String, ValueHolding>
|
|
|
|
|
1995-03-12 15:45:31 +00:00
|
|
|
+ (MutableString*) stringWithCapacity: (unsigned)capacity;
|
1995-03-11 20:49:02 +00:00
|
|
|
- initWithCapacity: (unsigned)capacity;
|
|
|
|
|
1995-03-12 15:45:31 +00:00
|
|
|
/* This from IndexedCollecting: - removeRange: (IndexRange)range; */
|
1995-03-11 20:49:02 +00:00
|
|
|
- (void) insertString: (String*)string atIndex: (unsigned)index;
|
|
|
|
|
1995-03-12 15:45:31 +00:00
|
|
|
- (void) setString: (String*)string;
|
|
|
|
- (void) appendString: (String*)string;
|
1995-03-11 20:49:02 +00:00
|
|
|
- (void) replaceRange: (IndexRange)range withString: (String*)string;
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
1995-03-12 15:45:31 +00:00
|
|
|
/* Abstract string classes */
|
|
|
|
|
1995-03-11 20:49:02 +00:00
|
|
|
@interface String : IndexedCollection <String>
|
|
|
|
@end
|
|
|
|
|
|
|
|
@interface MutableString : String <MutableString>
|
|
|
|
@end
|
|
|
|
|
1995-03-12 15:45:31 +00:00
|
|
|
/* Some concrete string classes */
|
|
|
|
|
|
|
|
@interface CString : String
|
1995-03-11 20:49:02 +00:00
|
|
|
{
|
|
|
|
char * _contents_chars;
|
|
|
|
int _count;
|
|
|
|
}
|
|
|
|
@end
|
|
|
|
|
1995-03-12 15:45:31 +00:00
|
|
|
@interface MutableCString : MutableString
|
1995-03-11 20:49:02 +00:00
|
|
|
{
|
1995-03-12 15:45:31 +00:00
|
|
|
char * _contents_chars;
|
|
|
|
int _count;
|
1995-03-11 20:49:02 +00:00
|
|
|
int _capacity;
|
|
|
|
}
|
|
|
|
@end
|
|
|
|
|
1995-03-12 15:45:31 +00:00
|
|
|
@interface ConstantString : CString
|
1995-03-11 20:49:02 +00:00
|
|
|
@end
|
|
|
|
|
1995-03-12 15:45:31 +00:00
|
|
|
/* The compiler makes @""-strings into NXConstantString's */
|
1995-03-11 20:49:02 +00:00
|
|
|
@interface NXConstantString : ConstantString
|
|
|
|
@end
|
|
|
|
|
|
|
|
#endif /* __String_h_OBJECTS_INCLUDE */
|