#import <ObjectiveLib/Text.h>
Public Member Functions | |
(OLTextBuffer *) | - appendChar: |
Append a character. | |
(OLTextBuffer *) | - appendChars:fromOffset:count: |
Append some characters. | |
(OLTextBuffer *) | - appendText: |
Append a text object. | |
(OLTextBuffer *) | - appendTextBuffer: |
Append another text buffer. | |
(OLTextBuffer *) | - assignAt:character: |
Assign a character. | |
(olchar) | - at: |
Return the character at index. | |
(unsigned) | - capacity |
Return the capacity of this buffer. | |
(void) | - clear |
Erase all characters. | |
(int) | - compare: |
Compare this object to another. | |
(id) | - copy |
Return a copy of this text buffer. | |
(BOOL) | - empty |
Return whether this text buffer is empty. | |
(OLTextBuffer *) | - eraseAt: |
Erase a character. | |
(OLTextBuffer *) | - eraseFromOffset:count: |
Erase a group of characters. | |
(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. | |
(OLTextBuffer *) | - insertChar:atOffset: |
Insert a character. | |
(OLTextBuffer *) | - insertChars:atOffset:count: |
Insert an array of characters. | |
(OLTextBuffer *) | - insertText:atOffset: |
Insert a chunk of text. | |
(BOOL) | - isEqual: |
Return whether this text buffer is equal to another one. | |
(unsigned) | - length |
Return the length of the text buffer. | |
(OLTextBuffer *) | - replaceFromOffset:count:withText: |
Replace a range of characters. | |
(void) | - reserve: |
Ensure that the capacity of the text buffer is at least of a certain size. | |
(OLTextBuffer *) | - resize:filledWith: |
Resize the text buffer. | |
(OLTextBuffer *) | - reverse |
Reverse the order of characters. | |
(unsigned) | - rfindChar:fromOffset: |
Find a character. | |
(unsigned) | - size |
Return the size of the text buffer. | |
(OLText *) | - substrFromOffset:count: |
Extract a subsequence. | |
(OLText *) | - text |
Return the text. | |
Initializers and Deallocators | |
(id) | - free |
Free all memory allocated by this buffer and destroy the object. | |
(id) | - init |
Initialize a new text buffer. | |
(id) | - initWithCapacity: |
Initialize a new text buffer. | |
(id) | - initWithText: |
Initialize a new text buffer. | |
Static Public Member Functions | |
(id) | + textBuffer |
Create and return a new, empty text buffer. | |
(id) | + textBufferWithText: |
Create and return a new text buffer that holds a copy of the give text object. | |
Protected Attributes | |
olchar * | begin |
The array of characters under control of this object. | |
unsigned | capacity |
The capacity of the array. | |
unsigned | size |
The size of the array. |
OLTextBuffer is like a mutable version of OLText. It is meant to be used when manipulating text, but not to be treated as a mutable replacement for OLText. The usage model would be something like, create a OLTextBuffer instance, build the desired sequence of characters, then convert it to OLText with the text (OLTextBuffer) method for general use, archiving or streaming.
OLTextBuffer* buffer = [[OLTextBuffer alloc] init]; [buffer [[appendText: [OLText textWithCString: "You're cute"]] appendChar: OL_EXCLAMATION_CHAR]];
- (OLTextBuffer*) appendChar: | (olchar) | ch |
Append a character.
The given character will be appended to the current array.
ch | the character to append |
- (OLTextBuffer*) appendChars: | (const olchar *) | chars | ||
fromOffset: | (unsigned) | offset | ||
count: | (unsigned) | num | ||
Append some characters.
A span of characters from the array chars starting at offset offset and extending num characters will be appended to the current array.
chars | the array from which to copy characters | |
offset | the offset from which to start copying | |
num | the number of characters to append |
- (OLTextBuffer*) appendText: | (OLText *) | text |
Append a text object.
All the characters of the given object will be appended to this array.
text | the text to append |
- (OLTextBuffer*) appendTextBuffer: | (OLTextBuffer *) | buffer |
Append another text buffer.
All the characters of the given buffer will be appended to this array.
buffer | the buffer to append |
- (OLTextBuffer*) assignAt: | (unsigned) | index | ||
character: | (olchar) | ch | ||
Assign a character.
The character at index is replaced.
index | the index at which to replace the value of the character | |
ch | the new character for index |
- (olchar) at: | (unsigned) | index |
Return the character at index.
index | the index of the character to return |
- (unsigned) capacity |
Return the capacity of this buffer.
- (void) clear |
Erase all characters.
- (int) compare: | (id) | other |
Compare this object to another.
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 text buffer.
- (BOOL) empty |
Return whether this text buffer is empty.
- (OLTextBuffer*) eraseAt: | (unsigned) | index |
Erase a character.
The character at the given index will be erased and the indices of all subsequent characters will be shifted down one position.
index | the index at which to erase |
- (OLTextBuffer*) eraseFromOffset: | (unsigned) | offset | ||
count: | (unsigned) | num | ||
Erase a group of characters.
The given number of characters starting at the given offset will be removed.
offset | the offset from which to erase | |
num | the number of characters to erase |
- (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 buffer 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 buffer 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 buffer 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 buffer 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 buffer 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 |
Free all memory allocated by this buffer and destroy the object.
- (void) getCharacters: | (olchar *) | buffer | ||
fromOffset: | (unsigned) | offset | ||
count: | (unsigned) | num | ||
Extract a range of characters.
A range of characters from this text buffer is copied to a buffer.
buffer | the destination buffer | |
offset | the starting offset | |
num | the number of characters to copy |
- (id) init |
Initialize a new text buffer.
The resuling buffer contains no text. The buffer will have an initial capacity of 32 characters. This will grow as needed.
- (id) initWithCapacity: | (unsigned) | cap |
Initialize a new text buffer.
The resuling buffer contains no text. The buffer will have an initial capacity of cap characters. This will grow as needed.
cap | the capacity with which to start |
- (id) initWithText: | (OLText *) | text |
Initialize a new text buffer.
The buffer will start with a copy of the given text.
text | the text to copy into the buffer |
- (OLTextBuffer*) insertChar: | (olchar) | ch | ||
atOffset: | (unsigned) | offset | ||
Insert a character.
The given character is inserted at the given offset and the indices of all subsequent characters are shifted up by one.
ch | the character to insert | |
offset | the offset at which to insert ch |
- (OLTextBuffer*) insertChars: | (const olchar *) | chars | ||
atOffset: | (unsigned) | offset | ||
count: | (unsigned) | num | ||
Insert an array of characters.
The given number of haracters from the given array are inserted from the given offset.
chars | the array from which to copy characters | |
offset | the index in chars from which to start copying | |
num | the number of characters to insert |
- (OLTextBuffer*) insertText: | (OLText *) | text | ||
atOffset: | (unsigned) | offset | ||
Insert a chunk of text.
The given text is inserted into the buffer at the given offset.
text | the text object to insert | |
offset | the offset at which to insert the characters from text |
- (BOOL) isEqual: | (id) | object |
Return whether this text buffer is equal to another one.
This message returns YES if compare: returns zero.
object | the object to test |
- (unsigned) length |
Return the length of the text buffer.
This is message returns the same value as size. The number of characters controlled by the buffer is returned, not the capacity.
- (OLTextBuffer*) replaceFromOffset: | (unsigned) | offset | ||
count: | (unsigned) | num | ||
withText: | (OLText *) | text | ||
Replace a range of characters.
The given number of characters are replaced from the given offset with the given text object.
offset | the starting offset of the characters to replace | |
num | the number of characters to replace | |
text | the text to insert as a replacement |
- (void) reserve: | (unsigned) | cap |
Ensure that the capacity of the text buffer is at least of a certain size.
After sending this message the capacity of the text buffer will be no less than the given value.
cap | the new desired capacity |
- (OLTextBuffer*) resize: | (unsigned) | newLength | ||
filledWith: | (olchar) | ch | ||
Resize the text buffer.
If the given size is greater than the current size, not the current capacity, then the remainder will be filled with the given character. If the give size is less than the current size, then the size will be truncated.
newLength | the new size of the text buffer | |
ch | the character with which to fill the empty space if the new size is greater than the current size |
- (OLTextBuffer*) reverse |
Reverse the order of characters.
After sending this message the characters will be in reverse order from the order in which they were before.
- (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 buffer.
ch | the character for which to search | |
offset | the offset from which to start |
- (unsigned) size |
Return the size of the text buffer.
This is message returns the same value as length. The number of characters controlled by the buffer is returned, not the capacity.
- (OLText*) substrFromOffset: | (unsigned) | offset | ||
count: | (unsigned) | num | ||
Extract a subsequence.
A new text object is created from the indicated subsequence of this one.
No range checking is performed on the validity of the arguments passed.
offset | the offset from which to start the new object | |
num | the number of characters in the new object |
- (OLText*) text |
Return the text.
All of the text controlled by this buffer will be used to create a new text object.
+ (id) textBuffer |
Create and return a new, empty text buffer.
+ (id) textBufferWithText: | (OLText *) | text |
Create and return a new text buffer that holds a copy of the give text object.
text | the text to copy into this buffer |
- (unsigned) capacity [protected] |
The capacity of the array.
- (unsigned) size [protected] |
The size of the array.
|