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

Namespaces

namespace  detail
 

Classes

class  NaturalStringSorter
 

Functions

OString stripStart (const OString &rIn, char c)
 Strips occurrences of a character from the start of the source string. More...
 
std::string_view stripStart (std::string_view rIn, char c)
 
OUString stripStart (const OUString &rIn, sal_Unicode c)
 Strips occurrences of a character from the start of the source string. More...
 
std::u16string_view stripStart (std::u16string_view rIn, sal_Unicode c)
 
OString stripEnd (const OString &rIn, char c)
 Strips occurrences of a character from the end of the source string. More...
 
std::string_view stripEnd (std::string_view rIn, char c)
 
OUString stripEnd (const OUString &rIn, sal_Unicode c)
 Strips occurrences of a character from the end of the source string. More...
 
std::u16string_view stripEnd (std::u16string_view rIn, sal_Unicode c)
 
OString strip (const OString &rIn, char c)
 Strips occurrences of a character from the start and end of the source string. More...
 
std::string_view strip (std::string_view rIn, char c)
 
OUString strip (const OUString &rIn, sal_Unicode c)
 Strips occurrences of a character from the start and end of the source string. More...
 
std::u16string_view strip (std::u16string_view rIn, sal_Unicode c)
 
sal_Int32 getTokenCount (std::string_view rIn, char cTok)
 Returns number of tokens in an OUString. More...
 
sal_Int32 getTokenCount (std::u16string_view rIn, sal_Unicode cTok)
 Returns number of tokens in an OUString. More...
 
sal_uInt32 decimalStringToNumber (std::u16string_view str)
 Convert a decimal string to a number. More...
 
OUString convertCommaSeparated (uno::Sequence< OUString > const &i_rSeq)
 
std::vector< OUString > split (std::u16string_view rStr, sal_Unicode cSeparator)
 
uno::Sequence< OUString > convertCommaSeparated (std::u16string_view i_rString)
 Convert a single comma separated string to a sequence of strings. More...
 
OString join (std::string_view 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 (std::string_view rString)
 Determine if an OString contains solely ASCII numeric digits. More...
 
bool isdigitAsciiString (std::u16string_view rString)
 Determine if an OUString contains solely ASCII numeric digits. More...
 
OUString reverseString (std::u16string_view rStr)
 Reverse an OUString's UTF-16 code units. More...
 
OUString reverseCodePoints (OUString const &str)
 Reverse an OUString's Unicode code points. More...
 
sal_Int32 indexOfAny (std::u16string_view rIn, sal_Unicode const *const pChars, sal_Int32 const nPos)
 Find any of a list of code units in the string. More...
 
OUString removeAny (std::u16string_view 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, std::u16string_view rNewToken)
 Replace a token in a string. More...
 
void replaceAt (OUStringBuffer &rIn, sal_Int32 nIndex, sal_Int32 nCount, std::u16string_view newStr)
 Similar to OUString::replaceAt, but for an OUStringBuffer. More...
 
OUString sanitizeStringSurrogates (const OUString &rString)
 Sanitize an OUString to not have invalid surrogates. 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, 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...
 
OUString encodeForXml (std::u16string_view rStr)
 

Function Documentation

◆ compareNatural() [1/2]

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

◆ compareNatural() [2/2]

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 413 of file string.cxx.

References decimalStringToNumber().

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

◆ convertCommaSeparated() [1/3]

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 ", ".

◆ convertCommaSeparated() [2/3]

COMPHELPER_DLLPUBLIC css::uno::Sequence< OUString > comphelper::string::convertCommaSeparated ( std::u16string_view  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 395 of file string.cxx.

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

◆ convertCommaSeparated() [3/3]

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

Definition at line 366 of file string.cxx.

References comphelper::intersperse().

◆ decimalStringToNumber()

COMPHELPER_DLLPUBLIC sal_uInt32 comphelper::string::decimalStringToNumber ( std::u16string_view  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 266 of file string.cxx.

References i, o3tl::iterateCodePoints(), result, and value.

Referenced by compareNatural().

◆ encodeForXml()

OUString comphelper::string::encodeForXml ( std::u16string_view  rStr)
inline

Definition at line 26 of file xmlencode.hxx.

References pos.

◆ getTokenCount() [1/2]

COMPHELPER_DLLPUBLIC sal_Int32 comphelper::string::getTokenCount ( std::string_view  rIn,
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 256 of file string.cxx.

◆ getTokenCount() [2/2]

COMPHELPER_DLLPUBLIC sal_Int32 comphelper::string::getTokenCount ( std::u16string_view  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 261 of file string.cxx.

◆ indexOfAny()

COMPHELPER_DLLPUBLIC sal_Int32 comphelper::string::indexOfAny ( std::u16string_view  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 537 of file string.cxx.

References i, nPos, and pChar.

◆ isdigitAsciiString() [1/2]

COMPHELPER_DLLPUBLIC bool comphelper::string::isdigitAsciiString ( std::string_view  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 502 of file string.cxx.

◆ isdigitAsciiString() [2/2]

COMPHELPER_DLLPUBLIC bool comphelper::string::isdigitAsciiString ( std::u16string_view  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 509 of file string.cxx.

◆ join()

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

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

Definition at line 401 of file string.cxx.

References aBuffer, and i.

◆ padToLength() [1/2]

OStringBuffer & comphelper::string::padToLength ( OStringBuffer &  rBuffer,
sal_Int32  nLength,
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 217 of file string.hxx.

References nLength, and comphelper::string::detail::padToLength().

◆ padToLength() [2/2]

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

Definition at line 224 of file string.hxx.

References nLength, and comphelper::string::detail::padToLength().

◆ remove()

OUStringBuffer & comphelper::string::remove ( OUStringBuffer &  rIn,
sal_Unicode  c 
)
inline

◆ removeAny()

COMPHELPER_DLLPUBLIC OUString comphelper::string::removeAny ( std::u16string_view  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 554 of file string.cxx.

References i, and pChar.

◆ replaceAt()

COMPHELPER_DLLPUBLIC void comphelper::string::replaceAt ( OUStringBuffer &  rIn,
sal_Int32  nIndex,
sal_Int32  nCount,
std::u16string_view  newStr 
)

Similar to OUString::replaceAt, but for an OUStringBuffer.

Replace n = count characters from position index in this string with newStr.

Definition at line 625 of file string.cxx.

References o3tl::make_unsigned(), nCount, and nIndex.

◆ reverseCodePoints()

COMPHELPER_DLLPUBLIC OUString comphelper::string::reverseCodePoints ( OUString const &  str)

Reverse an OUString's Unicode code points.

Definition at line 528 of file string.cxx.

References i.

◆ reverseString()

COMPHELPER_DLLPUBLIC OUString comphelper::string::reverseString ( std::u16string_view  rStr)

Reverse an OUString's UTF-16 code units.

Parameters
rInthe input OUString
Returns
the reversed input

Definition at line 516 of file string.cxx.

References i.

◆ sanitizeStringSurrogates()

COMPHELPER_DLLPUBLIC OUString comphelper::string::sanitizeStringSurrogates ( const OUString &  rString)

Sanitize an OUString to not have invalid surrogates.

Parameters
rStringAn OUString
Returns
same string if no surrogates or surrogates are valid. Otherwise the string truncated to the valid sequence.

Definition at line 650 of file string.cxx.

References i, and SAL_WARN.

◆ setToken()

COMPHELPER_DLLPUBLIC OUString comphelper::string::setToken ( const OUString &  rIn,
sal_Int32  nToken,
sal_Unicode  cTok,
std::u16string_view  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 590 of file string.cxx.

References i, nToken, and rNewToken.

◆ split()

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

Definition at line 376 of file string.cxx.

References o3tl::getToken(), idx, and o3tl::trim().

Referenced by convertCommaSeparated().

◆ strip() [1/4]

COMPHELPER_DLLPUBLIC OString comphelper::string::strip ( const OString &  rIn,
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 217 of file string.cxx.

◆ strip() [2/4]

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 227 of file string.cxx.

◆ strip() [3/4]

COMPHELPER_DLLPUBLIC std::string_view comphelper::string::strip ( std::string_view  rIn,
char  c 
)

Definition at line 222 of file string.cxx.

◆ strip() [4/4]

COMPHELPER_DLLPUBLIC std::u16string_view comphelper::string::strip ( std::u16string_view  rIn,
sal_Unicode  c 
)

Definition at line 232 of file string.cxx.

◆ stripEnd() [1/4]

COMPHELPER_DLLPUBLIC OString comphelper::string::stripEnd ( const OString &  rIn,
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 146 of file string.cxx.

◆ stripEnd() [2/4]

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 156 of file string.cxx.

◆ stripEnd() [3/4]

COMPHELPER_DLLPUBLIC std::string_view comphelper::string::stripEnd ( std::string_view  rIn,
char  c 
)

Definition at line 151 of file string.cxx.

◆ stripEnd() [4/4]

COMPHELPER_DLLPUBLIC std::u16string_view comphelper::string::stripEnd ( std::u16string_view  rIn,
sal_Unicode  c 
)

Definition at line 161 of file string.cxx.

◆ stripStart() [1/4]

COMPHELPER_DLLPUBLIC OString comphelper::string::stripStart ( const OString &  rIn,
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 88 of file string.cxx.

◆ stripStart() [2/4]

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 98 of file string.cxx.

◆ stripStart() [3/4]

COMPHELPER_DLLPUBLIC std::string_view comphelper::string::stripStart ( std::string_view  rIn,
char  c 
)

Definition at line 93 of file string.cxx.

◆ stripStart() [4/4]

COMPHELPER_DLLPUBLIC std::u16string_view comphelper::string::stripStart ( std::u16string_view  rIn,
sal_Unicode  c 
)

Definition at line 103 of file string.cxx.

◆ truncateToLength()

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 187 of file string.hxx.

References nLength, and comphelper::string::detail::truncateToLength().