Jive reference manual
|
Encapsulates a character string. More...
#include <jem/base/String.h>
Public Types | |
typedef const char * | Iterator |
A random access iterator type. More... | |
Public Member Functions | |
String () | |
Creates an empty String. More... | |
String (bool value) | |
Initializes this string to the string representation of the boolean value. More... | |
String (char value) | |
Initializes this string to the character value. More... | |
String (byte value) | |
Initializes this string to the string representation of the byte value. More... | |
String (short value) | |
Initializes this string to the string representation of the short value. More... | |
String (int value) | |
Initializes this string to the string representation of the int value. More... | |
String (long value) | |
Initializes this string to the string representation of the long int value. More... | |
String (float value) | |
Initializes this string to the string representation of the float value. More... | |
String (double value) | |
Initializes this string to the string representation of the double value. More... | |
String (const char *str) | |
Initializes this string to a null-terminated character array. More... | |
String (InputIterator first, InputIterator last) | |
Constructs a string given two input iterators. More... | |
String (const BasicString &lhs, const BasicString &rhs) | |
Creates a string that is the catenation of two BasicString objects. More... | |
String (const String &rhs) | |
Creates a copy of another string. More... | |
~String () | |
Frees resources if necessary. More... | |
String & | operator= (const String &rhs) |
Copies another string into this string. More... | |
String & | operator= (const char *str) |
Copies a character array into this string. More... | |
void | swap (String &rhs) |
Swaps the contents of this string with another string. More... | |
Iterator | begin () const |
Returns an iterator pointing to the begin of this string. More... | |
Iterator | end () const |
Returns an iterator pointing to the end of this string. More... | |
char | front () const |
Returns the first character in this string. More... | |
char | back () const |
Returns the last character in this string. More... | |
char | operator[] (int i) const |
String subscript operator. More... | |
String | operator[] (const Slice &s) const |
Slice operator that creates a slice of this string. More... | |
String | operator[] (const SliceFromTo &s) const |
Overloaded slice operator. More... | |
String | operator[] (const SliceTo &s) const |
Overloaded slice operator. More... | |
String | operator[] (const SliceFrom &s) const |
Overloaded slice operator. More... | |
String | operator[] (const SliceAll &) const |
Overloaded slice operator. More... | |
int | size () const |
Returns the size of this string. More... | |
const char * | addr (int i=0) const |
Returns a pointer to the i-th character in this string. More... | |
long | hashValue () const |
Returns a hash value for this string. More... | |
String | toUpper () const |
Returns this string with all characters translated to upper case. More... | |
String | toLower () const |
Returns this string with all characters translated to lower case. More... | |
String | stripWhite () const |
Returns this string stripped of white space. More... | |
bool | equals (const String &rhs) const |
Comparison of two strings. More... | |
bool | equals (const char *rhs) const |
Comparison of two strings. More... | |
bool | equalsIgnoreCase (const BasicString &rhs) const |
Case insensitive comparison of two strings. More... | |
int | compareTo (const BasicString &rhs) const |
Lexicographical comparison of two Strings. More... | |
int | compareToIgnoreCase (const BasicString &rhs) const |
Case insensitive lexicographical comparison of two Strings. More... | |
int | find (const BasicString &needle, int fromIndex) const |
Finds the first occurrence of a specified substring. More... | |
int | find (char needle, int fromIndex) const |
Finds the first occurrence of a specified character. More... | |
int | rfind (const BasicString &needle) const |
Finds the last occurrence of a specified substring. More... | |
int | rfind (char needle) const |
Finds the last occurrence of a specified character. More... | |
int | rfind (const BasicString &needle, int fromIndex) const |
Finds the last occurrence of a specified substring, starting at a specified index. More... | |
int | rfind (char needle, int fromIndex) const |
Finds the last occurrence of a specified character, starting at a specified index. More... | |
String | format (const char *fmt,...) |
Creates a string according to a printf-style format string. More... | |
Public Attributes | |
const char * | ConstIterator |
A random access iterator type. More... | |
Related Functions | |
(Note that these are not member functions.) | |
void | swap (String &lhs, String &rhs) |
Swaps two strings. More... | |
String catenation operators. | |
Catenation of strings and characters. | |
String | operator+ (const String &lhs, const String &rhs) |
String | operator+ (const String &lhs, const char *rhs) |
String | operator+ (const char *lhs, const String &rhs) |
String | operator+ (const String &lhs, char rhs) |
String | operator+ (char lhs, const String &rhs) |
String comparison operators. | |
Lexicographical comparison of strings. | |
bool | operator== (const String &lhs, const String &rhs) |
bool | operator== (const String &lhs, const char *rhs) |
bool | operator== (const char *lhs, const String &rhs) |
bool | operator!= (const String &lhs, const String &rhs) |
bool | operator!= (const String &lhs, const char *rhs) |
bool | operator!= (const char *lhs, const String &rhs) |
bool | operator< (const String &lhs, const String &rhs) |
bool | operator< (const String &lhs, const char *rhs) |
bool | operator< (const char *lhs, const String &rhs) |
bool | operator<= (const String &lhs, const String &rhs) |
bool | operator<= (const String &lhs, const char *rhs) |
bool | operator<= (const char *lhs, const String &rhs) |
bool | operator> (const String &lhs, const String &rhs) |
bool | operator> (const String &lhs, const char *rhs) |
bool | operator> (const char *lhs, const String &rhs) |
bool | operator>= (const String &lhs, const String &rhs) |
bool | operator>= (const String &lhs, const char *rhs) |
bool | operator>= (const char *lhs, const String &rhs) |
Input and output operators | |
io::DataInput & | operator>> (io::DataInput &in, String &s) |
String de-serialization operator. More... | |
io::DataOutput & | operator<< (io::DataOutput &out, const String &s) |
String serialization operator. More... | |
io::TextInput & | operator>> (io::TextInput &in, String &s) |
Reads a string from a text input stream. More... | |
io::TextOutput & | operator<< (io::TextOutput &out, const String &s) |
Writes a string to a text output stream. More... | |
The String
class represents character arrays. It provides a set of functions for accessing individual characters, for comparing strings, for finding substrings, for stripping white space from a string, and for translating all characters to uppercase or lowercase. The String
class also overloads the + operator so that one can easily concatenate two strings.
Strings are immutable. This means that the individual characters in a string can not be modified. The only way to change the contents of a string is to call one of the assignment operators. Use an Array
, or a similar type of object, if you need to modify the
Strings may share their contents through a thread-safe reference counting scheme. Very small strings, however, are stored directly in a String
object itself. This implementation avoids the overhead associated with reference counting when the strings are small. Note that users of the String
class do not need to be aware that strings may share their contents; they can safely assume that each String
stores its own copy of its contents. In particular, there is no danger that modifications to one String
will be visible in another String
.
String
instances are used by the exception classes, the class String
will never throw an exception itself.String
object is not null-terminated. Use the CString
class and the makeCString
function to convert a String
object to a null-terminated character array.CString
. typedef const char* jem::String::Iterator |
|
explicit |
Initilizes this String
object to the string representation of the boolean value.
value | - a boolean value. |
Boolean::print()
.
|
explicit |
|
explicit |
Initilizes this String
object to the string representation of the byte value.
value | - a byte. |
Integer::print()
.
|
explicit |
Initilizes this String
object to the string representation of the short value.
value | - a short integer. |
Integer::print()
.
|
explicit |
Initilizes this String
object to the string representation of the int value.
value | - an integer. |
Integer::print()
.
|
explicit |
Initilizes this String
object to the string representation of the long int value.
value | - a long integer. |
Integer::print()
.
|
explicit |
Initilizes this String
object to the string representation of the float value.
value | - a float. |
Float::print()
.
|
explicit |
Initilizes this String
object to the string representation of the double value.
value | - a double. |
Float::print()
. jem::String::String | ( | const char * | str | ) |
Initializes this String
to the null-terminated character array str. If str is NULL
, this String
is initialized to an empty String
. Note that this contructor makes a copy of the array str.
str | - a null-terminated character array, or NULL . |
this->equals( rhs ) == true
String
is not null-terminated. jem::String::String | ( | InputIterator | first, |
InputIterator | last | ||
) |
Constructs a string containing the characters between the input iterators first and last.
first | - an input iterator pointing to the first character. |
last | - an input iterator pointing to one position past the last character. |
*first
can be converted to type char
. this->size() == std::distance( first, last )
jem::String::String | ( | const BasicString & | lhs, |
const BasicString & | rhs | ||
) |
Creates a String
that is the catenation of the BasicString
lhs and the BasicString
rhs. That is, the first lhs.size()
characters of this String
are equal to the characters in lhs, while the next rhs.size()
characters are equal to the characters in rhs.
lhs | - the first BasicString to be catenated. |
rhs | - the second BasicString to be catenated. |
(*this)[ slice(BEGIN,lhs.size()) ] == lhs &&
(*this)[ slice(lhs.size(),END) ] == rhs
jem::String::String | ( | const String & | rhs | ) |
jem::String::~String | ( | ) |
Frees resources if necessary.
String& jem::String::operator= | ( | const char * | str | ) |
Copies the null-terminated character array rhs into this String
.
str | a null-terminated character array, or NULL . |
this->equals( rhs ) == true
void jem::String::swap | ( | String & | rhs | ) |
Iterator jem::String::begin | ( | ) | const |
Returns an Iterator
pointing to the first character of this string, or end()
if this string is empty. The Iterator
is valid until one of the assignment operators of this String
is called, or until the destructor of this String
is invoked.
Iterator
pointing to the first character of this String
. Iterator jem::String::end | ( | ) | const |
Returns an Iterator
pointing to one position past the last character of this string. The Iterator
is valid until one of the assignment operators of this String
is called, or until the destructor of this String
is called.
Iterator
pointing one position past the last character of this String
. char jem::String::front | ( | ) | const |
char jem::String::back | ( | ) | const |
char jem::String::operator[] | ( | int | i | ) | const |
String jem::String::operator[] | ( | const SliceFromTo & | s | ) | const |
int jem::String::size | ( | ) | const |
Returns the size of this String
.
String
. const char* jem::String::addr | ( | int | i = 0 | ) | const |
Returns a pointer to the i-th character in this String
. The pointer is valid until one of the assignment operators of this String
is called, or until the destructor of this String
is invoked.
i | - a character index. |
String
.i >= 0 && i <= this->size()
long jem::String::hashValue | ( | ) | const |
String jem::String::toUpper | ( | ) | const |
Translates all characters in this String
to upper case.
String
with all characters translated to upper case. String jem::String::toLower | ( | ) | const |
String jem::String::stripWhite | ( | ) | const |
Strips this String
of white space.
String
that has been stripped of leading and trailing white space. bool jem::String::equals | ( | const String & | rhs | ) | const |
Compares this String
to the string rhs. The result is true
if and only if both strings represent the same character sequence.
true
if both strings are equal, false
otherwise.String
instead of type BasicString
. bool jem::String::equals | ( | const char * | rhs | ) | const |
Compares this String
to the character array rhs. The result is true
if and only if both strings represent the same character sequence. If the character array rhs equals NULL
, it is viewed as a string with zero length.
rhs | - a null-terminated character array to which this String is compared. |
true
if both strings are equal, false
otherwise.const char*
instead of type BasicString
. bool jem::String::equalsIgnoreCase | ( | const BasicString & | rhs | ) | const |
Compares this String
to the argument string rhs, ignoring case considerations. The result is true
if and only if both strings have the same size and the corresponding characters in both strings are equal ignoring case.
rhs | - a BasicString to which this String is compared. |
true
if both strings are equal ignoring case, false
otherwise. int jem::String::compareTo | ( | const BasicString & | rhs | ) | const |
Compares this String
lexicographically to the argument string rhs. This function is similar to the standard C function strcmp()
.
rhs | - a BasicString to which this String is compared. |
int jem::String::compareToIgnoreCase | ( | const BasicString & | rhs | ) | const |
This function is similar to the function compareTo()
, except that case considerations are ignored.
rhs | - a BasicString to which this String is compared. |
String
is larger than, equal to, or smaller than the argument string. int jem::String::find | ( | const BasicString & | needle, |
int | fromIndex | ||
) | const |
Determines the smallest integer k such that
k >= fromIndex &&
(*this)[ slice(k,k+needle.size()) ].equals( needle ) == true
needle | - the substring to be found. |
fromIndex | - the character index from which the search is started. fromIndex may have any value. |
int jem::String::find | ( | char | needle, |
int | fromIndex | ||
) | const |
Determines the smallest integer k such that
k >= fromIndex && k < this->size() &&
(*this)[k] == needle
needle | - the character to be found. |
fromIndex | - the character index from which the search is started. fromIndex may have any value. |
int jem::String::rfind | ( | const BasicString & | needle | ) | const |
Finds the last occurrence of a specified substring.
needle | - the substring to be found. |
this->rfind( needle, this->size() )
int jem::String::rfind | ( | char | needle | ) | const |
Finds the last occurrence of a specified character.
needle | - the character to be found. |
this->rfind( needle, this->size() )
int jem::String::rfind | ( | const BasicString & | needle, |
int | fromIndex | ||
) | const |
Determines the largest integer k such that
k < fromIndex &&
(*this)[ slice(k,k+needle.size()) ].equals( needle )
needle | - the substring to be found. |
fromIndex | - the character index from which the backward search is started. fromIndex may have any value. |
int jem::String::rfind | ( | char | needle, |
int | fromIndex | ||
) | const |
Determines the largest integer k such that
k >= 0 && k < fromIndex && (*this)[k] == needle
needle | - the character to be found. |
fromIndex | - the character index from which the backward search is started. fromIndex may have any value. |
String jem::String::format | ( | const char * | fmt, |
... | |||
) |
Creates a String
according to the format string fmt. This function is similar to the standard C function printf
, except that it recognises only the following conversion specifiers: %%, %d, %i %o, %u, %x, %X, %f, %g, %e, %G, %E, %c, %s and %p (see the manual pages for printf for their meaning). Any special formatting flags, such as the field width, are not supported.
This format string fmt may also contain the special format specifier %S. The argument for this specifier must be a pointer to a String
object.
fmt | - a null-terminated format string. |
String
formatted according to the format string fmt.Returns the catenation of two strings.
lhs | - a String . |
rhs | - a null-terminated character array, or NULL . |
String( lhs, rhs )
Returns the catenation of two strings.
lhs | - a null-terminated character array, or NULL . |
rhs | - a String . |
String( lhs, rhs )
Returns the catenation of a string and a character.
lhs | - a String . |
rhs | - a character. |
String( lhs, BasicString( &rhs, 1 ) )
Returns the catenation of a string and a character.
lhs | - a character. |
rhs | - a String . |
String( BasicString( &rhs, 1 ), rhs )
|
related |
|
related |
|
related |
|
related |
|
related |
|
related |
|
related |
|
related |
|
related |
|
related |
|
related |
|
related |
|
related |
Reads a String
from the data input stream in and assigns it to s.
in | - the DataInputStream from which the string is to be read. |
s | - the String to be read. |
io::IOException | - if an IO error occurs. |
io::SerializationException | - if the data input stream is corrupt. |
|
related |
Writes the String
s to the data output stream out. The de-serialization operator can be used to restore the String
object.
out | - the data output stream to which the string is to be written. |
s | - the String to be written. |
io::IOException | - if an IO error occurs. |
|
related |
Skips white space and then reads a String
from the text input stream in. This function is equivalent with:
in | - the text input stream from which the string is te be read. |
s | - the string to be read. |
io::IOException | - if an IO error occurs. |
|
related |
Writes the contents of the String
s to the text output stream out. This function is equivalent with:
out.write( s.addr(), s.size() )
.
out | - the text output stream to which the string is to be written. |
s | - the string to be writtem. |
io::IOException | - if an IO error occurs. |
const char* jem::String::ConstIterator |
A random access iterator type pointing to elements of type const char
. This is an alias for the Iterator
type.