LibreOffice Module comphelper (master)  1
Namespaces | Classes | Functions
comphelper::string Namespace Reference

Namespaces

 detail
 

Classes

class  NaturalStringSorter
 

Functions

OString stripStart (const OString &rIn, sal_Char c)
 Strips occurrences of a character from the start of the source string. More...
 
OUString stripStart (const OUString &rIn, sal_Unicode c)
 Strips occurrences of a character from the start of the source string. More...
 
OString stripEnd (const OString &rIn, sal_Char c)
 Strips occurrences of a character from the end of the source string. More...
 
OUString stripEnd (const OUString &rIn, sal_Unicode c)
 Strips occurrences of a character from the end of the source string. More...
 
OString strip (const OString &rIn, sal_Char c)
 Strips occurrences of a character from the start and end of the source string. More...
 
OUString strip (const OUString &rIn, sal_Unicode c)
 Strips occurrences of a character from the start and end of the source string. More...
 
sal_Int32 getTokenCount (const OString &rIn, sal_Char cTok)
 Returns number of tokens in an OUString. More...
 
sal_Int32 getTokenCount (const OUString &rIn, sal_Unicode cTok)
 Returns number of tokens in an OUString. More...
 
static sal_uInt32 decimalStringToNumber (OUString const &str, sal_Int32 nStart, sal_Int32 nLength)
 
sal_uInt32 decimalStringToNumber (OUString const &str)
 Convert a decimal string to a number. More...
 
OUString convertCommaSeparated (uno::Sequence< OUString > const &i_rSeq)
 
std::vector< OUString > split (const OUString &rStr, sal_Unicode cSeparator)
 
uno::Sequence< OUString > convertCommaSeparated (OUString const &i_rString)
 Convert a single comma separated string to a sequence of strings. More...
 
OString join (const OString &rSeparator, const std::vector< OString > &rSequence)
 Return a string which is the concatenation of the strings in the sequence. More...
 
sal_Int32 compareNatural (const OUString &rLHS, const OUString &rRHS, const uno::Reference< i18n::XCollator > &rCollator, const uno::Reference< i18n::XBreakIterator > &rBI, const lang::Locale &rLocale)
 
bool isdigitAsciiString (const OString &rString)
 Determine if an OString contains solely ASCII numeric digits. More...
 
bool isdigitAsciiString (const OUString &rString)
 Determine if an OUString contains solely ASCII numeric digits. More...
 
OUString reverseString (const OUString &rStr)
 Reverse an OUString. More...
 
OString reverseString (const OString &rStr)
 Reverse an OString. More...
 
sal_Int32 indexOfAny (OUString const &rIn, sal_Unicode const *const pChars, sal_Int32 const nPos)
 Find any of a list of code units in the string. More...
 
OUString removeAny (OUString const &rIn, sal_Unicode const *const pChars)
 Remove any of a list of code units in the string. More...
 
OUString setToken (const OUString &rIn, sal_Int32 nToken, sal_Unicode cTok, const OUString &rNewToken)
 Replace a token in a string. More...
 
bool equals (const OUString &rIn, sal_Unicode c)
 Compare an OUString to a single char. More...
 
OUStringBuffer & remove (OUStringBuffer &rIn, sal_Unicode c)
 Removes all occurrences of a character from within the source string. More...
 
OUStringBuffer & truncateToLength (OUStringBuffer &rBuffer, sal_Int32 nLength)
 Truncate a buffer to a given length. More...
 
OStringBuffer & padToLength (OStringBuffer &rBuffer, sal_Int32 nLength, sal_Char cFill= '\0')
 Pad a buffer to a given length using a given char. More...
 
OUStringBuffer & padToLength (OUStringBuffer &rBuffer, sal_Int32 nLength, sal_Unicode cFill= '\0')
 
COMPHELPER_DLLPUBLIC OUString convertCommaSeparated (css::uno::Sequence< OUString > const &i_rSeq)
 Convert a sequence of strings to a single comma separated string. More...
 
COMPHELPER_DLLPUBLIC sal_Int32 compareNatural (const OUString &rLHS, const OUString &rRHS, const css::uno::Reference< css::i18n::XCollator > &rCollator, const css::uno::Reference< css::i18n::XBreakIterator > &rBI, const css::lang::Locale &rLocale)
 Compares two strings using natural order. More...
 

Function Documentation

sal_Int32 comphelper::string::compareNatural ( const OUString &  rLHS,
const OUString &  rRHS,
const uno::Reference< i18n::XCollator > &  rCollator,
const uno::Reference< i18n::XBreakIterator > &  rBI,
const lang::Locale &  rLocale 
)

Definition at line 301 of file string.cxx.

References decimalStringToNumber().

Referenced by comphelper::string::NaturalStringSorter::compare().

COMPHELPER_DLLPUBLIC sal_Int32 comphelper::string::compareNatural ( const OUString &  rLHS,
const OUString &  rRHS,
const css::uno::Reference< css::i18n::XCollator > &  rCollator,
const css::uno::Reference< css::i18n::XBreakIterator > &  rBI,
const css::lang::Locale &  rLocale 
)

Compares two strings using natural order.

For non digit characters, the comparison use the same algorithm as rtl_str_compare. When a number is encountered during the comparison, natural order is used. Thus, Heading 10 will be considered as greater than Heading 2. Numerical comparison is done using decimal representation.

Beware that "MyString 001" and "MyString 1" will be considered as equal since leading 0 are meaningless.

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
OUString comphelper::string::convertCommaSeparated ( uno::Sequence< OUString > const &  i_rSeq)

Definition at line 253 of file string.cxx.

References comphelper::intersperse().

COMPHELPER_DLLPUBLIC OUString comphelper::string::convertCommaSeparated ( css::uno::Sequence< OUString > const &  i_rSeq)

Convert a sequence of strings to a single comma separated string.

Note that no escaping of commas or anything fancy is done.

Parameters
i_rSeqA list of strings to be concatenated.
Returns
A single string containing the concatenation of the given list, interspersed with the string ", ".
COMPHELPER_DLLPUBLIC css::uno::Sequence< OUString > comphelper::string::convertCommaSeparated ( OUString const &  i_rString)

Convert a single comma separated string to a sequence of strings.

Note that no escaping of commas or anything fancy is done.

Parameters
i_rStringA string containing comma-separated words.
Returns
A sequence of strings resulting from splitting the given string at ',' tokens and stripping whitespace.

Definition at line 283 of file string.cxx.

References comphelper::containerToSequence(), and split().

static sal_uInt32 comphelper::string::decimalStringToNumber ( OUString const &  str,
sal_Int32  nStart,
sal_Int32  nLength 
)
static

Definition at line 146 of file string.cxx.

References result, and value.

Referenced by compareNatural(), and decimalStringToNumber().

COMPHELPER_DLLPUBLIC sal_uInt32 comphelper::string::decimalStringToNumber ( OUString const &  str)

Convert a decimal string to a number.

The string must be base-10, no sign but can contain any codepoint listed in the "Number, Decimal Digit" Unicode category.

No verification is made about the validity of the string, passing string not containing decimal digit code points gives unspecified results

If your string is guaranteed to contain only ASCII digit use OUString::toInt32 instead.

Parameters
strThe string to convert containing only decimal digit codepoints.
Returns
The value of the string as an int32.

Definition at line 243 of file string.cxx.

References decimalStringToNumber().

bool comphelper::string::equals ( const OUString &  rIn,
sal_Unicode  c 
)
inline

Compare an OUString to a single char.

Parameters
rInThe input OUString
cThe character to compare against
Returns
true if rIn has one char and its equal to c

Definition at line 50 of file string.hxx.

COMPHELPER_DLLPUBLIC sal_Int32 comphelper::string::getTokenCount ( const OString &  rIn,
sal_Char  cTok 
)

Returns number of tokens in an OUString.

Parameters
rInthe input OString
cTokthe character which separate the tokens.
Returns
the number of tokens

Definition at line 136 of file string.cxx.

COMPHELPER_DLLPUBLIC sal_Int32 comphelper::string::getTokenCount ( const OUString &  rIn,
sal_Unicode  cTok 
)

Returns number of tokens in an OUString.

Parameters
rInthe input OUString
cTokthe character which separate the tokens.
Returns
the number of tokens

Definition at line 141 of file string.cxx.

COMPHELPER_DLLPUBLIC sal_Int32 comphelper::string::indexOfAny ( OUString const &  rIn,
sal_Unicode const *const  pChars,
sal_Int32 const  nPos 
)

Find any of a list of code units in the string.

Parameters
rInOUString to search
pChars0-terminated array of sal_Unicode code units to search for
nPosstart position
Returns
position of first occurrence of any of the elements of pChars or -1 if none of the code units occur in the string

Definition at line 412 of file string.cxx.

References pChar.

COMPHELPER_DLLPUBLIC bool comphelper::string::isdigitAsciiString ( const OString &  rString)

Determine if an OString contains solely ASCII numeric digits.

Parameters
rStringAn OString
Returns
false if string contains any characters outside the ASCII '0'-'9' range true otherwise, including for empty string

Definition at line 373 of file string.cxx.

COMPHELPER_DLLPUBLIC bool comphelper::string::isdigitAsciiString ( const OUString &  rString)

Determine if an OUString contains solely ASCII numeric digits.

Parameters
rStringAn OUString
Returns
false if string contains any characters outside the ASCII '0'-'9' range true otherwise, including for empty string

Definition at line 380 of file string.cxx.

COMPHELPER_DLLPUBLIC OString comphelper::string::join ( const OString &  rSeparator,
const std::vector< OString > &  rSequence 
)

Return a string which is the concatenation of the strings in the sequence.

Definition at line 289 of file string.cxx.

OStringBuffer& comphelper::string::padToLength ( OStringBuffer &  rBuffer,
sal_Int32  nLength,
sal_Char  cFill = '\0' 
)
inline

Pad a buffer to a given length using a given char.

If the StringBuffer has less characters than nLength it will be expanded on the right to nLength characters, with the expansion filled using cFill.

Has no effect if the StringBuffer is >= nLength

Parameters
rBufStringBuffer to operate on
nLengthLength to pad the buffer to
cFillcharacter to fill expansion with
Returns
rBuf;

Definition at line 224 of file string.hxx.

References comphelper::string::detail::padToLength().

OUStringBuffer& comphelper::string::padToLength ( OUStringBuffer &  rBuffer,
sal_Int32  nLength,
sal_Unicode  cFill = '\0' 
)
inline

Definition at line 231 of file string.hxx.

References comphelper::string::detail::padToLength().

OUStringBuffer& comphelper::string::remove ( OUStringBuffer &  rIn,
sal_Unicode  c 
)
inline
COMPHELPER_DLLPUBLIC OUString comphelper::string::removeAny ( OUString const &  rIn,
sal_Unicode const *const  pChars 
)

Remove any of a list of code units in the string.

Parameters
rInOUString to search
pChars0-terminated array of sal_Unicode code units to search for
Returns
OUString that has all of the pChars code units removed

Definition at line 429 of file string.cxx.

References pChar.

COMPHELPER_DLLPUBLIC OUString comphelper::string::reverseString ( const OUString &  rStr)

Reverse an OUString.

Parameters
rInthe input OUString
Returns
the reversed input

Definition at line 402 of file string.cxx.

COMPHELPER_DLLPUBLIC OString comphelper::string::reverseString ( const OString &  rStr)

Reverse an OString.

Parameters
rInthe input OString
Returns
the reversed input

Definition at line 407 of file string.cxx.

COMPHELPER_DLLPUBLIC OUString comphelper::string::setToken ( const OUString &  rIn,
sal_Int32  nToken,
sal_Unicode  cTok,
const OUString &  rNewToken 
)

Replace a token in a string.

Parameters
rInOUString in which the token is to be replaced
nTokenwhich nToken to replace
cToktoken delimiter
rNewTokenreplacement token
Returns
original string with token nToken replaced by rNewToken

Definition at line 465 of file string.cxx.

COMPHELPER_DLLPUBLIC std::vector< OUString > comphelper::string::split ( const OUString &  rStr,
sal_Unicode  cSeparator 
)

Definition at line 263 of file string.cxx.

Referenced by convertCommaSeparated().

COMPHELPER_DLLPUBLIC OString comphelper::string::strip ( const OString &  rIn,
sal_Char  c 
)

Strips occurrences of a character from the start and end of the source string.

Parameters
rInThe input OString
cThe character to be stripped from the start and end
Returns
The resulting OString

Definition at line 107 of file string.cxx.

References stripEnd(), and stripStart().

COMPHELPER_DLLPUBLIC OUString comphelper::string::strip ( const OUString &  rIn,
sal_Unicode  c 
)

Strips occurrences of a character from the start and end of the source string.

Parameters
rInThe input OUString
cThe character to be stripped from the start and end
Returns
The resulting OUString

Definition at line 112 of file string.cxx.

References stripEnd(), and stripStart().

COMPHELPER_DLLPUBLIC OString comphelper::string::stripEnd ( const OString &  rIn,
sal_Char  c 
)

Strips occurrences of a character from the end of the source string.

Parameters
rInThe input OString
cThe character to be stripped from the end
Returns
The resulting OString

Definition at line 97 of file string.cxx.

Referenced by strip().

COMPHELPER_DLLPUBLIC OUString comphelper::string::stripEnd ( const OUString &  rIn,
sal_Unicode  c 
)

Strips occurrences of a character from the end of the source string.

Parameters
rInThe input OUString
cThe character to be stripped from the end
Returns
The resulting OUString

Definition at line 102 of file string.cxx.

COMPHELPER_DLLPUBLIC OString comphelper::string::stripStart ( const OString &  rIn,
sal_Char  c 
)

Strips occurrences of a character from the start of the source string.

Parameters
rInThe input OString
cThe character to be stripped from the start
Returns
The resulting OString

Definition at line 66 of file string.cxx.

Referenced by strip().

COMPHELPER_DLLPUBLIC OUString comphelper::string::stripStart ( const OUString &  rIn,
sal_Unicode  c 
)

Strips occurrences of a character from the start of the source string.

Parameters
rInThe input OUString
cThe character to be stripped from the start
Returns
The resulting OUString

Definition at line 71 of file string.cxx.

OUStringBuffer& comphelper::string::truncateToLength ( OUStringBuffer &  rBuffer,
sal_Int32  nLength 
)
inline

Truncate a buffer to a given length.

If the StringBuffer has more characters than nLength it will be truncated on the right to nLength characters.

Has no effect if the StringBuffer is <= nLength

Parameters
rBufStringBuffer to operate on
nLengthLength to truncate the buffer to
Returns
rBuf;

Definition at line 189 of file string.hxx.

References comphelper::string::detail::truncateToLength().