#import <ObjectiveLib/Text.h>
Inheritance diagram for OLText:
Public Member Functions | |
(olchar) | - at: |
Return the character at index. | |
(uint8_t *) | - bytesWithEncoding:returnedCount: |
Return the text encoded with the given encoding. | |
(int) | - compare: |
Compare this object to another. | |
(id) | - copy |
Return a copy of this object. | |
(const char *) | - cString |
Return a "C string". | |
(BOOL) | - empty |
Return whether this text is empty. | |
(unsigned) | - findChar:fromOffset: |
Find a character. | |
(unsigned) | - findFirstNotOf:fromOffset: |
Find a character not in a set. | |
(unsigned) | - findFirstOf:fromOffset: |
Find a character of a set. | |
(unsigned) | - findLastNotOf:fromOffset: |
Find a character not in a set. | |
(unsigned) | - findLastOf:fromOffset: |
Find a character of a set. | |
(unsigned) | - findText:fromOffset: |
Find a subsequence. | |
(void) | - getCharacters:fromOffset:count: |
Extract a range of characters. | |
(unsigned) | - hash |
Return a hash code. | |
(BOOL) | - isEqual: |
Return whether this text object is equal to another one. | |
(unsigned) | - length |
Return the length of the text. | |
(unsigned) | - maxSize |
Return the maximum size of a text object. | |
(uint8_t *) | - nullTerminatedBytesWithEncoding: |
Return the text encoded with the given encoding. | |
(unsigned) | - rfindChar:fromOffset: |
Find a character. | |
(unsigned) | - size |
Return the size of the text. | |
(OLText *) | - substrFromOffset:count: |
Extract a subsequence. | |
(void) | - writeSelfToStream: |
Write this object to a stream. | |
Initializers and Deallocators | |
(id) | - free |
Reduce the reference count to the text by one and deallocate the memory if the reference count becomes zero. | |
(id) | - init |
Initialize a new text object. | |
(id) | - initWithBytes:count:encoding: |
Initialize a new text object. | |
(id) | - initWithChars:count: |
Initialize a new text object. | |
(id) | - initWithConstantString: |
(id) | - initWithCString: |
Initialize the text object. | |
(id) | - initWithObjectInStream: |
Initialize the text object. | |
(id) | - initWithText: |
Initialize the text object. | |
(id) | - initWithText:offset:count: |
Initialize the text object. | |
Static Public Member Functions | |
(id) | + initialize |
Initialize the class. | |
(id) | + textWithBytes:count:encoding: |
Create and return a new text object. | |
(id) | + textWithCString: |
Create and return a new text object. | |
(id) | + textWithText: |
Create and return a new text object. | |
Protected Attributes | |
_OLTextReference * | reference |
The opaque structure that holds the data. |
Text stored in an instance of OLText can be queried, searched, converted to other encodings and subsequences can be extracted, but the text itself cannot be changed. In order to mutate a piece of text an instance of the class OLTextBuffer must be used, and then an immutable OLText object can be derived.
OLText objects maintain their data by reference counting. Therefore, copying a piece of text is a very inexpensive operation, as the reference count is simply incremented.
- (olchar) at: | (unsigned) | index |
Return the character at index.
index | the index of the character to return |
- (uint8_t*) bytesWithEncoding: | (const char *) | enc | ||
returnedCount: | (unsigned *) | rc | ||
Return the text encoded with the given encoding.
The length of the returned array will be placed in rc.
objc_free
.OLInvalidArgumentException | if the given encoding is not supported |
enc | the encoding with which to encode the text | |
rc | the length of the returned array |
- (int) compare: | (id) | other |
Compare this object to another.
OLText objects can be compared to other OLText objects, to NSString objects under OpenStep and to OLConstantString objects if OpenStep is not present. The two objects, if compatible, will be compared lexicographically.
other | the object to which to compare this one |
- (id) copy |
Return a copy of this object.
A new object is returned that refers to the same text as this object. The reference count is merely incremented.
- (const char*) cString |
Return a "C string".
The returned array is an array of bytes encoded with the default encoding for the platform. This encoding should be set with a previous call to setlocale
. The returned array should not be freed by the caller.
- (BOOL) empty |
Return whether this text is empty.
- (unsigned) findChar: | (olchar) | ch | ||
fromOffset: | (unsigned) | offset | ||
Find a character.
The character is searched for from the given offset.
ch | the character for which to search | |
offset | the offset from which to start |
- (unsigned) findFirstNotOf: | (OLText *) | text | ||
fromOffset: | (unsigned) | offset | ||
Find a character not in a set.
The characters of this text object are searched until one is found that is not contained in the given set, text.
text | the set of characters against which to compare | |
offset | the starting offset in this text object of the search |
- (unsigned) findFirstOf: | (OLText *) | text | ||
fromOffset: | (unsigned) | offset | ||
Find a character of a set.
The characters of this text object are searched until one is found that is contained in the given set, text.
text | the set of characters against which to compare | |
offset | the starting offset in this text object of the search |
- (unsigned) findLastNotOf: | (OLText *) | text | ||
fromOffset: | (unsigned) | offset | ||
Find a character not in a set.
The characters of this text object are searched until one is found that is not contained in the given set, text. The search begins at offset and proceeds backwards, towards the beginning of this text object.
text | the set of characters against which to compare | |
offset | the starting offset in this text object of the search |
- (unsigned) findLastOf: | (OLText *) | text | ||
fromOffset: | (unsigned) | offset | ||
Find a character of a set.
The characters of this text object are searched until one is found that is contained in the given set, text. The search begins at offset and proceeds backwards, towards the beginning of this text object.
text | the set of characters against which to compare | |
offset | the starting offset in this text object of the search |
- (unsigned) findText: | (OLText *) | text | ||
fromOffset: | (unsigned) | offset | ||
Find a subsequence.
This text object is searched until the subsequence represented by text is found.
text | the subsequence for which to search | |
offset | the starting offset in this text object of the search |
- (id) free |
Reduce the reference count to the text by one and deallocate the memory if the reference count becomes zero.
- (void) getCharacters: | (olchar *) | buffer | ||
fromOffset: | (unsigned) | offset | ||
count: | (unsigned) | num | ||
Extract a range of characters.
A range of characters from this text object is copied to a buffer.
buffer | the destination buffer | |
offset | the starting offset | |
num | the number of characters to copy |
- (unsigned) hash |
Return a hash code.
The hash code for this text object is computed using OLHash.
- (id) init |
Initialize a new text object.
The text is empty.
+ (id) initialize |
Initialize the class.
This for the runtime system to call. Please don't call this method.
- (id) initWithBytes: | (const uint8_t *) | bytes | ||
count: | (unsigned) | num | ||
encoding: | (const char *) | enc | ||
Initialize a new text object.
The bytes given will be converted from the encoding enc to UTF-16.
OLInvalidArgumentException | if the given encoding is not supported |
bytes | the bytes containing the text encoded with the given encoding | |
num | the number of bytes | |
enc | the encoding used for the data in bytes |
- (id) initWithChars: | (const olchar *) | chs | ||
count: | (unsigned) | num | ||
Initialize a new text object.
The new object will contain the characters pointed to by the parameter chs.
chs | the characters to copy into the new text object | |
num | the number of characters |
- (id) initWithCString: | (const char *) | chs |
Initialize the text object.
The text in chs is assumed to be in the default encoding for the platform. This locale is assumed to have been set by a previous call to setlocale
. The "C string" chs should be null-terminated.
chs | the characters to encode with UTF-16 and store |
- (id) initWithObjectInStream: | (OLObjectInStream *) | stream |
Initialize the text object.
Creates a new text object from an object input stream.
stream | the input stream from which to read the text |
Reimplemented from < OLStreamable >.
- (id) initWithText: | (OLText *) | text |
Initialize the text object.
The given text object text is copied, meaning that the reference count to its data is incremented.
text | the text to copy |
- (id) initWithText: | (OLText *) | text | ||
offset: | (unsigned) | roff | ||
count: | (unsigned) | num | ||
Initialize the text object.
A span of num characters is copied from the given text object text starting at roff.
text | the text object from which to copy characters | |
roff | the beginning offset from which to copy | |
num | the number of characters to copy |
- (BOOL) isEqual: | (id) | object |
Return whether this text object is equal to another one.
This message returns YES if compare: returns zero.
object | the object to test |
- (unsigned) length |
- (unsigned) maxSize |
Return the maximum size of a text object.
- (uint8_t*) nullTerminatedBytesWithEncoding: | (const char *) | enc |
Return the text encoded with the given encoding.
The resulting array will be null-terminated.
objc_free
.OLInvalidArgumentException | if the given encoding is not supported |
enc | the encoding with which to encode the text |
- (unsigned) rfindChar: | (olchar) | ch | ||
fromOffset: | (unsigned) | offset | ||
Find a character.
The character is searched for from the given offset backwards, towards the beginning of this text object.
ch | the character for which to search | |
offset | the offset from which to start |
- (unsigned) size |
- (OLText*) substrFromOffset: | (unsigned) | offset | ||
count: | (unsigned) | num | ||
Extract a subsequence.
A new text object is created from the indicated subsequence of this one.
offset | the offset from which to start the new object | |
num | the number of characters in the new object |
+ (id) textWithBytes: | (const uint8_t *) | bytes | ||
count: | (unsigned) | num | ||
encoding: | (const char *) | enc | ||
Create and return a new text object.
The text is encoded from the given encoding enc to the internal encoding used by all text objects of UTF-16.
OLInvalidArgumentException | if the given encoding is not supported |
bytes | the bytes containing the text encoded with the given encoding | |
num | the number of bytes | |
enc | the encoding used for the data in bytes |
+ (id) textWithCString: | (const char *) | chs |
Create and return a new text object.
The text in chs is assumed to be in the default encoding for the platform. This locale is assumed to have been set by a previous call to setlocale
. The "C string" chs should be null-terminated.
chs | the characters to encode with UTF-16 and store |
+ (id) textWithText: | (OLText *) | text |
Create and return a new text object.
The given text object text is copied, meaning that the reference count to its data is incremented.
text | the text to copy |
- (void) writeSelfToStream: | (OLObjectOutStream *) | stream |
Write this object to a stream.
The text is written in a platform-neutral way and may be recovered with the initializer initWithObjectInStream:.
OLInputOutputException | if there is an error writing to the stream |
stream | the stream to which to write |
Reimplemented from < OLStreamable >.
- (struct _OLTextReference*) reference [protected] |
The opaque structure that holds the data.
|