Simplify NSString subclassing

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@7954 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-MacDonald 2000-10-31 19:07:35 +00:00
parent 8894c52b34
commit 780868f1a5
4 changed files with 202 additions and 30 deletions

View file

@ -3,6 +3,7 @@
* Source/NSString.m: Implemented
([-initWithCharactersNoCopy:length:freeWhenDone:]) and
([-initWithCStringNoCopy:length:freeWhenDone:]) for NSMutableString.
([-initWithCStringNoCopy:length:freeWhenDone:]) for NSString.
2000-10-31 Richard Frith-Macdonald <rfm@gnu.org>

View file

@ -10,8 +10,8 @@
<author name="James Dessart">
<email address="skwirl@cam.org"/>
</author>
<version>0.1</version>
<date>28 February, 2000</date>
<version>0.2</version>
<date>31 October, 2000</date>
</head>
<body>
<chapter>
@ -19,50 +19,81 @@
<class name="NSString" super="NSObject">
<declared>Foundation/NSString.h</declared>
<conform>NSCoding</conform>
<desc>
<p>NSString objects represent an immutable string of characters. NSString itself is an
abstract class which provides factory methods to generate objects of unspecified
subclasses.</p>
<desc>
<p>
NSString objects represent an immutable string of characters.
NSString itself is an abstract class which provides factory
methods to generate objects of unspecified subclasses.
</p>
<p>
A constant NSString can be created using the following syntax:
<code>@"..."</code>, where the contents of the quotes are the
string, using only ASCII characters.
</p>
<p>
To create a concrete subclass of NSString, you must have your
class inherit from NSString and override at least the two
primitive methods - length and characterAtIndex:
</p>
<p>
In general the rule is that your subclass must override any
initialiser that you want to use with it. The GNUstep
implementation relaxes that to say that, you may override
only the <em>designated initialiser</em> and the other
initialisation methods should work.
</p>
</desc>
<p>A constant NSString can be created using the following syntax: <code>@"..."</code>,
where the contents of the quotes are the string, using only ASCII characters.</p>
</desc>
<method type="const NSStringEncoding*" factory="yes">
<sel>availableStringEncodings</sel>
<desc>
<p>Returns an array of all available string encodings, terminated by a null value.</p>
<p>
Returns an array of all available string encodings,
terminated by a null value.
</p>
</desc>
</method>
<method type="NSStringEncoding" factory="yes">
<sel>defaultCStringEncoding</sel>
<desc>
<p>Returns the encoding used for any method accepting a C string.</p>
<p>
Returns the encoding used for any method accepting a C string.
</p>
</desc>
</method>
<method type="NSString*" factory="yes">
<sel>localizedNameOfStringEncoding:</sel>
<arg type="NSStringEncoding">encoding</arg>
<desc>
<p>Returns the localized name of the encoding specified by <var>encoding</var>.</p>
<p>
Returns the localized name of the encoding specified
by <var>encoding</var>.
</p>
</desc>
</method>
<method type="NSString*" factory="yes">
<sel>localizedStringWithFormat:</sel>
<arg type="NSString*">format,</arg>
<desc>
</desc>
</method>
<method type="NSString*" factory="yes">
<sel>pathWithComponents:</sel>
<arg type="NSArray*">components</arg>
<desc>
</desc>
</method>
<method type="id" factory="yes">
<sel>string</sel>
<desc>
</desc>
</method>
<method type="id" factory="yes">
<sel>stringWithCharacters:</sel>
<arg type="const unichar*">chars</arg>
@ -71,77 +102,90 @@
<desc>
</desc>
</method>
<method type="id" factory="yes">
<sel>stringWithContentsOfFile:</sel>
<arg type="NSString*">path</arg>
<desc>
</desc>
</method>
<method type="id" factory="yes">
<sel>stringWithCString:</sel>
<arg type="const char*">cString</arg>
<desc>
</desc>
</method>
<method type="id" factory="yes">
<sel>stringWithCString:</sel>
<arg type="const char*">cString</arg>
<desc>
</desc>
</method>
<method type="id" factory="yes">
<sel>stringWithFormat:</sel>
<arg type="NSString*">format,</arg>
<desc>
</desc>
</method>
<method type="id" factory="yes">
<sel>stringWithString:</sel>
<arg type="NSString*">aString</arg>
<desc>
</desc>
</method>
<method type="BOOL">
<sel>canBeConvertedToEncoding:</sel>
<arg type="NSStringEncoding">encoding</arg>
<desc>
</desc>
</method>
<method type="NSString*">
<sel>capitalizedString</sel>
<desc>
</desc>
</method>
<method type="NSComparisonResult">
<sel>caseInsensitiveCompare:</sel>
<arg type="NSString*">aString</arg>
<desc>
</desc>
</method>
<method type="unichar">
<sel>characterAtIndex:</sel>
<arg type="unsigned int">index</arg>
<desc>
</desc>
</method>
<method type="NSString*">
<sel>commonPrefixWithString:</sel>
<arg type="NSString*">aString</arg>
<desc>
</desc>
</method>
<method type="NSComparisonResult">
<sel>compare:</sel>
<arg type="NSString*">aString</arg>
<desc>
</desc>
</method>
<method type="NSComparisonResult">
<sel>compare:</sel>
<arg type="NSString*">aString</arg>
<desc>
</desc>
</method>
<method type="NSComparisonResult">
<sel>compare:</sel>
<arg type="NSString*">aString</arg>
@ -152,6 +196,7 @@
<desc>
</desc>
</method>
<method type="unsigned int">
<sel>completePathIntoString:</sel>
<arg type="NSString**">outputName</arg>
@ -162,28 +207,37 @@
<desc>
</desc>
</method>
<method type="NSArray*">
<sel>componentsSeparatedByString:</sel>
<arg type="NSString*">separator</arg>
<desc>
</desc>
</method>
<method type="const char*">
<sel>cString</sel>
<desc>
Returns a pointer to a nul terminated string of 8-bit
characters in the default encoding. The memory pointed
to is not owned by the caller, so the caller must copy
its contents to keep it.
</desc>
</method>
<method type="unsigned int">
<sel>cStringLength</sel>
<desc>
</desc>
</method>
<method type="NSData*">
<sel>dataUsingEncoding:</sel>
<arg type="NSStringEncoding">encoding</arg>
<desc>
</desc>
</method>
<method type="NSData*">
<sel>dataUsingEncoding:</sel>
<arg type="NSStringEncoding">encoding</arg>
@ -192,49 +246,58 @@
<desc>
</desc>
</method>
<method type="NSString*">
<sel>description</sel>
<desc>
</desc>
</method>
<method type="double">
<sel>doubleValue</sel>
<desc>
</desc>
</method>
<method type="NSStringEncoding">
<sel>fastestEncoding</sel>
<desc>
</desc>
</method>
<method type="const char*">
<sel>fileSystemRepresentation</sel>
<desc>
</desc>
</method>
<method type="float">
<sel>floatValue</sel>
<desc>
</desc>
</method>
<method type="void">
<sel>getCharacters:</sel>
<arg type="unichar*">buffer</arg>
<desc>
</desc>
</method>
<method type="void">
<sel>getCharacters:</sel>
<arg type="unichar*">buffer</arg>
<desc>
</desc>
</method>
<method type="void">
<sel>getCString:</sel>
<arg type="char*">buffer</arg>
<desc>
</desc>
</method>
<method type="void">
<sel>getCString:</sel>
<arg type="char*">buffer</arg>
@ -243,6 +306,7 @@
<desc>
</desc>
</method>
<method type="void">
<sel>getCString:</sel>
<arg type="char*">buffer</arg>
@ -255,6 +319,7 @@
<desc>
</desc>
</method>
<method type="BOOL">
<sel>getFileSystemRepresentation:</sel>
<arg type="char*">buffer</arg>
@ -263,6 +328,7 @@
<desc>
</desc>
</method>
<method type="void" factory="yes">
<sel>getLineStart:</sel>
<arg type="unsigned int*">startIndex</arg>
@ -273,35 +339,41 @@
<desc>
</desc>
</method>
<method type="unsigned int">
<sel>hash</sel>
<desc>
</desc>
</method>
<method type="BOOL">
<sel>hasPrefix:</sel>
<arg type="NSString*">aString</arg>
<desc>
</desc>
</method>
<method type="BOOL">
<sel>hasSuffix:</sel>
<arg type="NSString*">aString</arg>
<desc>
</desc>
</method>
<method type="id">
<sel>init</sel>
<desc>
</desc>
</method>
<method type="id">
<sel>initWithCharacters:</sel>
<arg type="const unichar*">characters</arg>
<desc>
</desc>
</method>
<method type="id">
<method type="id" init="yes">
<sel>initWithCharactersNoCopy:</sel>
<arg type="unichar*">characters</arg>
<sel>length:</sel>
@ -309,26 +381,33 @@
<sel>freeWhenDone:</sel>
<arg type="BOOL">flag</arg>
<desc>
This is the most basic initialiser for unicode strings.
In the GNUstep implementation, your subclasses may override
this initialiser in order to have all others function.
</desc>
</method>
<method type="id">
<sel>initWithContentsOfFile:</sel>
<arg type="NSString*">path</arg>
<desc>
</desc>
</method>
<method type="id">
<sel>initWithCString:</sel>
<arg type="const char*">cString</arg>
<desc>
</desc>
</method>
<method type="id">
<sel>initWithCString:</sel>
<arg type="const char*">cString</arg>
<desc>
</desc>
</method>
<method type="id">
<sel>initWithCStringNoCopy:</sel>
<arg type="char*">cString</arg>
@ -339,6 +418,7 @@
<desc>
</desc>
</method>
<method type="id">
<sel>initWithData:</sel>
<arg type="NSData*">data</arg>
@ -347,12 +427,14 @@
<desc>
</desc>
</method>
<method type="id">
<sel>initWithFormat:</sel>
<arg type="NSString*">format,</arg>
<desc>
</desc>
</method>
<method type="id">
<sel>initWithFormat:</sel>
<arg type="NSString*">format</arg>
@ -361,12 +443,14 @@
<desc>
</desc>
</method>
<method type="id">
<sel>initWithFormat:</sel>
<arg type="NSString*">format</arg>
<desc>
</desc>
</method>
<method type="id">
<sel>initWithFormat:</sel>
<arg type="NSString*">format</arg>
@ -377,80 +461,97 @@
<desc>
</desc>
</method>
<method type="id">
<sel>initWithString:</sel>
<arg type="NSString*">aString</arg>
<desc>
</desc>
</method>
<method type="int">
<sel>intValue</sel>
<desc>
</desc>
</method>
<method type="BOOL">
<sel>isAbsolutePath</sel>
<desc>
</desc>
</method>
<method type="BOOL">
<sel>isEqualToString:</sel>
<arg type="NSString*">aString</arg>
<desc>
</desc>
</method>
<method type="NSString*">
<sel>lastPathComponent</sel>
<desc>
</desc>
</method>
<method type="unsigned int">
<sel>length</sel>
<desc>
</desc>
</method>
<method type="NSRange" factory="yes">
<sel>lineRangeForRange:</sel>
<arg type="NSRange">aRange</arg>
<desc>
</desc>
</method>
<method type="const char*">
<sel>lossyCString</sel>
<desc>
</desc>
</method>
<method type="NSString*">
<sel>lowercaseString</sel>
<desc>
Returns a copy of the receiver with all characters converted
to lowercase.
</desc>
</method>
<method type="NSArray*">
<sel>pathComponents</sel>
<desc>
</desc>
</method>
<method type="NSString*">
<sel>pathExtension</sel>
<desc>
</desc>
</method>
<method type="id">
<sel>propertyList</sel>
<desc>
</desc>
</method>
<method type="NSDictionary*">
<sel>propertyListFromStringsFileFormat</sel>
<desc>
</desc>
</method>
<method type="NSRange">
<sel>rangeOfCharacterFromSet:</sel>
<arg type="NSCharacterSet*">aSet</arg>
<desc>
</desc>
</method>
<method type="NSRange">
<sel>rangeOfCharacterFromSet:</sel>
<arg type="NSCharacterSet*">aSet</arg>
@ -459,6 +560,7 @@
<desc>
</desc>
</method>
<method type="NSRange">
<sel>rangeOfCharacterFromSet:</sel>
<arg type="NSCharacterSet*">aSet</arg>
@ -469,12 +571,14 @@
<desc>
</desc>
</method>
<method type="NSRange">
<sel>rangeOfComposedCharacterSequenceAtIndex:</sel>
<arg type="unsigned int">anIndex</arg>
<desc>
</desc>
</method>
<method type="NSRange">
<sel>rangeOfString:</sel>
<arg type="NSString*">aString</arg>
@ -483,6 +587,7 @@
set to zero.
</desc>
</method>
<method type="NSRange">
<sel>rangeOfString:</sel>
<arg type="NSString*">aString</arg>
@ -493,6 +598,7 @@
set to the range of the whole of the reciever.
</desc>
</method>
<method type="NSRange">
<sel>rangeOfString:</sel>
<arg type="NSString*">subString</arg>
@ -522,55 +628,65 @@
</list>
</desc>
</method>
<method type="NSStringEncoding">
<sel>smallestEncoding</sel>
<desc>
</desc>
</method>
<method type="NSString*">
<sel>stringByAbbreviatingWithTildeInPath</sel>
<desc>
</desc>
</method>
<method type="NSString*">
<sel>stringByAppendingFormat:</sel>
<arg type="NSString*">format,</arg>
<desc>
</desc>
</method>
<method type="NSString*">
<sel>stringByAppendingPathComponent:</sel>
<arg type="NSString*">aString</arg>
<desc>
</desc>
</method>
<method type="NSString*">
<sel>stringByAppendingPathExtension:</sel>
<arg type="NSString*">string</arg>
<desc>
</desc>
</method>
<method type="NSString*">
<sel>stringByAppendingString:</sel>
<arg type="NSString*">aString</arg>
<desc>
</desc>
</method>
<method type="NSString*">
<sel>stringByDeletingLastPathComponent</sel>
<desc>
</desc>
</method>
<method type="NSString*">
<sel>stringByDeletingPathExtension</sel>
<desc>
</desc>
</method>
<method type="NSString*">
<sel>stringByExpandingTildeInPath</sel>
<desc>
</desc>
</method>
<method type="NSString*">
<sel>stringByReplacingString:</sel>
<arg type="NSString*">aString</arg>
@ -585,35 +701,43 @@
</desc>
<standards><GNUstep/><NotMacOS-X/><NotOpenStep/></standards>
</method>
<method type="NSArray*">
<sel>stringsByAppendingPaths:</sel>
<arg type="NSArray*">paths</arg>
<desc>
</desc>
</method>
<method type="NSString*">
<sel>substringFromIndex:</sel>
<arg type="unsigned int">anIndex</arg>
<desc>
</desc>
</method>
<method type="NSString*">
<sel>substringToIndex:</sel>
<arg type="unsigned int">anIndex</arg>
<desc>
</desc>
</method>
<method type="NSString*">
<sel>substringWithRange:</sel>
<arg type="NSRange">aRange</arg>
<desc>
</desc>
</method>
<method type="NSString*">
<sel>uppercaseString</sel>
<desc>
Returns a copy of the receiver with all characters converted
to uppercase.
</desc>
</method>
<method type="BOOL">
<sel>writeToFile:</sel>
<arg type="NSString*">path</arg>

View file

@ -13,8 +13,8 @@
<dt>James Dessart
<dd>
</dl>
<p>Version: 0.1</p>
<p>Date: 28 February, 2000</p>
<p>Version: 0.2</p>
<p>Date: 31 October, 2000</p>
<h2><a name ="cont-0">NSString</a></h2>
<h2><a name ="NSString">NSString</a></h2>
<p><b>Declared in: </b> Foundation/NSString.h</p>
@ -24,16 +24,36 @@
<hr>
<p>
NSString objects represent an immutable string of characters. NSString itself is an
abstract class which provides factory methods to generate objects of unspecified
subclasses.</p>
NSString objects represent an immutable string of characters.
NSString itself is an abstract class which provides factory
methods to generate objects of unspecified subclasses.
</p>
<p>
A constant NSString can be created using the following syntax: <code>@"..."</code>,
where the contents of the quotes are the string, using only ASCII characters.</p>
A constant NSString can be created using the following syntax:
<code>@"..."</code>, where the contents of the quotes are the
string, using only ASCII characters.
</p>
<p>
To create a concrete subclass of NSString, you must have your
class inherit from NSString and override at least the two
primitive methods - length and characterAtIndex:
</p>
<p>
In general the rule is that your subclass must override any
initialiser that you want to use with it. The GNUstep
implementation relaxes that to say that, you may override
only the <em>designated initialiser</em> and the other
initialisation methods should work.
</p>
<h2>Instance Variables </h2>
<ul>
</ul>
@ -133,24 +153,32 @@ A constant NSString can be created using the following syntax: <code>@"..."</cod
<h3><a name ="method-0">availableStringEncodings</a></h3>
+ (const NSStringEncoding*) <b>availableStringEncodings</b>;<br>
<p>
Returns an array of all available string encodings, terminated by a null value.</p>
<p>
Returns an array of all available string encodings,
terminated by a null value.
</p>
<hr>
<h3><a name ="method-1">defaultCStringEncoding</a></h3>
+ (NSStringEncoding) <b>defaultCStringEncoding</b>;<br>
<p>
Returns the encoding used for any method accepting a C string.</p>
<p>
Returns the encoding used for any method accepting a C string.
</p>
<hr>
<h3><a name ="method-2">localizedNameOfStringEncoding:</a></h3>
+ (NSString*) <b>localizedNameOfStringEncoding:</b> (NSStringEncoding)encoding;<br>
<p>
Returns the localized name of the encoding specified by <var>encoding</var>.</p>
<p>
Returns the localized name of the encoding specified
by <var>encoding</var>.
</p>
<hr>
@ -263,6 +291,10 @@ Returns the localized name of the encoding specified by <var>encoding</var>.</p>
<h3><a name ="method-22">cString</a></h3>
- (const char*) <b>cString</b>;<br>
Returns a pointer to a nul terminated string of 8-bit
characters in the default encoding. The memory pointed
to is not owned by the caller, so the caller must copy
its contents to keep it.
<hr>
<h3><a name ="method-23">cStringLength</a></h3>
@ -361,8 +393,12 @@ Returns the localized name of the encoding specified by <var>encoding</var>.</p>
<hr>
<h3><a name ="method-43">initWithCharactersNoCopy:length:freeWhenDone:</a></h3>
<b>This is the designated initialiser </b><br>
- (id) <b>initWithCharactersNoCopy:</b> (unichar*)characters <b>length:</b> (unsigned int)length <b>freeWhenDone:</b> (BOOL)flag;<br>
This is the most basic initialiser for unicode strings.
In the GNUstep implementation, your subclasses may override
this initialiser in order to have all others function.
<hr>
<h3><a name ="method-44">initWithContentsOfFile:</a></h3>
@ -448,6 +484,8 @@ Returns the localized name of the encoding specified by <var>encoding</var>.</p>
<h3><a name ="method-61">lowercaseString</a></h3>
- (NSString*) <b>lowercaseString</b>;<br>
Returns a copy of the receiver with all characters converted
to lowercase.
<hr>
<h3><a name ="method-62">pathComponents</a></h3>
@ -608,6 +646,8 @@ Standards: GNUstep NotMacOS-X NotOpenStep<br>
<h3><a name ="method-87">uppercaseString</a></h3>
- (NSString*) <b>uppercaseString</b>;<br>
Returns a copy of the receiver with all characters converted
to uppercase.
<hr>
<h3><a name ="method-88">writeToFile:atomically:</a></h3>

View file

@ -404,7 +404,7 @@ handle_printf_atsign (FILE *stream,
// Initializing Newly Allocated Strings
/* This is the designated initializer for Unicode Strings. */
/* This is the designated initializer. */
- (id) initWithCharactersNoCopy: (unichar*)chars
length: (unsigned)length
freeWhenDone: (BOOL)flag
@ -468,12 +468,19 @@ handle_printf_atsign (FILE *stream,
return self;
}
/* This is the designated initializer for CStrings. */
- (id) initWithCStringNoCopy: (char*)byteString
length: (unsigned)length
freeWhenDone: (BOOL)flag
{
[self subclassResponsibility: _cmd];
unichar *buf;
buf = (unichar*)NSZoneMalloc(GSObjCZone(self), sizeof(unichar)*length);
length = encode_strtoustr(buf, byteString, length, _DefaultStringEncoding);
if (flag == YES && byteString != 0)
{
NSZoneFree(NSZoneFromPointer(byteString), byteString);
}
self = [self initWithCharactersNoCopy: buf length: length freeWhenDone: YES];
return self;
}