LibreOffice
LibreOffice 5.3 SDK C/C++ API Reference
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Member Functions | Static Public Member Functions | Friends | List of all members
rtl::OString Class Reference

This String class provide base functionality for C++ like 8-Bit character array handling. More...

#include <string.hxx>

Public Member Functions

 OString ()
 New string containing no characters. More...
 
 OString (const OString &str)
 New string from OString. More...
 
 OString (rtl_String *str)
 New string from OString data. More...
 
 OString (rtl_String *str, __sal_NoAcquire)
 New string from OString data without acquiring it. More...
 
 OString (sal_Char value)
 New string from a single character. More...
 
template<typename T >
 OString (const T &value, typename libreoffice_internal::CharPtrDetector< T, libreoffice_internal::Dummy >::Type=libreoffice_internal::Dummy())
 New string from a character buffer array. More...
 
template<typename T >
 OString (T &value, typename libreoffice_internal::NonConstCharArrayDetector< T, libreoffice_internal::Dummy >::Type=libreoffice_internal::Dummy())
 
template<typename T >
 OString (T &literal, typename libreoffice_internal::ConstCharArrayDetector< T, libreoffice_internal::Dummy >::Type=libreoffice_internal::Dummy())
 New string from a string literal. More...
 
 OString (const sal_Char *value, sal_Int32 length)
 New string from a character buffer array. More...
 
 OString (const sal_Unicode *value, sal_Int32 length, rtl_TextEncoding encoding, sal_uInt32 convertFlags=OUSTRING_TO_OSTRING_CVTFLAGS)
 New string from a Unicode character buffer array. More...
 
 ~OString ()
 Release the string data. More...
 
OStringoperator= (const OString &str)
 Assign a new string. More...
 
template<typename T >
libreoffice_internal::ConstCharArrayDetector
< T, OString & >::Type 
operator= (T &literal)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. This function accepts an ASCII string literal as its argument. More...
 
OStringoperator+= (const OString &str)
 Append a string to this string. More...
 
void clear ()
 Clears the string, i.e, makes a zero-character string. More...
 
sal_Int32 getLength () const
 Returns the length of this string. More...
 
bool isEmpty () const
 Checks if a string is empty. More...
 
const sal_ChargetStr () const
 Returns a pointer to the characters of this string. More...
 
sal_Char operator[] (sal_Int32 index) const
 Access to individual characters. More...
 
sal_Int32 compareTo (const OString &str) const
 Compares two strings. More...
 
sal_Int32 compareTo (const OString &rObj, sal_Int32 maxLength) const
 Compares two strings with an maximum count of characters. More...
 
sal_Int32 reverseCompareTo (const OString &str) const
 Compares two strings in reverse order. More...
 
bool equals (const OString &str) const
 Perform a comparison of two strings. More...
 
bool equalsL (const sal_Char *value, sal_Int32 length) const
 Perform a comparison of two strings. More...
 
bool equalsIgnoreAsciiCase (const OString &str) const
 Perform a ASCII lowercase comparison of two strings. More...
 
template<typename T >
libreoffice_internal::CharPtrDetector
< T, bool >::Type 
equalsIgnoreAsciiCase (const T &asciiStr) const
 Perform a ASCII lowercase comparison of two strings. More...
 
template<typename T >
libreoffice_internal::NonConstCharArrayDetector
< T, bool >::Type 
equalsIgnoreAsciiCase (T &asciiStr) const
 
template<typename T >
libreoffice_internal::ConstCharArrayDetector
< T, bool >::Type 
equalsIgnoreAsciiCase (T &literal) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. This function accepts an ASCII string literal as its argument. More...
 
bool equalsIgnoreAsciiCaseL (const sal_Char *asciiStr, sal_Int32 asciiStrLength) const
 Perform a ASCII lowercase comparison of two strings. More...
 
bool match (const OString &str, sal_Int32 fromIndex=0) const
 Match against a substring appearing in this string. More...
 
template<typename T >
libreoffice_internal::ConstCharArrayDetector
< T, bool >::Type 
match (T &literal, sal_Int32 fromIndex=0) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. This function accepts an ASCII string literal as its argument. More...
 
bool matchL (char const *str, sal_Int32 strLength, sal_Int32 fromIndex=0) const
 Match against a substring appearing in this string. More...
 
bool matchIgnoreAsciiCase (const OString &str, sal_Int32 fromIndex=0) const
 Match against a substring appearing in this string, ignoring the case of ASCII letters. More...
 
template<typename T >
libreoffice_internal::ConstCharArrayDetector
< T, bool >::Type 
matchIgnoreAsciiCase (T &literal, sal_Int32 fromIndex=0) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. This function accepts an ASCII string literal as its argument. More...
 
bool startsWith (OString const &str, OString *rest=NULL) const
 Check whether this string starts with a given substring. More...
 
template<typename T >
libreoffice_internal::ConstCharArrayDetector
< T, bool >::Type 
startsWith (T &literal, OString *rest=NULL) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. This function accepts an ASCII string literal as its argument. More...
 
bool startsWithIgnoreAsciiCase (OString const &str, OString *rest=NULL) const
 Check whether this string starts with a given string, ignoring the case of ASCII letters. More...
 
template<typename T >
libreoffice_internal::ConstCharArrayDetector
< T, bool >::Type 
startsWithIgnoreAsciiCase (T &literal, OString *rest=NULL) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. This function accepts an ASCII string literal as its argument. More...
 
bool endsWith (OString const &str, OString *rest=NULL) const
 Check whether this string ends with a given substring. More...
 
template<typename T >
libreoffice_internal::ConstCharArrayDetector
< T, bool >::Type 
endsWith (T &literal, OString *rest=NULL) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. This function accepts an ASCII string literal as its argument. More...
 
bool endsWithL (char const *str, sal_Int32 strLength) const
 Check whether this string ends with a given substring. More...
 
sal_Int32 hashCode () const
 Returns a hashcode for this string. More...
 
sal_Int32 indexOf (sal_Char ch, sal_Int32 fromIndex=0) const
 Returns the index within this string of the first occurrence of the specified character, starting the search at the specified index. More...
 
sal_Int32 lastIndexOf (sal_Char ch) const
 Returns the index within this string of the last occurrence of the specified character, searching backward starting at the end. More...
 
sal_Int32 lastIndexOf (sal_Char ch, sal_Int32 fromIndex) const
 Returns the index within this string of the last occurrence of the specified character, searching backward starting before the specified index. More...
 
sal_Int32 indexOf (const OString &str, sal_Int32 fromIndex=0) const
 Returns the index within this string of the first occurrence of the specified substring, starting at the specified index. More...
 
template<typename T >
libreoffice_internal::ConstCharArrayDetector
< T, sal_Int32 >::Type 
indexOf (T &literal, sal_Int32 fromIndex=0) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. This function accepts an ASCII string literal as its argument. More...
 
sal_Int32 indexOfL (char const *str, sal_Int32 len, sal_Int32 fromIndex=0) const
 Returns the index within this string of the first occurrence of the specified substring, starting at the specified index. More...
 
sal_Int32 lastIndexOf (const OString &str) const
 Returns the index within this string of the last occurrence of the specified substring, searching backward starting at the end. More...
 
sal_Int32 lastIndexOf (const OString &str, sal_Int32 fromIndex) const
 Returns the index within this string of the last occurrence of the specified substring, searching backward starting before the specified index. More...
 
SAL_WARN_UNUSED_RESULT OString copy (sal_Int32 beginIndex) const
 Returns a new string that is a substring of this string. More...
 
SAL_WARN_UNUSED_RESULT OString copy (sal_Int32 beginIndex, sal_Int32 count) const
 Returns a new string that is a substring of this string. More...
 
SAL_WARN_UNUSED_RESULT OString concat (const OString &str) const
 Concatenates the specified string to the end of this string. More...
 
SAL_WARN_UNUSED_RESULT OString replaceAt (sal_Int32 index, sal_Int32 count, const OString &newStr) const
 Returns a new string resulting from replacing n = count characters from position index in this string with newStr. More...
 
SAL_WARN_UNUSED_RESULT OString replace (sal_Char oldChar, sal_Char newChar) const
 Returns a new string resulting from replacing all occurrences of oldChar in this string with newChar. More...
 
SAL_WARN_UNUSED_RESULT OString replaceFirst (OString const &from, OString const &to, sal_Int32 *index=NULL) const
 Returns a new string resulting from replacing the first occurrence of a given substring with another substring. More...
 
SAL_WARN_UNUSED_RESULT OString replaceAll (OString const &from, OString const &to) const
 Returns a new string resulting from replacing all occurrences of a given substring with another substring. More...
 
SAL_WARN_UNUSED_RESULT OString toAsciiLowerCase () const
 Converts from this string all ASCII uppercase characters (65-90) to ASCII lowercase characters (97-122). More...
 
SAL_WARN_UNUSED_RESULT OString toAsciiUpperCase () const
 Converts from this string all ASCII lowercase characters (97-122) to ASCII uppercase characters (65-90). More...
 
SAL_WARN_UNUSED_RESULT OString trim () const
 Returns a new string resulting from removing white space from both ends of the string. More...
 
OString getToken (sal_Int32 token, sal_Char cTok, sal_Int32 &index) const
 Returns a token in the string. More...
 
OString getToken (sal_Int32 count, char separator) const
 Returns a token from the string. More...
 
bool toBoolean () const
 Returns the Boolean value from this string. More...
 
sal_Char toChar () const
 Returns the first character from this string. More...
 
sal_Int32 toInt32 (sal_Int16 radix=10) const
 Returns the int32 value from this string. More...
 
sal_uInt32 toUInt32 (sal_Int16 radix=10) const
 Returns the uint32 value from this string. More...
 
sal_Int64 toInt64 (sal_Int16 radix=10) const
 Returns the int64 value from this string. More...
 
sal_uInt64 toUInt64 (sal_Int16 radix=10) const
 Returns the uint64 value from this string. More...
 
float toFloat () const
 Returns the float value from this string. More...
 
double toDouble () const
 Returns the double value from this string. More...
 

Static Public Member Functions

static OString number (int i, sal_Int16 radix=10)
 Returns the string representation of the integer argument. More...
 
static OString number (unsigned int i, sal_Int16 radix=10)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More...
 
static OString number (long i, sal_Int16 radix=10)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More...
 
static OString number (unsigned long i, sal_Int16 radix=10)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More...
 
static OString number (long long ll, sal_Int16 radix=10)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More...
 
static OString number (unsigned long long ll, sal_Int16 radix=10)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More...
 
static OString number (float f)
 Returns the string representation of the float argument. More...
 
static OString number (double d)
 Returns the string representation of the double argument. More...
 
static OString valueOf (sal_Bool b)
 Returns the string representation of the sal_Bool argument. More...
 
static OString boolean (bool b)
 Returns the string representation of the boolean argument. More...
 
static OString valueOf (sal_Char c)
 Returns the string representation of the char argument. More...
 
static OString valueOf (sal_Int32 i, sal_Int16 radix=10)
 Returns the string representation of the int argument. More...
 
static OString valueOf (sal_Int64 ll, sal_Int16 radix=10)
 Returns the string representation of the long argument. More...
 
static OString valueOf (float f)
 Returns the string representation of the float argument. More...
 
static OString valueOf (double d)
 Returns the string representation of the double argument. More...
 

Friends

bool operator== (const OString &rStr1, const OString &rStr2)
 
bool operator!= (const OString &rStr1, const OString &rStr2)
 
bool operator< (const OString &rStr1, const OString &rStr2)
 
bool operator> (const OString &rStr1, const OString &rStr2)
 
bool operator<= (const OString &rStr1, const OString &rStr2)
 
bool operator>= (const OString &rStr1, const OString &rStr2)
 
template<typename T >
libreoffice_internal::CharPtrDetector
< T, bool >::Type 
operator== (const OString &rStr1, const T &value)
 
template<typename T >
libreoffice_internal::NonConstCharArrayDetector
< T, bool >::Type 
operator== (const OString &rStr1, T &value)
 
template<typename T >
libreoffice_internal::CharPtrDetector
< T, bool >::Type 
operator== (const T &value, const OString &rStr2)
 
template<typename T >
libreoffice_internal::NonConstCharArrayDetector
< T, bool >::Type 
operator== (T &value, const OString &rStr2)
 
template<typename T >
libreoffice_internal::ConstCharArrayDetector
< T, bool >::Type 
operator== (const OString &rStr, T &literal)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. This function accepts an ASCII string literal as its argument. More...
 
template<typename T >
libreoffice_internal::ConstCharArrayDetector
< T, bool >::Type 
operator== (T &literal, const OString &rStr)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. This function accepts an ASCII string literal as its argument. More...
 
template<typename T >
libreoffice_internal::CharPtrDetector
< T, bool >::Type 
operator!= (const OString &rStr1, const T &value)
 
template<typename T >
libreoffice_internal::NonConstCharArrayDetector
< T, bool >::Type 
operator!= (const OString &rStr1, T &value)
 
template<typename T >
libreoffice_internal::CharPtrDetector
< T, bool >::Type 
operator!= (const T &value, const OString &rStr2)
 
template<typename T >
libreoffice_internal::NonConstCharArrayDetector
< T, bool >::Type 
operator!= (T &value, const OString &rStr2)
 
template<typename T >
libreoffice_internal::ConstCharArrayDetector
< T, bool >::Type 
operator!= (const OString &rStr, T &literal)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. This function accepts an ASCII string literal as its argument. More...
 
template<typename T >
libreoffice_internal::ConstCharArrayDetector
< T, bool >::Type 
operator!= (T &literal, const OString &rStr)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. This function accepts an ASCII string literal as its argument. More...
 
OString operator+ (const OString &str1, const OString &str2)
 

Detailed Description

This String class provide base functionality for C++ like 8-Bit character array handling.

The advantage of this class is, that it handle all the memory managament for you - and it do it more efficient. If you assign a string to another string, the data of both strings are shared (without any copy operation or memory allocation) as long as you do not change the string. This class stores also the length of the string, so that many operations are faster as the C-str-functions.

This class provide only readonly string handling. So you could create a string and you could only query the content from this string. It provide also functionality to change the string, but this results in every case in a new string instance (in the most cases with an memory allocation). You don't have functionality to change the content of the string. If you want change the string content, than you should us the OStringBuffer class, which provide these functionality and avoid to much memory allocation.

The design of this class is similar to the string classes in Java and so more people should have fewer understanding problems when they use this class.

Constructor & Destructor Documentation

rtl::OString::OString ( )
inline

New string containing no characters.

rtl::OString::OString ( const OString str)
inline

New string from OString.

Parameters
stra OString.
rtl::OString::OString ( rtl_String *  str)
inline

New string from OString data.

Parameters
stra OString data.
rtl::OString::OString ( rtl_String *  str,
__sal_NoAcquire   
)
inline

New string from OString data without acquiring it.

Takeover of ownership.

The SAL_NO_ACQUIRE dummy parameter is only there to distinguish this from other constructors.

Parameters
stra OString data.
rtl::OString::OString ( sal_Char  value)
inlineexplicit

New string from a single character.

Parameters
valuea character.
template<typename T >
rtl::OString::OString ( const T &  value,
typename libreoffice_internal::CharPtrDetector< T, libreoffice_internal::Dummy >::Type  = libreoffice_internal::Dummy() 
)
inline

New string from a character buffer array.

Note: The argument type is always either char* or const char*. The template is used only for technical reasons, as is the second argument.

Parameters
valuea NULL-terminated character array.
template<typename T >
rtl::OString::OString ( T &  value,
typename libreoffice_internal::NonConstCharArrayDetector< T, libreoffice_internal::Dummy >::Type  = libreoffice_internal::Dummy() 
)
inline
template<typename T >
rtl::OString::OString ( T &  literal,
typename libreoffice_internal::ConstCharArrayDetector< T, libreoffice_internal::Dummy >::Type  = libreoffice_internal::Dummy() 
)
inline

New string from a string literal.

If there are any embedded \0's in the string literal, the result is undefined. Use the overload that explicitly accepts length.

Since
LibreOffice 3.6
Parameters
literala string literal
rtl::OString::OString ( const sal_Char value,
sal_Int32  length 
)
inline

New string from a character buffer array.

Parameters
valuea character array.
lengththe number of character which should be copied. The character array length must be greater or equal than this value.
rtl::OString::OString ( const sal_Unicode value,
sal_Int32  length,
rtl_TextEncoding  encoding,
sal_uInt32  convertFlags = OUSTRING_TO_OSTRING_CVTFLAGS 
)
inline

New string from a Unicode character buffer array.

Parameters
valuea Unicode character array.
lengththe number of character which should be converted. The Unicode character array length must be greater or equal than this value.
encodingthe text encoding in which the Unicode character sequence should be converted.
convertFlagsflags which controls the conversion. see RTL_UNICODETOTEXT_FLAGS_...
Exceptions
std::bad_allocis thrown if an out-of-memory condition occurs
rtl::OString::~OString ( )
inline

Release the string data.

Member Function Documentation

static OString rtl::OString::boolean ( bool  b)
inlinestatic

Returns the string representation of the boolean argument.

If the argument is true, the string "true" is returned. If the argument is false, the string "false" is returned. This function can't be used for language specific conversion.

Parameters
ba bool.
Returns
a string with the string representation of the argument.
Since
LibreOffice 4.1
void rtl::OString::clear ( )
inline

Clears the string, i.e, makes a zero-character string.

Since
LibreOffice 4.4
sal_Int32 rtl::OString::compareTo ( const OString str) const
inline

Compares two strings.

The comparison is based on the numeric value of each character in the strings and return a value indicating their relationship. This function can't be used for language specific sorting.

Parameters
strthe object to be compared.
Returns
0 - if both strings are equal < 0 - if this string is less than the string argument > 0 - if this string is greater than the string argument
sal_Int32 rtl::OString::compareTo ( const OString rObj,
sal_Int32  maxLength 
) const
inline

Compares two strings with an maximum count of characters.

The comparison is based on the numeric value of each character in the strings and return a value indicating their relationship. This function can't be used for language specific sorting.

Parameters
rObjthe object to be compared.
maxLengththe maximum count of characters to be compared.
Returns
0 - if both strings are equal < 0 - if this string is less than the string argument > 0 - if this string is greater than the string argument
SAL_WARN_UNUSED_RESULT OString rtl::OString::concat ( const OString str) const
inline

Concatenates the specified string to the end of this string.

Parameters
strthe string that is concatenated to the end of this string.
Returns
a string that represents the concatenation of this string followed by the string argument.
SAL_WARN_UNUSED_RESULT OString rtl::OString::copy ( sal_Int32  beginIndex) const
inline

Returns a new string that is a substring of this string.

The substring begins at the specified beginIndex. If beginIndex is negative or be greater than the length of this string, behaviour is undefined.

Parameters
beginIndexthe beginning index, inclusive.
Returns
the specified substring.
SAL_WARN_UNUSED_RESULT OString rtl::OString::copy ( sal_Int32  beginIndex,
sal_Int32  count 
) const
inline

Returns a new string that is a substring of this string.

The substring begins at the specified beginIndex and contains count characters. If either beginIndex or count are negative, or beginIndex + count are greater than the length of this string then behaviour is undefined.

Parameters
beginIndexthe beginning index, inclusive.
countthe number of characters.
Returns
the specified substring.
bool rtl::OString::endsWith ( OString const &  str,
OString rest = NULL 
) const
inline

Check whether this string ends with a given substring.

Parameters
strthe substring to be compared
restif non-null, and this function returns true, then assign a copy of the remainder of this string to *rest. Available since LibreOffice 4.2
Returns
true if and only if the given str appears as a substring at the end of this string
Since
LibreOffice 3.6
template<typename T >
libreoffice_internal::ConstCharArrayDetector< T, bool >::Type rtl::OString::endsWith ( T &  literal,
OString rest = NULL 
) const
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. This function accepts an ASCII string literal as its argument.

Since
LibreOffice 3.6
bool rtl::OString::endsWithL ( char const *  str,
sal_Int32  strLength 
) const
inline

Check whether this string ends with a given substring.

Parameters
strthe substring to be compared; must not be null and must point to memory of at least strLength bytes
strLengththe length of the substring; must be non-negative
Returns
true if and only if the given str appears as a substring at the end of this string
Since
LibreOffice 3.6
bool rtl::OString::equals ( const OString str) const
inline

Perform a comparison of two strings.

The result is true if and only if second string represents the same sequence of characters as the first string. This function can't be used for language specific comparison.

Parameters
strthe object to be compared.
Returns
true if the strings are equal; false, otherwise.
bool rtl::OString::equalsIgnoreAsciiCase ( const OString str) const
inline

Perform a ASCII lowercase comparison of two strings.

The result is true if and only if second string represents the same sequence of characters as the first string, ignoring the case. Character values between 65 and 90 (ASCII A-Z) are interpreted as values between 97 and 122 (ASCII a-z). This function can't be used for language specific comparison.

Parameters
strthe object to be compared.
Returns
true if the strings are equal; false, otherwise.
template<typename T >
libreoffice_internal::CharPtrDetector< T, bool >::Type rtl::OString::equalsIgnoreAsciiCase ( const T &  asciiStr) const
inline

Perform a ASCII lowercase comparison of two strings.

The result is true if and only if second string represents the same sequence of characters as the first string, ignoring the case. Character values between 65 and 90 (ASCII A-Z) are interpreted as values between 97 and 122 (ASCII a-z). Since this method is optimized for performance, the ASCII character values are not converted in any way. The caller has to make sure that all ASCII characters are in the allowed range between 0 and

  1. The ASCII string must be NULL-terminated. This function can't be used for language specific comparison.

Note: The argument type is always either char* or const char*, the return type is bool. The template is used only for technical reasons.

Parameters
asciiStrthe 8-Bit ASCII character string to be compared.
Returns
true if the strings are equal; false, otherwise.
template<typename T >
libreoffice_internal::NonConstCharArrayDetector< T, bool >::Type rtl::OString::equalsIgnoreAsciiCase ( T &  asciiStr) const
inline
template<typename T >
libreoffice_internal::ConstCharArrayDetector< T, bool >::Type rtl::OString::equalsIgnoreAsciiCase ( T &  literal) const
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. This function accepts an ASCII string literal as its argument.

Since
LibreOffice 3.6
bool rtl::OString::equalsIgnoreAsciiCaseL ( const sal_Char asciiStr,
sal_Int32  asciiStrLength 
) const
inline

Perform a ASCII lowercase comparison of two strings.

The result is true if and only if second string represents the same sequence of characters as the first string, ignoring the case. Character values between 65 and 90 (ASCII A-Z) are interpreted as values between 97 and 122 (ASCII a-z). Since this method is optimized for performance, the ASCII character values are not converted in any way. The caller has to make sure that all ASCII characters are in the allowed range between 0 and

  1. The ASCII string must be greater or equal in length as asciiStrLength. This function can't be used for language specific comparison.
Parameters
asciiStrthe 8-Bit ASCII character string to be compared.
asciiStrLengththe length of the ascii string
Returns
true if the strings are equal; false, otherwise.
bool rtl::OString::equalsL ( const sal_Char value,
sal_Int32  length 
) const
inline

Perform a comparison of two strings.

The result is true if and only if second string represents the same sequence of characters as the first string. The ASCII string must be NULL-terminated and must be greater or equal as length. This function can't be used for language specific comparison.

Parameters
valuea character array.
lengththe length of the character array.
Returns
true if the strings are equal; false, otherwise.
sal_Int32 rtl::OString::getLength ( ) const
inline

Returns the length of this string.

The length is equal to the number of characters in this string.

Returns
the length of the sequence of characters represented by this object.
const sal_Char* rtl::OString::getStr ( ) const
inline

Returns a pointer to the characters of this string.

The returned pointer is guaranteed to point to a null-terminated byte string. But note that this string object may contain embedded null characters, which will thus also be embedded in the returned null-terminated byte string.

Returns
a pointer to a null-terminated byte string representing the characters of this string object.
OString rtl::OString::getToken ( sal_Int32  token,
sal_Char  cTok,
sal_Int32 &  index 
) const
inline

Returns a token in the string.

Example: sal_Int32 nIndex = 0; do { ... OString aToken = aStr.getToken( 0, ';', nIndex ); ... } while ( nIndex >= 0 );

Parameters
tokenthe number of the token to return.
cTokthe character which separate the tokens.
indexthe position at which the token is searched in the string. The index must not be greater than the length of the string. This param is set to the position of the next token or to -1, if it is the last token.
Returns
the token; if either token or index is negative, an empty token is returned (and index is set to -1)
OString rtl::OString::getToken ( sal_Int32  count,
char  separator 
) const
inline

Returns a token from the string.

The same as getToken(sal_Int32, sal_Char, sal_Int32 &), but always passing in 0 as the start index in the third argument.

Parameters
countthe number of the token to return, starting with 0
separatorthe character which separates the tokens
Returns
the given token, or an empty string
Since
LibreOffice 3.6
sal_Int32 rtl::OString::hashCode ( ) const
inline

Returns a hashcode for this string.

Returns
a hash code value for this object.
See Also
rtl::OStringHash for convenient use of std::unordered_map
sal_Int32 rtl::OString::indexOf ( sal_Char  ch,
sal_Int32  fromIndex = 0 
) const
inline

Returns the index within this string of the first occurrence of the specified character, starting the search at the specified index.

Parameters
chcharacter to be located.
fromIndexthe index to start the search from. The index must be greater or equal than 0 and less or equal as the string length.
Returns
the index of the first occurrence of the character in the character sequence represented by this string that is greater than or equal to fromIndex, or -1 if the character does not occur.
sal_Int32 rtl::OString::indexOf ( const OString str,
sal_Int32  fromIndex = 0 
) const
inline

Returns the index within this string of the first occurrence of the specified substring, starting at the specified index.

If str doesn't include any character, always -1 is returned. This is also the case, if both strings are empty.

Parameters
strthe substring to search for.
fromIndexthe index to start the search from.
Returns
If the string argument occurs one or more times as a substring within this string at the starting index, then the index of the first character of the first such substring is returned. If it does not occur as a substring starting at fromIndex or beyond, -1 is returned.
template<typename T >
libreoffice_internal::ConstCharArrayDetector< T, sal_Int32 >::Type rtl::OString::indexOf ( T &  literal,
sal_Int32  fromIndex = 0 
) const
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. This function accepts an ASCII string literal as its argument.

Since
LibreOffice 3.6
sal_Int32 rtl::OString::indexOfL ( char const *  str,
sal_Int32  len,
sal_Int32  fromIndex = 0 
) const
inline

Returns the index within this string of the first occurrence of the specified substring, starting at the specified index.

If str doesn't include any character, always -1 is returned. This is also the case, if both strings are empty.

Parameters
strthe substring to search for.
lenthe length of the substring.
fromIndexthe index to start the search from.
Returns
If the string argument occurs one or more times as a substring within this string at the starting index, then the index of the first character of the first such substring is returned. If it does not occur as a substring starting at fromIndex or beyond, -1 is returned.
Since
LibreOffice 3.6
bool rtl::OString::isEmpty ( ) const
inline

Checks if a string is empty.

Returns
true if the string is empty; false, otherwise.
Since
LibreOffice 3.4
sal_Int32 rtl::OString::lastIndexOf ( sal_Char  ch) const
inline

Returns the index within this string of the last occurrence of the specified character, searching backward starting at the end.

Parameters
chcharacter to be located.
Returns
the index of the last occurrence of the character in the character sequence represented by this string, or -1 if the character does not occur.
sal_Int32 rtl::OString::lastIndexOf ( sal_Char  ch,
sal_Int32  fromIndex 
) const
inline

Returns the index within this string of the last occurrence of the specified character, searching backward starting before the specified index.

Parameters
chcharacter to be located.
fromIndexthe index before which to start the search.
Returns
the index of the last occurrence of the character in the character sequence represented by this string that is less than fromIndex, or -1 if the character does not occur before that point.
sal_Int32 rtl::OString::lastIndexOf ( const OString str) const
inline

Returns the index within this string of the last occurrence of the specified substring, searching backward starting at the end.

The returned index indicates the starting index of the substring in this string. If str doesn't include any character, always -1 is returned. This is also the case, if both strings are empty.

Parameters
strthe substring to search for.
Returns
If the string argument occurs one or more times as a substring within this string, then the index of the first character of the last such substring is returned. If it does not occur as a substring, -1 is returned.
sal_Int32 rtl::OString::lastIndexOf ( const OString str,
sal_Int32  fromIndex 
) const
inline

Returns the index within this string of the last occurrence of the specified substring, searching backward starting before the specified index.

The returned index indicates the starting index of the substring in this string. If str doesn't include any character, always -1 is returned. This is also the case, if both strings are empty.

Parameters
strthe substring to search for.
fromIndexthe index before which to start the search.
Returns
If the string argument occurs one or more times as a substring within this string before the starting index, then the index of the first character of the last such substring is returned. Otherwise, -1 is returned.
bool rtl::OString::match ( const OString str,
sal_Int32  fromIndex = 0 
) const
inline

Match against a substring appearing in this string.

The result is true if and only if the second string appears as a substring of this string, at the given position. This function can't be used for language specific comparison.

Parameters
strthe object (substring) to be compared.
fromIndexthe index to start the comparion from. The index must be greater or equal than 0 and less or equal as the string length.
Returns
true if str match with the characters in the string at the given position; false, otherwise.
template<typename T >
libreoffice_internal::ConstCharArrayDetector< T, bool >::Type rtl::OString::match ( T &  literal,
sal_Int32  fromIndex = 0 
) const
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. This function accepts an ASCII string literal as its argument.

Since
LibreOffice 3.6
bool rtl::OString::matchIgnoreAsciiCase ( const OString str,
sal_Int32  fromIndex = 0 
) const
inline

Match against a substring appearing in this string, ignoring the case of ASCII letters.

The result is true if and only if the second string appears as a substring of this string, at the given position. Character values between 65 and 90 (ASCII A-Z) are interpreted as values between 97 and 122 (ASCII a-z). This function can't be used for language specific comparison.

Parameters
strthe object (substring) to be compared.
fromIndexthe index to start the comparion from. The index must be greater or equal than 0 and less or equal as the string length.
Returns
true if str match with the characters in the string at the given position; false, otherwise.
template<typename T >
libreoffice_internal::ConstCharArrayDetector< T, bool >::Type rtl::OString::matchIgnoreAsciiCase ( T &  literal,
sal_Int32  fromIndex = 0 
) const
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. This function accepts an ASCII string literal as its argument.

Since
LibreOffice 3.6
bool rtl::OString::matchL ( char const *  str,
sal_Int32  strLength,
sal_Int32  fromIndex = 0 
) const
inline

Match against a substring appearing in this string.

Parameters
strthe substring to be compared; must not be null and must point to memory of at least strLength bytes
strLengththe length of the substring; must be non-negative
fromIndexthe index into this string to start the comparison at; must be non-negative and not greater than this string's length
Returns
true if and only if the given str is contained as a substring of this string at the given fromIndex
Since
LibreOffice 3.6
static OString rtl::OString::number ( int  i,
sal_Int16  radix = 10 
)
inlinestatic

Returns the string representation of the integer argument.

This function can't be used for language specific conversion.

Parameters
ian integer value
radixthe radix (between 2 and 36)
Returns
a string with the string representation of the argument.
Since
LibreOffice 4.1
static OString rtl::OString::number ( unsigned int  i,
sal_Int16  radix = 10 
)
inlinestatic

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Since
LibreOffice 4.1
static OString rtl::OString::number ( long  i,
sal_Int16  radix = 10 
)
inlinestatic

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Since
LibreOffice 4.1
static OString rtl::OString::number ( unsigned long  i,
sal_Int16  radix = 10 
)
inlinestatic

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Since
LibreOffice 4.1
static OString rtl::OString::number ( long long  ll,
sal_Int16  radix = 10 
)
inlinestatic

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Since
LibreOffice 4.1
static OString rtl::OString::number ( unsigned long long  ll,
sal_Int16  radix = 10 
)
inlinestatic

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Since
LibreOffice 4.1
static OString rtl::OString::number ( float  f)
inlinestatic

Returns the string representation of the float argument.

This function can't be used for language specific conversion.

Parameters
fa float.
Returns
a string with the string representation of the argument.
Since
LibreOffice 4.1
static OString rtl::OString::number ( double  d)
inlinestatic

Returns the string representation of the double argument.

This function can't be used for language specific conversion.

Parameters
da double.
Returns
a string with the string representation of the argument.
Since
LibreOffice 4.1
OString& rtl::OString::operator+= ( const OString str)
inline

Append a string to this string.

Parameters
stra OString.
OString& rtl::OString::operator= ( const OString str)
inline

Assign a new string.

Parameters
stra OString.
template<typename T >
libreoffice_internal::ConstCharArrayDetector< T, OString& >::Type rtl::OString::operator= ( T &  literal)
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. This function accepts an ASCII string literal as its argument.

Since
LibreOffice 3.6
sal_Char rtl::OString::operator[] ( sal_Int32  index) const
inline

Access to individual characters.

Parameters
indexmust be non-negative and less than length.
Returns
the character at the given index.
Since
LibreOffice 3.5
SAL_WARN_UNUSED_RESULT OString rtl::OString::replace ( sal_Char  oldChar,
sal_Char  newChar 
) const
inline

Returns a new string resulting from replacing all occurrences of oldChar in this string with newChar.

If the character oldChar does not occur in the character sequence represented by this object, then the string is assigned with str.

Parameters
oldCharthe old character.
newCharthe new character.
Returns
a string derived from this string by replacing every occurrence of oldChar with newChar.
SAL_WARN_UNUSED_RESULT OString rtl::OString::replaceAll ( OString const &  from,
OString const &  to 
) const
inline

Returns a new string resulting from replacing all occurrences of a given substring with another substring.

Replacing subsequent occurrences picks up only after a given replacement. That is, replacing from "xa" to "xx" in "xaa" results in "xxa", not "xxx".

Parameters
fromthe substring to be replaced
tothe replacing substring
Since
LibreOffice 3.6
SAL_WARN_UNUSED_RESULT OString rtl::OString::replaceAt ( sal_Int32  index,
sal_Int32  count,
const OString newStr 
) const
inline

Returns a new string resulting from replacing n = count characters from position index in this string with newStr.

Parameters
indexthe replacing index in str. The index must be greater or equal as 0 and less or equal as the length of the string.
countthe count of characters that will replaced The count must be greater or equal as 0 and less or equal as the length of the string minus index.
newStrthe new substring.
Returns
the new string.
SAL_WARN_UNUSED_RESULT OString rtl::OString::replaceFirst ( OString const &  from,
OString const &  to,
sal_Int32 *  index = NULL 
) const
inline

Returns a new string resulting from replacing the first occurrence of a given substring with another substring.

Parameters
fromthe substring to be replaced
tothe replacing substring
[in,out]indexpointer to a start index; if the pointer is non-null: upon entry to the function, its value is the index into the this string at which to start searching for the from substring, the value must be non-negative and not greater than this string's length; upon exit from the function its value is the index into this string at which the replacement took place or -1 if no replacement took place; if the pointer is null, searching always starts at index 0
Since
LibreOffice 3.6
sal_Int32 rtl::OString::reverseCompareTo ( const OString str) const
inline

Compares two strings in reverse order.

The comparison is based on the numeric value of each character in the strings and return a value indicating their relationship. This function can't be used for language specific sorting.

Parameters
strthe object to be compared.
Returns
0 - if both strings are equal < 0 - if this string is less than the string argument > 0 - if this string is greater than the string argument
bool rtl::OString::startsWith ( OString const &  str,
OString rest = NULL 
) const
inline

Check whether this string starts with a given substring.

Parameters
strthe substring to be compared
restif non-null, and this function returns true, then assign a copy of the remainder of this string to *rest. Available since LibreOffice 4.2
Returns
true if and only if the given str appears as a substring at the start of this string
Since
LibreOffice 4.0
template<typename T >
libreoffice_internal::ConstCharArrayDetector< T, bool >::Type rtl::OString::startsWith ( T &  literal,
OString rest = NULL 
) const
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. This function accepts an ASCII string literal as its argument.

Since
LibreOffice 4.0
bool rtl::OString::startsWithIgnoreAsciiCase ( OString const &  str,
OString rest = NULL 
) const
inline

Check whether this string starts with a given string, ignoring the case of ASCII letters.

Character values between 65 and 90 (ASCII A-Z) are interpreted as values between 97 and 122 (ASCII a-z). This function can't be used for language specific comparison.

Parameters
strthe substring to be compared
restif non-null, and this function returns true, then assign a copy of the remainder of this string to *rest.
Returns
true if and only if the given str appears as a substring at the start of this string, ignoring the case of ASCII letters ("A"–"Z" and "a"–"z")
Since
LibreOffice 5.1
template<typename T >
libreoffice_internal::ConstCharArrayDetector< T, bool >::Type rtl::OString::startsWithIgnoreAsciiCase ( T &  literal,
OString rest = NULL 
) const
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. This function accepts an ASCII string literal as its argument.

Since
LibreOffice 5.1
SAL_WARN_UNUSED_RESULT OString rtl::OString::toAsciiLowerCase ( ) const
inline

Converts from this string all ASCII uppercase characters (65-90) to ASCII lowercase characters (97-122).

This function can't be used for language specific conversion. If the string doesn't contain characters which must be converted, then the new string is assigned with str.

Returns
the string, converted to ASCII lowercase.
SAL_WARN_UNUSED_RESULT OString rtl::OString::toAsciiUpperCase ( ) const
inline

Converts from this string all ASCII lowercase characters (97-122) to ASCII uppercase characters (65-90).

This function can't be used for language specific conversion. If the string doesn't contain characters which must be converted, then the new string is assigned with str.

Returns
the string, converted to ASCII uppercase.
bool rtl::OString::toBoolean ( ) const
inline

Returns the Boolean value from this string.

This function can't be used for language specific conversion.

Returns
true, if the string is 1 or "True" in any ASCII case. false in any other case.
sal_Char rtl::OString::toChar ( ) const
inline

Returns the first character from this string.

Returns
the first character from this string or 0, if this string is empty.
double rtl::OString::toDouble ( ) const
inline

Returns the double value from this string.

This function can't be used for language specific conversion.

Returns
the double represented from this string. 0.0 if this string represents no number.
float rtl::OString::toFloat ( ) const
inline

Returns the float value from this string.

This function can't be used for language specific conversion.

Returns
the float represented from this string. 0.0 if this string represents no number.
sal_Int32 rtl::OString::toInt32 ( sal_Int16  radix = 10) const
inline

Returns the int32 value from this string.

This function can't be used for language specific conversion.

Parameters
radixthe radix (between 2 and 36)
Returns
the int32 represented from this string. 0 if this string represents no number or one of too large magnitude.
sal_Int64 rtl::OString::toInt64 ( sal_Int16  radix = 10) const
inline

Returns the int64 value from this string.

This function can't be used for language specific conversion.

Parameters
radixthe radix (between 2 and 36)
Returns
the int64 represented from this string. 0 if this string represents no number or one of too large magnitude.
sal_uInt32 rtl::OString::toUInt32 ( sal_Int16  radix = 10) const
inline

Returns the uint32 value from this string.

This function can't be used for language specific conversion.

Parameters
radixthe radix (between 2 and 36)
Returns
the uint32 represented from this string. 0 if this string represents no number or one of too large magnitude.
Since
LibreOffice 4.2
sal_uInt64 rtl::OString::toUInt64 ( sal_Int16  radix = 10) const
inline

Returns the uint64 value from this string.

This function can't be used for language specific conversion.

Parameters
radixthe radix (between 2 and 36)
Returns
the uint64 represented from this string. 0 if this string represents no number or one of too large magnitude.
Since
LibreOffice 4.1
SAL_WARN_UNUSED_RESULT OString rtl::OString::trim ( ) const
inline

Returns a new string resulting from removing white space from both ends of the string.

All characters that have codes less than or equal to 32 (the space character) are considered to be white space. If the string doesn't contain white spaces at both ends, then the new string is assigned with str.

Returns
the string, with white space removed from the front and end.
static OString rtl::OString::valueOf ( sal_Bool  b)
inlinestatic

Returns the string representation of the sal_Bool argument.

If the sal_Bool is true, the string "true" is returned. If the sal_Bool is false, the string "false" is returned. This function can't be used for language specific conversion.

Parameters
ba sal_Bool.
Returns
a string with the string representation of the argument.
Deprecated:
use boolean()
static OString rtl::OString::valueOf ( sal_Char  c)
inlinestatic

Returns the string representation of the char argument.

Parameters
ca character.
Returns
a string with the string representation of the argument.
Deprecated:
use operator, function or constructor taking char or sal_Unicode argument
static OString rtl::OString::valueOf ( sal_Int32  i,
sal_Int16  radix = 10 
)
inlinestatic

Returns the string representation of the int argument.

This function can't be used for language specific conversion.

Parameters
ia int32.
radixthe radix (between 2 and 36)
Returns
a string with the string representation of the argument.
Deprecated:
use number()
static OString rtl::OString::valueOf ( sal_Int64  ll,
sal_Int16  radix = 10 
)
inlinestatic

Returns the string representation of the long argument.

This function can't be used for language specific conversion.

Parameters
lla int64.
radixthe radix (between 2 and 36)
Returns
a string with the string representation of the argument.
Deprecated:
use number()
static OString rtl::OString::valueOf ( float  f)
inlinestatic

Returns the string representation of the float argument.

This function can't be used for language specific conversion.

Parameters
fa float.
Returns
a string with the string representation of the argument.
Deprecated:
use number()
static OString rtl::OString::valueOf ( double  d)
inlinestatic

Returns the string representation of the double argument.

This function can't be used for language specific conversion.

Parameters
da double.
Returns
a string with the string representation of the argument.
Deprecated:
use number()

Friends And Related Function Documentation

bool operator!= ( const OString rStr1,
const OString rStr2 
)
friend
template<typename T >
libreoffice_internal::CharPtrDetector< T, bool >::Type operator!= ( const OString rStr1,
const T &  value 
)
friend
template<typename T >
libreoffice_internal::NonConstCharArrayDetector< T, bool >::Type operator!= ( const OString rStr1,
T &  value 
)
friend
template<typename T >
libreoffice_internal::CharPtrDetector< T, bool >::Type operator!= ( const T &  value,
const OString rStr2 
)
friend
template<typename T >
libreoffice_internal::NonConstCharArrayDetector< T, bool >::Type operator!= ( T &  value,
const OString rStr2 
)
friend
template<typename T >
libreoffice_internal::ConstCharArrayDetector< T, bool >::Type operator!= ( const OString rStr,
T &  literal 
)
friend

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. This function accepts an ASCII string literal as its argument.

Since
LibreOffice 3.6
template<typename T >
libreoffice_internal::ConstCharArrayDetector< T, bool >::Type operator!= ( T &  literal,
const OString rStr 
)
friend

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. This function accepts an ASCII string literal as its argument.

Since
LibreOffice 3.6
OString operator+ ( const OString str1,
const OString str2 
)
friend
bool operator< ( const OString rStr1,
const OString rStr2 
)
friend
bool operator<= ( const OString rStr1,
const OString rStr2 
)
friend
bool operator== ( const OString rStr1,
const OString rStr2 
)
friend
template<typename T >
libreoffice_internal::CharPtrDetector< T, bool >::Type operator== ( const OString rStr1,
const T &  value 
)
friend
template<typename T >
libreoffice_internal::NonConstCharArrayDetector< T, bool >::Type operator== ( const OString rStr1,
T &  value 
)
friend
template<typename T >
libreoffice_internal::CharPtrDetector< T, bool >::Type operator== ( const T &  value,
const OString rStr2 
)
friend
template<typename T >
libreoffice_internal::NonConstCharArrayDetector< T, bool >::Type operator== ( T &  value,
const OString rStr2 
)
friend
template<typename T >
libreoffice_internal::ConstCharArrayDetector< T, bool >::Type operator== ( const OString rStr,
T &  literal 
)
friend

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. This function accepts an ASCII string literal as its argument.

Since
LibreOffice 3.6
template<typename T >
libreoffice_internal::ConstCharArrayDetector< T, bool >::Type operator== ( T &  literal,
const OString rStr 
)
friend

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. This function accepts an ASCII string literal as its argument.

Since
LibreOffice 3.6
bool operator> ( const OString rStr1,
const OString rStr2 
)
friend
bool operator>= ( const OString rStr1,
const OString rStr2 
)
friend

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