![]() |
The Simons
|
#include <String.h>
Inheritance diagram for String:
A String is a kind of Sequence that stores all of its Character elements in a compact memory block. A String is most efficient for reading, writing, searching and concatenating blocks of text. Individual Character elements may be inserted or removed individually, but this is less efficient, using general Sequence methods. A String is indexed from 0..n-1 where n is the size() of the String. The memory used to store elements may expand to accommodate more elements. A String may be constructed from a literal Character string and from all the basic types. A String may be converted back to values of basic types. A String may be searched for single Characters, substrings and bags of Characters.
Public Member Functions | |
String () | |
Construct an empty String. | |
virtual | ~String () |
Destroy and release a String. | |
String (const Character *) | |
Construct a String from a Character array. | |
String (CollectionID) | |
Copy a String from a Collection of Characters. | |
String (Boolean) | |
Construct a String from a Boolean. | |
String (Character) | |
Construct a String from a Character. | |
String (Natural) | |
Construct a String from a Natural. | |
String (Integer) | |
Construct a String from an Integer. | |
String (Decimal, Natural=5) | |
Construct a String from a Decimal. | |
virtual ObjectID | clone () const |
Clone a deep copy of this String. | |
virtual Natural | hash () const |
Return a quasi-unique hash code for this String. | |
virtual Order | compare (ObjectID) const |
Compare this String with another Object. | |
Order | compare (StringID) const |
Compare this String with another String. | |
virtual Void | readOn (ReaderID) |
Read this String on a Reader stream. | |
virtual Void | writeOn (WriterID) const |
Write this String on a Writer stream. | |
virtual Natural | size () const |
Return the size of this String. | |
virtual ObjectID | getAt (Integer) const |
Return the ith Character of this String as an Object. | |
virtual Void | putAt (Integer, ObjectID) |
Replace a Character, supplied as an Object, at the ith index position. | |
virtual Void | addAt (Integer, ObjectID) |
Insert a Character, supplied as an Object, at the ith index position. | |
virtual Void | removeAt (Integer) |
Remove the Character at the ith index position. | |
Boolean | has (Character) const |
Test if this String contains a given Character. | |
virtual Boolean | has (ObjectID) const |
Test if this String contains a given Character, supplied as an Object. | |
Void | addAll (StringID) |
Add all the elements of another String to this String. | |
virtual Void | addAll (CollectionID) |
Add all the elements of another Collection to this String. | |
Character | getValue (Integer) const |
Return the ith Character in a String. | |
Void | putValue (Integer, Character) |
Replace the Character at the ith index position. | |
Integer | indexOf (Character, Integer=0) const |
Find the next index of a Character in this String after a given index. | |
Integer | indexOfString (StringID, Integer=0) const |
Find the next index of a substring in this String after a given index. | |
Integer | indexOfBag (StringID, Integer=0) const |
Find the next index of a Character bag in this String, after a given index. | |
StringID | subString (Integer) const |
Return a substring starting at an index. | |
StringID | subString (Integer, Natural) const |
Return a substring of a given length starting at an index. | |
Boolean | toBoolean () const |
Convert String contents to a Boolean value. | |
Character | toCharacter () const |
Convert String contents to a Character value. | |
Natural | toNatural () const |
Convert String contents to a Natural value. | |
Integer | toInteger () const |
Convert String contents to an Integer value. | |
Decimal | toDecimal () const |
Convert String contents to a Decimal value. | |
const Character * | value () const |
Return the Character array encapsulated in this String. | |
Protected Member Functions | |
String (const String &) | |
Copy another String. | |
String (const String &, Natural) | |
Copy a prefix of another String. |
|
Copy another String. Allocates sufficient capacity to hold all the contents of the other String and takes a deep copy of the primitive Character array managed by the other String, setting the terminating null byte at index size(). Required by C++ and used by other public String methods.
|
|
Copy a prefix of another String. Allocates sufficient capacity to hold the requested prefix of the other String and copies that number of Character elements from the other String, setting the terminating null byte at index size(). Used by the subString() method.
|
|
Construct an empty String. Does not allocate any storage, but sets the internal primitive Character pointer to refer to a static array containing the empty character string.
|
|
Destroy and release a String. If this String allocated some storage, deletes the primitive Character array managed by this String. If this String was empty and referred to the static empty character string, does nothing. |
|
Construct a String from a Character array. Allocates sufficient capacity to hold all the contents of the primitive array and copies the array's contents, setting the terminating null byte at index size(). This is the standard constructor for initialising String objects from literal Character data.
|
|
Copy a String from a Collection of Characters. Does not initially allocate any storage, but constructs an empty String, then calls addAll() to include the contents of the other Collection, which is expected to contain Characters. If this is the case, this String allocates sufficient capacity to store the contents of the other Collection and copies its Characters. Otherwise, a TypeFailure exception is raised on this String, which remains empty.
|
|
Construct a String from a Boolean. Converts a Boolean into the String "true" or "false". Allocates storage exactly and sets the terminating null byte.
|
|
Construct a String from a Character. Converts a Character into a unit length String containing the Character. Allocates storage exactly and sets the terminating null byte.
|
|
Construct a String from a Natural. Converts a Natural number into its String representation. Allocates storage exactly and sets the terminating null byte. Implementation note: assumes that no representable number will exceed 20 characters in length.
|
|
Construct a String from an Integer. Converts an Integer number into its String representation. Allocates storage exactly and sets the terminating null byte. Implementation note: assumes that no representable number will exceed 20 characters in length.
|
|
Construct a String from a Decimal. Converts a Decimal number into its String representation, rounding to a given number of decimal places. Rounds to 5 decimal places by default, with a maximum precision of 9 places. Truncates any trailing zeros in the fractional part. Allocates sufficient storage to hold the sign, the decimal point, and the integral and fractional parts of the number. Sets the terminating null byte. Implementation note: assumes that no integral number will exceed 20 characters in length.
|
|
Add all the elements of another Collection to this String. If the other Collection is a String, concatenates the String's contents directly, after adjusting the capacity of this String to accommodate the other String's contents. Otherwise, iterates over the elements of the other Collection using item() up to the limit size() and uses add() to insert individual elements into this String. Raises a TypeFailure exception if any element of the other Collection is not a CharacterBox, but preserves the state of this String immediately prior to the failure.
Reimplemented from Collection. |
|
Add all the elements of another String to this String. This method is highly efficient. If this String has sufficient capacity, concatenates the other String's contents directly. Otherwise, doubles the capacity until this exceeds the required capacity and concatenates the other String's contents. Implementation note: this method is safe even if this and the other String are identical.
|
|
Insert a Character, supplied as an Object, at the ith index position. Part of the Sequence protocol, this method allows a String to be treated like a Sequence of Objects. The argument must be a CharacterBox. All existing Characters from the index position to the end of the String are moved up by one position and the new Character is inserted at the vacant index position. If the capacity of the String is exceeded, a larger memory block is allocated. Raises an OutOfRange exception if the index is out of range.
Reimplemented from Sequence. |
|
Clone a deep copy of this String. This returns a deep copy, rather than the default shallow copy, so that clients may freely modify the returned String.
Reimplemented from Object. |
|
Compare this String with another String. Lexicographic comparison, based on the alphabetical order of the two Strings. This String is considered LESS than, EQUAL to, or MORE than the other String if it appears before, in the same place, or after the other in the alphabet, respectively.
|
|
Compare this String with another Object. Generic comparison that tries to convert the other Object into a String and then proceeds to compare according to the lexicographic ordering of characters. If the other Object is not a String, the comparison is undefined and the result is NONE.
Reimplemented from Sequence. |
|
Return the ith Character of this String as an Object. Part of the Sequence protocol, this method allows a String to be treated like a Sequence of Objects. The result is wrapped in a CharacterBox. Raises an OutOfRange exception if the index is out of range.
Reimplemented from Sequence. |
|
Return the ith Character in a String. This returns the simple Character value directly. May raise an OutOfRange exception if the index is out of range.
|
|
Test if this String contains a given Character, supplied as an Object. Part of the Collection protocol, this method allows a String to be treated just like any other Collection. The argument must be a CharacterBox. Otherwise, a TypeFailure exception is raised.
Reimplemented from Collection. |
|
Test if this String contains a given Character. Scans the String in linear time searching for the Character.
|
|
Return a quasi-unique hash code for this String. Uses the famous P J Weinberger hashing algorithm from Aho, Sethi and Ullman, p 436. The result is based both on the value and the ordering of the Characters. For each Character, the result so far is shifted left by 4 bits, then the next Character ASCII code is added. If this sets any of the four high-order bits, these are stripped, shifted right by 24 bits and XORed with the result.
Reimplemented from Sequence. |
|
Find the next index of a Character in this String after a given index. Searches for the Character in this String starting at the given index. If the starting index is omitted, this defaults to 0 and the search is from the beginning of this String.
|
|
Find the next index of a Character bag in this String, after a given index. If the starting index is omitted, this defaults to 0 and the search is from the beginning of this String.
|
|
Find the next index of a substring in this String after a given index. Searches for a substring in this String starting at the given index. If the starting index is omitted, this defaults to 0 and the search is from the beginning of this String.
|
|
Replace a Character, supplied as an Object, at the ith index position. Part of the Sequence protocol, this method allows a String to be treated like a Sequence of Objects. The argument must be a CharacterBox. Otherwise, a TypeFailure exception is raised and this String is not modified. Raises an OutOfRange exception if the index is out of range.
Reimplemented from Sequence. |
|
Replace the Character at the ith index position. The argument is a simple Character. May raise an OutOfRange exception if the index is out of range.
|
|
Read this String on a Reader stream. String is a leaf-Object in any Object cluster. It determines its size from the Reader, then allocates a block large enough to hold that number of Character s and reads them in as a single block.
Reimplemented from Collection. |
|
Remove the Character at the ith index position. Part of the Sequence protocol, this method allows a String to be treated like any other Sequence of Objects. All existing characters from the index+1 position to the end of the String are moved down by one position. The removed Character is overwritten. May raise an OutOfRange exception if the index is out of range.
Reimplemented from Sequence. |
|
Return the size of this String. Returns the active String length, which is the number of Character elements up to, but not including, the terminating null byte.
Reimplemented from Collection. |
|
Return a substring of a given length starting at an index. If the index is valid, creates a new String which copies this String's Character sequence starting from the index position, for at most the requested Character count. If this String is shorter, copies to the end of this String.
|
|
Return a substring starting at an index. If the index is valid, creates a new String which copies this String's Character sequence from the index position to the end of this String. Otherwise, raises an OutOfRange exception.
|
|
Convert String contents to a Boolean value. Succeeds if this String does indeed represent a Boolean value, otherwise raises a TypeFailure exception.
Reimplemented from Object. |
|
Convert String contents to a Character value. Succeeds if this String does indeed store a single Character value, otherwise raises a TypeFailure exception.
Reimplemented from Object. |
|
Convert String contents to a Decimal value. Succeeds if this String does indeed represent a Decimal value, otherwise raises a TypeFailure exception.
Reimplemented from Object. |
|
Convert String contents to an Integer value. Succeeds if this String does indeed represent an Integer value, otherwise raises a TypeFailure exception.
Reimplemented from Object. |
|
Convert String contents to a Natural value. Succeeds if this String does indeed represent a Natural value, otherwise raises a TypeFailure exception.
Reimplemented from Object. |
|
Return the Character array encapsulated in this String. This method is not intended to be used by clients, but is provided so that Stream classes, such as TextOutput, can access the primitive data. Note that the returned primitive Character array is constant.
|
|
Write this String on a Writer stream. String is a leaf-Object in any Object cluster. It expects the Writer to encode its size in the header then writes its Character s out as a single block.
Reimplemented from Collection. |