picofuse-objc

Instance Methods | Class Methods | List of all members
NXString Class Reference

A string of UTF-8 text. More...

#import <Foundation/Foundation.h>

Inheritance diagram for NXString:
Inheritance graph
[legend]
Collaboration diagram for NXString:
Collaboration graph
[legend]

Instance Methods

(id) - initWithBytes:length:
 Initializes a string with a number of bytes, or those before the first which is zero.
 
(id) - initWithString:
 Initializes a string with the contents of another, which is empty if that's nil.
 
(id) - initWithQuotedString:
 Initializes a string from one in quotes, with its escapes decoded.
 
(id) - initWithCString:
 Initializes a string with the contents of a null-terminated string, which is empty if that's NULL.
 
(id) - initWithFormat:
 Initializes a string with a format and arguments.
 
(id) - initWithFormat:arguments:
 Initializes a string with a format and a list of arguments.
 
(size_t) - length
 Returns the length in bytes, which doesn't include the null terminator.
 
(const char *) - cStr
 Returns the contents, as a null-terminated string. More...
 
(size_t) - runeCount
 Returns the number of runes, which are Unicode code points.
 
(BOOL) - isEqual:
 Returns YES if the other object is a string with the same contents, whatever kind it is.
 
(uintptr_t) - hash
 Returns a hash of the contents, which is the same for equal strings.
 
(NXComparisonResult) - compare:
 Compares the string with another, byte by byte. More...
 
(BOOL) - hasPrefix:
 Returns YES if the string starts with another, as it does with nil or an empty string.
 
(BOOL) - hasSuffix:
 Returns YES if the string ends with another, as it does with nil or an empty string.
 
(BOOL) - containsString:
 Returns YES if the string has another in it, as it does nil or an empty string.
 
(size_t) - indexOfSubstring:
 Returns the index, in bytes, of the first place that another string is in this one, or NXNotFound. More...
 
(NXArray *) - componentsSeparatedByString:
 Returns the parts of the string between a separator, as new strings. More...
 
(NXArray *) - componentsSeparatedByWhitespace
 Returns the words of the string, which are between runs of whitespace, as new strings. More...
 
(NXString *) - description
 Returns the string itself.
 
- Instance Methods inherited from NXObject
(void) - dealloc
 Frees the instance. More...
 
(NXZone *) - zone
 Returns the zone in which the instance was allocated. More...
 
(id) - retain
 Increases the retain count of the receiver. More...
 
(void) - release
 Decreases the retain count of the receiver. More...
 
(id) - autorelease
 Releases the receiver later, when the current autorelease pool of the thread is drained. More...
 
(id) - copy
 Returns a copy which can't be changed by anything else, which the caller owns and has to release. More...
 
- Instance Methods inherited from Object
(id) - init
 Initialize the instance, after allocation. More...
 
(Class) - class
 Returns the class of the instance. More...
 
(Class) - superclass
 Returns the superclass of the instance. More...
 
(BOOL) - isKindOfClass:
 Returns a Boolean value that indicates whether the receiver is an instance of a given class. More...
 
(BOOL) - conformsTo:
 Checks if the receiver's class conforms to a protocol. More...
 
- Instance Methods inherited from <ObjectProtocol>
(BOOL) - respondsToSelector:
 Checks if the receiver responds to a selector. More...
 

Class Methods

(id) + string
 Returns an empty string.
 
(id) + stringWithString:
 Returns a string with the contents of another, which is empty if that's nil.
 
(id) + stringWithCString:
 Returns a string with the contents of a null-terminated string, which is empty if that's NULL.
 
(id) + stringWithFormat:
 Returns a string made from a format and arguments.
 
(id) + stringWithQuotedString:
 Returns a string from one in quotes, with its escapes decoded, or nil if it isn't one. More...
 
- Class Methods inherited from NXObject
(id) + alloc
 Allocates a new instance in the default zone, or if there isn't one, with sys_calloc(). More...
 
(id) + allocWithZone:
 Allocates a new instance in a specific zone. More...
 
(id) + new
 Allocates and initializes a new instance, as [[cls alloc] init] does. More...
 
- Class Methods inherited from Object
(void) + initialize
 Performs one-time initialization for the class. More...
 
(Class) + class
 Returns the class object. More...
 
(Class) + superclass
 Returns the superclass of the class. More...
 
(const char *) + name
 Returns the name of the class. More...
 
(BOOL) + conformsTo:
 Checks if the class conforms to a protocol. More...
 

Additional Inherited Members

- Protected Attributes inherited from Object
Class isa
 A pointer to the object's class structure. More...
 

Detailed Description

A string of UTF-8 text.

This is the class of any string, including a constant such as @"string", so it's what methods take and return. Other strings copy what they're made from.

Strings can't be changed, unless they're an NXMutableString. They don't contain a zero byte.

A format can have these in it:

Specifier Argument
c Character
s Null-terminated string
d u 32-bit signed or unsigned integer
x X 32-bit unsigned integer, in hexadecimal
b o 32-bit unsigned integer, in binary or octal
f e g Floating point, also F, E and G
p Pointer
%@ Object, which is replaced by its description, or <nil>
t NXDuration
%% None, as it's a percent sign

With an l, as in ld, an integer is 64 bits, on every system. With a z, it's a size_t. There can also be a minimum width, as in %80d, a precision for floating point, as in %.3f, and the flags - (on the left), 0 (pad with zeros), + (show the sign), space, and # (show the base). They have no effect on %@ and t.

The description of an object may be needed twice, as a long string is formatted once to find out how long it is.

Strings which are returned by class methods are in the current autorelease pool. Methods which make strings return nil if there isn't enough memory.

Subclasses implement length and cStr.

An NXString can't change, so any number of threads can use it at once. An NXMutableString can. See Threads and mutable objects.

Definition at line 53 of file NXString.h.

Method Documentation

◆ compare:()

- (NXComparisonResult) compare: (NXString *)  other

Compares the string with another, byte by byte.

If that's nil, it's compared with an empty string.

◆ componentsSeparatedByString:()

- (NXArray *) componentsSeparatedByString: (NXString *)  separator

Returns the parts of the string between a separator, as new strings.

Parameters
separatorThe separator, which can be more than one character.
Returns
The parts, in order, including empty ones: "a,,b" is "a", "" and "b", and an empty string is one empty part. If the separator isn't found, or is nil or empty, it's the string on its own. Joining the parts with componentsJoinedByString: gives the string back. Returns nil if there isn't enough memory.

◆ componentsSeparatedByWhitespace()

- (NXArray *) componentsSeparatedByWhitespace

Returns the words of the string, which are between runs of whitespace, as new strings.

Returns
The words, in order, without empty ones: " a b " is "a" and "b", and a string of only whitespace has none. Whitespace is Unicode's, as trimWhitespace removes. Returns nil if there isn't enough memory.

◆ cStr()

- (const char *) cStr

Returns the contents, as a null-terminated string.

It can be used for as long as the string exists, and isn't changed.

◆ indexOfSubstring:()

- (size_t) indexOfSubstring: (NXString *)  other

Returns the index, in bytes, of the first place that another string is in this one, or NXNotFound.

It's zero for nil or an empty string.

◆ stringWithQuotedString:()

+ (id) stringWithQuotedString: (NXString *)  quoted

Returns a string from one in quotes, with its escapes decoded, or nil if it isn't one.

Parameters
quotedThe whole of it is a string in ' or " quotes, such as a token from a scanner with NXScannerQuotes. The escapes are \\' \\" \\ \/ \b \f \n \r \t and \uXXXX.
Returns
The string, which stops at the first zero, from \u0000, or nil if it isn't closed, has anything after the closing quote, has an escape which isn't known, or there isn't enough memory.

The documentation for this class was generated from the following file: