activemq-cpp-3.9.0
decaf::lang::String Class Reference

An immutable sequence of characters. More...

#include <src/main/decaf/lang/String.h>

Inheritance diagram for decaf::lang::String:

Public Member Functions

 String ()
 Creates a new empty String object. More...
 
 String (const char value, int count)
 Create a new String instance that contains N copies of the given character value. More...
 
 String (const String &source)
 Create a new String object that represents the given STL string. More...
 
 String (const std::string &source)
 Create a new String object that represents the given STL string. More...
 
 String (const char *array)
 Create a new String object that represents the given array of characters, the C string must be null terminated in order for a proper size calculation to work. More...
 
 String (const char *array, int size)
 Create a new String object that represents the given array of characters. More...
 
 String (const char *array, int offset, int length)
 Create a new String object that represents the given array of characters, the C string must be null terminated in order for a proper size calculation to work. More...
 
 String (const char *array, int size, int offset, int length)
 Create a new String object that represents the given array of characters. More...
 
virtual ~String ()
 
Stringoperator= (const String &other)
 Assignment from another String instance. More...
 
Stringoperator= (const std::string &other)
 Assignment from another std::string instance. More...
 
Stringoperator= (const char *other)
 Assignment from another C string instance. More...
 
bool operator== (const char *other) const
 Comparison operators for the various string types that uses the equals method to determine equality. More...
 
bool operator== (const String &other) const
 
bool operator== (const std::string &other) const
 
bool operator!= (const char *other) const
 Comparison operators for the various string types that uses the equals method to determine equality. More...
 
bool operator!= (const String &other) const
 
bool operator!= (const std::string &other) const
 
bool operator< (const char *other) const
 Comparison operators for the various string types that uses the compareTo method to determine if the string is lexicographically less than the other. More...
 
bool operator< (const String &other) const
 
bool operator< (const std::string &other) const
 
bool operator<= (const char *other) const
 Comparison operators for the various string types that uses the compareTo method to determine if the string is lexicographically less than or equal to the other. More...
 
bool operator<= (const String &other) const
 
bool operator<= (const std::string &other) const
 
bool operator> (const char *other) const
 Comparison operators for the various string types that uses the compareTo method to determine if the string is lexicographically greater than the other. More...
 
bool operator> (const String &other) const
 
bool operator> (const std::string &other) const
 
bool operator>= (const char *other) const
 Comparison operators for the various string types that uses the compareTo method to determine if the string is lexicographically greater than or equal to the other. More...
 
bool operator>= (const String &other) const
 
bool operator>= (const std::string &other) const
 
String operator+ (const String &other) const
 Concatenation operators for the various string types. More...
 
String operator+ (const std::string &other) const
 
String operator+ (const char *other) const
 
const char * c_str () const
 Returns a const char* value to allow easier coexistence with standard c++ string operations. More...
 
String compact () const
 If the String instance is holding a reference to a character array that is larger than the string's view of the backing store a new array is allocated and the characters from the substring this String represents are copied to the new backing store and returned in the resulting String object. More...
 
int compareTo (const String &string) const
 Compares two strings lexicographically. More...
 
int compareTo (const std::string &string) const
 Compares two strings lexicographically. More...
 
int compareTo (const char *string) const
 Compares two strings lexicographically. More...
 
int compareToIgnoreCase (const String &string) const
 Compares two strings lexicographically, ignoring case differences. More...
 
int compareToIgnoreCase (const std::string &string) const
 Compares two strings lexicographically, ignoring case differences. More...
 
int compareToIgnoreCase (const char *string) const
 Compares two strings lexicographically, ignoring case differences. More...
 
String concat (const String &string) const
 Concatenates this string and the specified string. More...
 
String concat (const std::string &string) const
 Concatenates this string and the specified std::string. More...
 
String concat (const char *string) const
 Concatenates this string and the specified C string. More...
 
bool contains (const String &string) const
 Determines if this String contains the sequence of characters in the String passed in. More...
 
bool contains (const std::string &string) const
 Determines if this String contains the sequence of characters in the std::string passed in. More...
 
bool contains (const char *string) const
 Determines if this String contains the sequence of characters in the C String passed in. More...
 
bool endsWith (const String &suffix) const
 Compares the specified string to this string to determine if the specified string is a suffix. More...
 
bool equals (const String &other) const
 Returns true if this String is equal to the given String instance. More...
 
bool equals (const std::string &other) const
 Returns true if this String is equal to the given std::string instance. More...
 
bool equals (const char *other) const
 Returns true if this String is equal to the given C string instance. More...
 
bool equalsIgnoreCase (const String &string) const
 Compares the specified string to this string ignoring the case of the characters and returns true if they are equal. More...
 
bool equalsIgnoreCase (const std::string &string) const
 Compares the specified std::string to this String ignoring the case of the characters and returns true if they are equal. More...
 
bool equalsIgnoreCase (const char *string) const
 Compares the specified C string to this string ignoring the case of the characters and returns true if they are equal. More...
 
int findFirstOf (const String &chars) const
 Searches in this string for the first index of any character in the specified String. More...
 
int findFirstOf (const String &chars, int start) const
 Searches in this string for the first index of any character in the specified String. More...
 
int findFirstNotOf (const String &chars) const
 Searches in this string for the first index of any character that is not in the specified String. More...
 
int findFirstNotOf (const String &chars, int start) const
 Searches in this string for the first index of any character that is not in the specified String. More...
 
void getChars (int srcBegin, int srcEnd, char *dest, int destSize, int destBegin) const
 Copies characters from this String into the destination char array, starting from the given index. More...
 
int hashCode () const
 Returns a hash code for this String instance, the hash code for an empty String will always be zero. More...
 
int indexOf (char value) const
 Searches in this string for the first index of the specified character. More...
 
int indexOf (char value, int start) const
 Searches in this string for the index of the specified character. More...
 
int indexOf (const String &string) const
 Searches in this string for the first index of the specified string. More...
 
int indexOf (const String &subString, int start) const
 Searches in this string for the index of the specified string. More...
 
int indexOf (const std::string &string) const
 Searches in this String for the first index of the specified std::string. More...
 
int indexOf (const std::string &subString, int start) const
 Searches in this string for the index of the specified std::string. More...
 
int indexOf (const char *string) const
 Searches in this String for the first index of the specified C string. More...
 
int indexOf (const char *subString, int start) const
 Searches in this string for the index of the specified C string. More...
 
bool isEmpty () const
 
int lastIndexOf (char value) const
 Searches in this string for the last index of the specified character. More...
 
int lastIndexOf (char value, int start) const
 Searches in this string for the index of the specified character. More...
 
int lastIndexOf (const String &string) const
 Searches in this string for the last index of the specified string. More...
 
int lastIndexOf (const String &subString, int start) const
 Searches in this string for the index of the specified string. More...
 
int lastIndexOf (const std::string &string) const
 Searches in this string for the last index of the specified std::string. More...
 
int lastIndexOf (const std::string &subString, int start) const
 Searches in this string for the index of the specified std::string. More...
 
int lastIndexOf (const char *string) const
 Searches in this string for the last index of the specified C string. More...
 
int lastIndexOf (const char *subString, int start) const
 Searches in this string for the index of the specified C string. More...
 
bool regionMatches (int thisStart, const String &string, int start, int length) const
 Compares the specified string to this string and compares the specified range of characters to determine if they are the same. More...
 
bool regionMatches (bool ignoreCase, int thisStart, const String &string, int start, int length) const
 Compares the specified string to this string and compares the specified range of characters to determine if they are the same. More...
 
String replace (char oldChar, char newChar) const
 Copies this string replacing occurrences of the specified character with another character. More...
 
bool startsWith (const String &prefix) const
 Compares the specified string to this string to determine if the specified string is a prefix. More...
 
bool startsWith (const String &prefix, int start) const
 Compares the specified string to this string, starting at the specified offset, to determine if the specified string is a prefix. More...
 
String substring (int start) const
 Copies a range of characters into a new string starting from the given offset and extending to the end of this String. More...
 
String substring (int start, int end) const
 Copies a range of characters into a new string. More...
 
char * toCharArray () const
 Copies the characters in this string to a newly allocated character array. More...
 
String toLowerCase () const
 Converts the characters in this string to lower case. More...
 
String toUpperCase () const
 Converts the characters in this string to upper case. More...
 
String trim () const
 Returns a copy of the string, with leading and trailing whitespace omitted. More...
 
virtual int length () const
 
Returns
the length of the underlying character sequence.
More...
 
virtual char charAt (int index) const
 Returns the Char at the specified index so long as the index is not greater than the length of the sequence.
Parameters
indexThe position to return the char at.
Returns
the char at the given position.
Exceptions
IndexOutOfBoundsExceptionif index is > than length() or negative
More...
 
virtual CharSequencesubSequence (int start, int end) const
 Returns a new CharSequence that is a subsequence of this sequence.The subsequence starts with the char value at the specified index and ends with the char value at index end - 1. The length (in chars) of the returned sequence is end - start, so if start == end then an empty sequence is returned.
Parameters
startThe start index, inclusive.
endThe end index, exclusive.
Returns
a new CharSequence
Exceptions
IndexOutOfBoundsExceptionif start or end > length() or start or end are negative.
More...
 
virtual std::string toString () const
 
Returns
the String representation of this CharSequence
More...
 
- Public Member Functions inherited from decaf::lang::CharSequence
virtual ~CharSequence ()
 

Static Public Member Functions

static String copyValueOf (const char *data)
 Creates a new string containing the characters in the specified character array. More...
 
static String copyValueOf (char *data, int start, int length)
 Creates a new string containing the specified characters in the character array. More...
 
static bool isNullOrEmpty (const char *)
 Given a C String pointer return true if the value is either NULL or the string contained is empty. More...
 
static String valueOf (bool value)
 Returns a String that represents the value of the given boolean value. More...
 
static String valueOf (char value)
 Returns a String that represents the value of the given char value. More...
 
static String valueOf (float value)
 Returns a String that represents the value of the given float value. More...
 
static String valueOf (double value)
 Returns a String that represents the value of the given double value. More...
 
static String valueOf (short value)
 Returns a String that represents the value of the given short value. More...
 
static String valueOf (int value)
 Returns a String that represents the value of the given integer value. More...
 
static String valueOf (long long value)
 Returns a String that represents the value of the given 64bit long value. More...
 

Friends

class AbstractStringBuilder
 

Detailed Description

An immutable sequence of characters.

This class is implemented using a char[]. The length of the array may exceed the length of the string. For example, the string "Hello" may be backed by the array

['H', 'e', 'l', 'l', 'o', 'W'. 'o', 'r', 'l', 'd']

with offset 0 and length 5.

Multiple strings can share the same char[] because strings are immutable.

The substring method always returns a string that shares the backing array of its source string. Generally this is an optimization: fewer character arrays need to be allocated, and less copying is necessary. But this can also lead to unwanted heap retention. Taking a short substring of long string means that the long shared char[] won't be garbage until both strings are destroyed. This typically happens when parsing small substrings out of a large input. To avoid this where necessary, call the compact method which allocates a new array that is just big enough to store the String's content.

Since
1.0

Constructor & Destructor Documentation

decaf::lang::String::String ( )

Creates a new empty String object.

This value is equivalent to calling String("") and all methods will behave as if the string is an empty string.

decaf::lang::String::String ( const char  value,
int  count 
)

Create a new String instance that contains N copies of the given character value.

Parameters
valueThe character to fill this String with.
countThe number of copies of the character to fill.
Exceptions
IndexOutOfBoundsExceptionif the count parameter is negative.
decaf::lang::String::String ( const String source)

Create a new String object that represents the given STL string.

Parameters
sourceThe string to copy into this new String object.
decaf::lang::String::String ( const std::string &  source)

Create a new String object that represents the given STL string.

Parameters
sourceThe string to copy into this new String object.
decaf::lang::String::String ( const char *  array)

Create a new String object that represents the given array of characters, the C string must be null terminated in order for a proper size calculation to work.

If the string is not properly terminated than this method can overrun the array and cause a fault.

Parameters
arrayThe character buffer to copy into this new String object.
Exceptions
NullPointerExceptionif the character array parameter is NULL.
decaf::lang::String::String ( const char *  array,
int  size 
)

Create a new String object that represents the given array of characters.

The method takes the size of the array as a parameter to allow for strings that are not NULL terminated, the caller can pass strlen(array) in the case where the array is properly NULL terminated.

Parameters
arrayThe character buffer to copy into this new String object.
sizeThe size of the string buffer given, in case the string is not NULL terminated.
Exceptions
NullPointerExceptionif the character array parameter is NULL.
IndexOutOfBoundsExceptionif the size parameter is negative.
decaf::lang::String::String ( const char *  array,
int  offset,
int  length 
)

Create a new String object that represents the given array of characters, the C string must be null terminated in order for a proper size calculation to work.

If the string is not properly terminated than this method can overrun the array and cause a fault.

Parameters
arrayThe character buffer to copy into this new String object.
offsetThe position to start copying from in the given buffer.
lengthThe number of bytes to copy from the given buffer starting from the offset.
Exceptions
NullPointerExceptionif the character array parameter is NULL.
IndexOutOfBoundsExceptionif the size, offset or length parameter is negative or if the length to copy is greater than the span of size - offset.
decaf::lang::String::String ( const char *  array,
int  size,
int  offset,
int  length 
)

Create a new String object that represents the given array of characters.

The method takes the size of the array as a parameter to allow for strings that are not NULL terminated, the caller can pass strlen(array) in the case where the array is properly NULL terminated.

Parameters
arrayThe character buffer to copy into this new String object.
sizeThe size of the string buffer given, in case the string is not NULL terminated.
offsetThe position to start copying from in the given buffer.
lengthThe number of bytes to copy from the given buffer starting from the offset.
Exceptions
NullPointerExceptionif the character array parameter is NULL.
IndexOutOfBoundsExceptionif the size, offset or length parameter is negative or if the length to copy is greater than the span of size - offset.
virtual decaf::lang::String::~String ( )
virtual

Member Function Documentation

const char* decaf::lang::String::c_str ( ) const

Returns a const char* value to allow easier coexistence with standard c++ string operations.

This method can result in a compaction of the String's backing store into a new character array in order to return a pointer value that is guaranteed to be NULL terminated.

Returns
a const char* value for this String.
virtual char decaf::lang::String::charAt ( int  index) const
virtual

Returns the Char at the specified index so long as the index is not greater than the length of the sequence.

Parameters
indexThe position to return the char at.
Returns
the char at the given position.
Exceptions
IndexOutOfBoundsExceptionif index is > than length() or negative

Implements decaf::lang::CharSequence.

String decaf::lang::String::compact ( ) const

If the String instance is holding a reference to a character array that is larger than the string's view of the backing store a new array is allocated and the characters from the substring this String represents are copied to the new backing store and returned in the resulting String object.

This can free up heap memory when a String is holding a large array but only viewing a small portion of it and the original source String is no longer also maintaining a reference to the backing store.

Returns
a new String instance with a compacted backing store.
int decaf::lang::String::compareTo ( const String string) const

Compares two strings lexicographically.

The comparison is based on the value of each character in the strings. The character sequence represented by this String is compared lexicographically to the character sequence represented by the provided string. The result is a negative number if this String lexicographically precedes the argument string. The result is a positive value if this String lexicographically follows the argument string. The result is zero if the strings are equal; compareTo returns 0 exactly when the equals method would return true.

Parameters
stringthe string to compare.
Returns
0 if the strings are equal, a negative integer if this string is before the specified string, or a positive integer if this string is after the specified string.
int decaf::lang::String::compareTo ( const std::string &  string) const

Compares two strings lexicographically.

The comparison is based on the value of each character in the strings. The character sequence represented by this String is compared lexicographically to the character sequence represented by the provided string. The result is a negative number if this String lexicographically precedes the argument string. The result is a positive value if this String lexicographically follows the argument string. The result is zero if the strings are equal; compareTo returns 0 exactly when the equals method would return true.

Parameters
stringthe STL string to compare.
Returns
0 if the strings are equal, a negative integer if this string is before the specified string, or a positive integer if this string is after the specified string.
int decaf::lang::String::compareTo ( const char *  string) const

Compares two strings lexicographically.

The comparison is based on the value of each character in the strings. The character sequence represented by this String is compared lexicographically to the character sequence represented by the provided string. The result is a negative number if this String lexicographically precedes the argument string. The result is a positive value if this String lexicographically follows the argument string. The result is zero if the strings are equal; compareTo returns 0 exactly when the equals method would return true.

Parameters
stringthe C string to compare.
Returns
0 if the strings are equal, a negative integer if this string is before the specified string, or a positive integer if this string is after the specified string.
Exceptions
NullPointerExceptionif the passed in C String value is NULL.
int decaf::lang::String::compareToIgnoreCase ( const String string) const

Compares two strings lexicographically, ignoring case differences.

This method returns an integer whose sign is that of calling compareTo with normalized versions of the strings where case differences have been eliminated by calling Character::toLowerCase() on each character.

Parameters
stringthe string to compare.
Returns
0 if the strings are equal, a negative integer if this string is before the specified string, or a positive integer if this string is after the specified string.
int decaf::lang::String::compareToIgnoreCase ( const std::string &  string) const

Compares two strings lexicographically, ignoring case differences.

This method returns an integer whose sign is that of calling compareTo with normalized versions of the strings where case differences have been eliminated by calling Character::toLowerCase() on each character.

Parameters
stringthe STL string to compare.
Returns
0 if the strings are equal, a negative integer if this string is before the specified string, or a positive integer if this string is after the specified string.
int decaf::lang::String::compareToIgnoreCase ( const char *  string) const

Compares two strings lexicographically, ignoring case differences.

This method returns an integer whose sign is that of calling compareTo with normalized versions of the strings where case differences have been eliminated by calling Character::toLowerCase() on each character.

Parameters
stringthe C string to compare.
Returns
0 if the strings are equal, a negative integer if this string is before the specified string, or a positive integer if this string is after the specified string.
Exceptions
NullPointerExceptionif the passed in C String value is NULL.
String decaf::lang::String::concat ( const String string) const

Concatenates this string and the specified string.

Parameters
stringthe string to concatenate onto this String
Returns
a new string which is the concatenation of this string and the specified string.
String decaf::lang::String::concat ( const std::string &  string) const

Concatenates this string and the specified std::string.

Parameters
stringthe STL string to concatenate onto this String
Returns
a new string which is the concatenation of this string and the specified string.
String decaf::lang::String::concat ( const char *  string) const

Concatenates this string and the specified C string.

Parameters
stringthe C string to concatenate onto this String
Returns
a new string which is the concatenation of this string and the specified string.
bool decaf::lang::String::contains ( const String string) const

Determines if this String contains the sequence of characters in the String passed in.

Parameters
stringthe String value to search for.
Returns
true if the sequence of characters are contained in this String, otherwise returns false.
bool decaf::lang::String::contains ( const std::string &  string) const

Determines if this String contains the sequence of characters in the std::string passed in.

Parameters
stringthe STL String value to search for.
Returns
true if the sequence of characters are contained in this String, otherwise returns false.
bool decaf::lang::String::contains ( const char *  string) const

Determines if this String contains the sequence of characters in the C String passed in.

If the value given is null the method always returns false.

Parameters
stringthe C String value to search for.
Returns
true if the sequence of characters are contained in this String, otherwise returns false.
static String decaf::lang::String::copyValueOf ( const char *  data)
static

Creates a new string containing the characters in the specified character array.

Modifying the character array after creating the string has no effect on the string.

Parameters
datathe array of characters.
Returns
the new string.
Exceptions
NullPointerExceptionif the C string pointer is NULL
static String decaf::lang::String::copyValueOf ( char *  data,
int  start,
int  length 
)
static

Creates a new string containing the specified characters in the character array.

Modifying the character array after creating the string has no effect on the string.

Parameters
datathe array of characters.
startthe starting offset in the character array.
lengththe number of characters to use.
Returns
the new string.
Exceptions
NullPointerExceptionif the C string is NULL
IndexOutOfBoundsExceptionif length < 0, start < 0 or start + length > the C string's length.
bool decaf::lang::String::endsWith ( const String suffix) const

Compares the specified string to this string to determine if the specified string is a suffix.

Parameters
suffixthe suffix to look for.
Returns
true if the specified string is a suffix of this string, false otherwise.
bool decaf::lang::String::equals ( const String other) const

Returns true if this String is equal to the given String instance.

Parameters
otherA String instance to compare to this string.
Returns
true if this String is equal to the given String instance.
bool decaf::lang::String::equals ( const std::string &  other) const

Returns true if this String is equal to the given std::string instance.

Parameters
otherA standard string instance to compare to this String.
Returns
true if this String is equal to the given std::string instance.
bool decaf::lang::String::equals ( const char *  other) const

Returns true if this String is equal to the given C string instance.

This method treats the NULL pointer case as equivalent to the empty string case and returns true if this String instance is also empty.

Parameters
otherA C string instance to compare to this String.
Returns
true if this String is equal to the given C string instance.
bool decaf::lang::String::equalsIgnoreCase ( const String string) const

Compares the specified string to this string ignoring the case of the characters and returns true if they are equal.

Parameters
stringthe string to compare.
Returns
true if the specified string is equal to this string, false otherwise.
bool decaf::lang::String::equalsIgnoreCase ( const std::string &  string) const

Compares the specified std::string to this String ignoring the case of the characters and returns true if they are equal.

Parameters
stringthe std::string to compare.
Returns
true if the specified string is equal to this String, false otherwise.
bool decaf::lang::String::equalsIgnoreCase ( const char *  string) const

Compares the specified C string to this string ignoring the case of the characters and returns true if they are equal.

Parameters
stringthe C string to compare.
Returns
true if the specified C string is equal to this string, false otherwise.
int decaf::lang::String::findFirstNotOf ( const String chars) const

Searches in this string for the first index of any character that is not in the specified String.

The search for the non-matching characters starts at the beginning and moves towards the end of this string.

Parameters
charsthe characters to find the first non-matching index of within this String.
Returns
the index of the first character not in the specified string in this string, -1 if all of the characters in the given String exist in this String.
int decaf::lang::String::findFirstNotOf ( const String chars,
int  start 
) const

Searches in this string for the first index of any character that is not in the specified String.

The search for the non-matching characters starts at the given index and moves towards the end of this string.

Parameters
charsthe characters to find the first non-matching index of within this String.
startthe starting offset.
Returns
the index of the first character not in the specified string in this string, -1 if all of the characters in the given String exist in this String.
int decaf::lang::String::findFirstOf ( const String chars) const

Searches in this string for the first index of any character in the specified String.

The search for the matching characters starts at the beginning and moves towards the end of this string.

Parameters
stringthe characters to find the first of within this String.
Returns
the index of the first character of the specified string in this string, -1 if none of the characters in the String exist in this String.
int decaf::lang::String::findFirstOf ( const String chars,
int  start 
) const

Searches in this string for the first index of any character in the specified String.

The search for the matching characters starts at the given index and moves towards the end of this string.

Parameters
charsthe characters to find the first of within this String.
startthe starting offset.
Returns
the index of the first character of the specified string in this string, -1 if none of the characters in the String exist in this String.
void decaf::lang::String::getChars ( int  srcBegin,
int  srcEnd,
char *  dest,
int  destSize,
int  destBegin 
) const

Copies characters from this String into the destination char array, starting from the given index.

Parameters
srcBeginStarting index in this String for the copy operation.
srcEndThe index at which the copy ends, this value is not copied.
destThe destination character array to copy the data to.
destSizeThe size of the destination array.
destBeginThe offset into the destination array to start copying to.
Exceptions
IndexOutOfBoundsExceptionif any of the following conditions are met: srcBegin or srcEnd are negative. srcBegin is greater than src end. srcEnd is greater than the length() destSize or destBegin are negative. destBegin + (srcEnd - srcBegin) is greater than destSize.
int decaf::lang::String::hashCode ( ) const

Returns a hash code for this String instance, the hash code for an empty String will always be zero.

Returns
a hash code for this String instance.
int decaf::lang::String::indexOf ( char  value) const

Searches in this string for the first index of the specified character.

The search for the character starts at the beginning and moves towards the end of this string.

Parameters
cthe character to find.
Returns
the index in this string of the specified character, -1 if the character isn't found.
int decaf::lang::String::indexOf ( char  value,
int  start 
) const

Searches in this string for the index of the specified character.

The search for the character starts at the specified offset and moves towards the end of this string.

If the start value given is less than zero the search starts at the beginning of the string. If the start value is greater than the length of the string minus one is returned.

Parameters
valuethe character to find.
startthe starting offset.
Returns
the index in this string of the specified character, -1 if the character isn't found.
int decaf::lang::String::indexOf ( const String string) const

Searches in this string for the first index of the specified string.

The search for the string starts at the beginning and moves towards the end of this string.

Parameters
stringthe string to find within this String.
Returns
the index of the first character of the specified string in this string, -1 if the specified string is not a substring.
int decaf::lang::String::indexOf ( const String subString,
int  start 
) const

Searches in this string for the index of the specified string.

The search for the string starts at the specified offset and moves towards the end of this string.

Parameters
subStringthe string to find within this String.
startthe starting offset.
Returns
the index of the first character of the specified string in this string, -1 if the specified string is not a substring.
int decaf::lang::String::indexOf ( const std::string &  string) const

Searches in this String for the first index of the specified std::string.

The search for the string starts at the beginning and moves towards the end of this string.

Parameters
stringthe STL string to find within this String.
Returns
the index of the first character of the specified string in this string, -1 if the specified string is not a substring.
int decaf::lang::String::indexOf ( const std::string &  subString,
int  start 
) const

Searches in this string for the index of the specified std::string.

The search for the string starts at the specified offset and moves towards the end of this string.

Parameters
subStringthe STL string to find within this String.
startthe starting offset.
Returns
the index of the first character of the specified string in this string, -1 if the specified string is not a substring.
int decaf::lang::String::indexOf ( const char *  string) const

Searches in this String for the first index of the specified C string.

The search for the string starts at the beginning and moves towards the end of this string. If the given string pointer is NULL this method returns -1.

Parameters
stringthe C string to find within this String.
Returns
the index of the first character of the specified string in this string, -1 if the specified string is not a substring.
int decaf::lang::String::indexOf ( const char *  subString,
int  start 
) const

Searches in this string for the index of the specified C string.

The search for the string starts at the specified offset and moves towards the end of this string. If the given string pointer is NULL this method returns -1.

Parameters
subStringthe C string to find within this String.
startthe starting offset.
Returns
the index of the first character of the specified string in this string, -1 if the specified string is not a substring.
bool decaf::lang::String::isEmpty ( ) const
Returns
true if the length of this String is zero.
static bool decaf::lang::String::isNullOrEmpty ( const char *  )
static

Given a C String pointer return true if the value is either NULL or the string contained is empty.

Returns
true if the C string is either a NULL or an Empty string.
int decaf::lang::String::lastIndexOf ( char  value) const

Searches in this string for the last index of the specified character.

The search for the character starts at the end and moves towards the beginning of this string.

Parameters
valuethe character to find.
Returns
the index in this string of the specified character, -1 if the character isn't found.
int decaf::lang::String::lastIndexOf ( char  value,
int  start 
) const

Searches in this string for the index of the specified character.

The search for the character starts at the specified offset and moves towards the beginning of this string.

Parameters
valuethe character to find.
startthe starting offset.
Returns
the index in this string of the specified character, -1 if the character isn't found.
int decaf::lang::String::lastIndexOf ( const String string) const

Searches in this string for the last index of the specified string.

The search for the string starts at the end and moves towards the beginning of this string.

Parameters
stringthe string to find.
Returns
the index of the first character of the specified string in this string, -1 if the specified string is not a substring.
int decaf::lang::String::lastIndexOf ( const String subString,
int  start 
) const

Searches in this string for the index of the specified string.

The search for the string starts at the specified offset and moves towards the beginning of this string.

Parameters
subStringthe string to find.
startthe starting offset.
Returns
the index of the first character of the specified string in this string , -1 if the specified string is not a substring.
int decaf::lang::String::lastIndexOf ( const std::string &  string) const

Searches in this string for the last index of the specified std::string.

The search for the string starts at the end and moves towards the beginning of this string.

Parameters
stringthe STL string to find.
Returns
the index of the first character of the specified string in this string, -1 if the specified string is not a substring.
int decaf::lang::String::lastIndexOf ( const std::string &  subString,
int  start 
) const

Searches in this string for the index of the specified std::string.

The search for the string starts at the specified offset and moves towards the beginning of this string.

Parameters
subStringthe STL string to find.
startthe starting offset.
Returns
the index of the first character of the specified string in this string , -1 if the specified string is not a substring.
int decaf::lang::String::lastIndexOf ( const char *  string) const

Searches in this string for the last index of the specified C string.

The search for the string starts at the end and moves towards the beginning of this string.

Parameters
stringthe C string to find.
Returns
the index of the first character of the specified string in this string, -1 if the specified string is not a substring.
int decaf::lang::String::lastIndexOf ( const char *  subString,
int  start 
) const

Searches in this string for the index of the specified C string.

The search for the string starts at the specified offset and moves towards the beginning of this string.

Parameters
subStringthe C string to find.
startthe starting offset.
Returns
the index of the first character of the specified string in this string , -1 if the specified string is not a substring.
virtual int decaf::lang::String::length ( ) const
virtual

Returns
the length of the underlying character sequence.

Implements decaf::lang::CharSequence.

bool decaf::lang::String::operator!= ( const char *  other) const

Comparison operators for the various string types that uses the equals method to determine equality.

Parameters
otherThe string value to compare to this one.
Returns
true if the other string is not equal to this one, false otherwise.
bool decaf::lang::String::operator!= ( const String other) const
bool decaf::lang::String::operator!= ( const std::string &  other) const
String decaf::lang::String::operator+ ( const String other) const

Concatenation operators for the various string types.

The value of this string and the given string are concatenated and returned in a new String instance.

Parameters
otherThe string whose value is to be concatenated with this one.
Returns
a new String instance that is the concatenation of the two strings.
String decaf::lang::String::operator+ ( const std::string &  other) const
String decaf::lang::String::operator+ ( const char *  other) const
bool decaf::lang::String::operator< ( const char *  other) const

Comparison operators for the various string types that uses the compareTo method to determine if the string is lexicographically less than the other.

Parameters
otherThe string value to compare to this one.
Returns
true if this string is lexicographically less than the other string.
bool decaf::lang::String::operator< ( const String other) const
bool decaf::lang::String::operator< ( const std::string &  other) const
bool decaf::lang::String::operator<= ( const char *  other) const

Comparison operators for the various string types that uses the compareTo method to determine if the string is lexicographically less than or equal to the other.

Parameters
otherThe string value to compare to this one.
Returns
true if this string is lexicographically less than or equal to the other string.
bool decaf::lang::String::operator<= ( const String other) const
bool decaf::lang::String::operator<= ( const std::string &  other) const
String& decaf::lang::String::operator= ( const String other)

Assignment from another String instance.

The internal contents of this string now reference the same contents as the provided String. The original contents of this String are not altered in other String instances that reference it.

Parameters
otherThe other String to assign to this instance.
Returns
a reference to this string with the new contents.
String& decaf::lang::String::operator= ( const std::string &  other)

Assignment from another std::string instance.

The internal contents of this string now reference a copy of the contents as the provided std::string. The original contents of this String are not altered in other String instances that reference it.

Parameters
otherThe other std::string to assign to this instance.
Returns
a reference to this string with the new contents.
String& decaf::lang::String::operator= ( const char *  other)

Assignment from another C string instance.

The internal contents of this string now reference a copy of the contents as the provided C string. The original contents of this String are not altered in other String instances that reference it.

Parameters
otherThe other C string to assign to this instance.
Returns
a reference to this string with the new contents.
bool decaf::lang::String::operator== ( const char *  other) const

Comparison operators for the various string types that uses the equals method to determine equality.

Parameters
otherThe string value to compare to this one.
Returns
true if the other string is equal to this one, false otherwise.
bool decaf::lang::String::operator== ( const String other) const
bool decaf::lang::String::operator== ( const std::string &  other) const
bool decaf::lang::String::operator> ( const char *  other) const

Comparison operators for the various string types that uses the compareTo method to determine if the string is lexicographically greater than the other.

Parameters
otherThe string value to compare to this one.
Returns
true if this string is lexicographically greater than the other string.
bool decaf::lang::String::operator> ( const String other) const
bool decaf::lang::String::operator> ( const std::string &  other) const
bool decaf::lang::String::operator>= ( const char *  other) const

Comparison operators for the various string types that uses the compareTo method to determine if the string is lexicographically greater than or equal to the other.

Parameters
otherThe string value to compare to this one.
Returns
true if this string is lexicographically greater than the other string.
bool decaf::lang::String::operator>= ( const String other) const
bool decaf::lang::String::operator>= ( const std::string &  other) const
bool decaf::lang::String::regionMatches ( int  thisStart,
const String string,
int  start,
int  length 
) const

Compares the specified string to this string and compares the specified range of characters to determine if they are the same.

The method returns false is any of the index values are negative or result in a span that would exceed the length of either string.

Parameters
thisStartthe starting offset in this string.
stringthe string to compare.
startthe starting offset in the specified string.
lengththe number of characters to compare.
Returns
true if the ranges of characters are equal, false otherwise
bool decaf::lang::String::regionMatches ( bool  ignoreCase,
int  thisStart,
const String string,
int  start,
int  length 
) const

Compares the specified string to this string and compares the specified range of characters to determine if they are the same.

When ignoreCase is true, the case of the characters is ignored during the comparison.

Parameters
ignoreCasespecifies if case should be ignored.
thisStartthe starting offset in this string.
stringthe string to compare.
startthe starting offset in the specified string.
lengththe number of characters to compare.
Returns
true if the ranges of characters are equal, false otherwise.
String decaf::lang::String::replace ( char  oldChar,
char  newChar 
) const

Copies this string replacing occurrences of the specified character with another character.

Parameters
oldCharthe character to replace.
newCharthe replacement character.
Returns
a new string with occurrences of oldChar replaced by newChar.
bool decaf::lang::String::startsWith ( const String prefix) const

Compares the specified string to this string to determine if the specified string is a prefix.

If the prefix string is empty or is equal to this String than true is returned.

Parameters
prefixthe string to look for.
Returns
if the specified string is a prefix of this string, false otherwise
bool decaf::lang::String::startsWith ( const String prefix,
int  start 
) const

Compares the specified string to this string, starting at the specified offset, to determine if the specified string is a prefix.

Parameters
prefixthe string to look for.
startthe starting offset.
Returns
true if the specified string occurs in this string at the specified offset, false otherwise.
virtual CharSequence* decaf::lang::String::subSequence ( int  start,
int  end 
) const
virtual

Returns a new CharSequence that is a subsequence of this sequence.The subsequence starts with the char value at the specified index and ends with the char value at index end - 1. The length (in chars) of the returned sequence is end - start, so if start == end then an empty sequence is returned.

Parameters
startThe start index, inclusive.
endThe end index, exclusive.
Returns
a new CharSequence
Exceptions
IndexOutOfBoundsExceptionif start or end > length() or start or end are negative.

Implements decaf::lang::CharSequence.

String decaf::lang::String::substring ( int  start) const

Copies a range of characters into a new string starting from the given offset and extending to the end of this String.

Parameters
startthe offset of the first character.
Returns
a new string containing the characters from start to the end of the string.
Exceptions
IndexOutOfBoundsExceptionif start < 0 or start > length().
String decaf::lang::String::substring ( int  start,
int  end 
) const

Copies a range of characters into a new string.

The length of the returned String is end - start meaning that the characters in the new string include only start to end - 1.

Parameters
startthe offset of the first character. (inclusive)
endthe offset one past the last character. (exclusive)
Returns
a new string containing the characters from start to end - 1.
Exceptions
IndexOutOfBoundsExceptionif start < 0, start > end or end > length().
char* decaf::lang::String::toCharArray ( ) const

Copies the characters in this string to a newly allocated character array.

The returned array is the property of the caller and must be deleted by them. If the String is empty then a NULL is returned.

The array returned is not guaranteed to be null terminated as the array is sized according to the result of calling length().

Returns
a character array containing the characters of this string.
String decaf::lang::String::toLowerCase ( ) const

Converts the characters in this string to lower case.

The resulting value is returned in a new String instance and this one is left unchanged.

Returns
a new string containing the lower case characters equivalent to the characters in this string.
virtual std::string decaf::lang::String::toString ( ) const
virtual

Returns
the String representation of this CharSequence

Implements decaf::lang::CharSequence.

String decaf::lang::String::toUpperCase ( ) const

Converts the characters in this string to upper case.

The resulting value is returned in a new String instance and this one is left unchanged.

Returns
a new string containing the upper case characters equivalent to the characters in this string.
String decaf::lang::String::trim ( ) const

Returns a copy of the string, with leading and trailing whitespace omitted.

Returns
a copy of the string, with leading and trailing whitespace omitted.
static String decaf::lang::String::valueOf ( bool  value)
static

Returns a String that represents the value of the given boolean value.

Parameters
valueThe value whose string representation is to be returned.
Returns
"true" if the boolean is true, "false" otherwise.
static String decaf::lang::String::valueOf ( char  value)
static

Returns a String that represents the value of the given char value.

Parameters
valueThe value whose string representation is to be returned.
Returns
a String that contains the single character value given.
static String decaf::lang::String::valueOf ( float  value)
static

Returns a String that represents the value of the given float value.

Parameters
valueThe value whose string representation is to be returned.
Returns
a String that contains the string representation of the float value given.
static String decaf::lang::String::valueOf ( double  value)
static

Returns a String that represents the value of the given double value.

Parameters
valueThe value whose string representation is to be returned.
Returns
a String that contains the string representation of the double value given.
static String decaf::lang::String::valueOf ( short  value)
static

Returns a String that represents the value of the given short value.

Parameters
valueThe value whose string representation is to be returned.
Returns
a String that contains the string representation of the short value given.
static String decaf::lang::String::valueOf ( int  value)
static

Returns a String that represents the value of the given integer value.

Parameters
valueThe value whose string representation is to be returned.
Returns
a String that contains the string representation of the integer value given.
static String decaf::lang::String::valueOf ( long long  value)
static

Returns a String that represents the value of the given 64bit long value.

Parameters
valueThe value whose string representation is to be returned.
Returns
a String that contains the string representation of the 64 bit long value given.

Friends And Related Function Documentation

friend class AbstractStringBuilder
friend

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