23 #include <string_view>
27 #include <rtl/character.hxx>
28 #include <rtl/ustring.hxx>
29 #include <rtl/ustrbuf.hxx>
30 #include <rtl/string.hxx>
31 #include <rtl/strbuf.hxx>
38 #include <com/sun/star/i18n/BreakIterator.hpp>
39 #include <com/sun/star/i18n/CharType.hpp>
40 #include <com/sun/star/i18n/Collator.hpp>
47 template <
typename T,
typename C> T tmpl_stripStart(
const T &rIn,
55 while (i < rIn.getLength())
57 if (rIn[i] != cRemove)
68 return tmpl_stripStart<OString, char>(rIn, c);
73 return tmpl_stripStart<OUString, sal_Unicode>(rIn, c);
78 template <
typename T,
typename C> T tmpl_stripEnd(
const T &rIn,
84 sal_Int32 i = rIn.getLength();
88 if (rIn[i-1] != cRemove)
93 return rIn.copy(0, i);
99 return tmpl_stripEnd<OString, char>(rIn, c);
104 return tmpl_stripEnd<OUString, sal_Unicode>(rIn, c);
107 OString
strip(
const OString &rIn,
char c)
119 template <
typename T,
typename C> sal_Int32 tmpl_getTokenCount(
const T &rIn,
126 sal_Int32 nTokCount = 1;
127 for (sal_Int32 i = 0; i < rIn.getLength(); ++i)
138 return tmpl_getTokenCount<OString, char>(rIn, cTok);
143 return tmpl_getTokenCount<OUString, sal_Unicode>(rIn, cTok);
147 OUString
const & str, sal_Int32 nStart, sal_Int32 nLength )
150 for( sal_Int32 i = nStart; i < nStart + nLength; )
152 sal_uInt32 c = str.iterateCodePoints(&i);
153 sal_uInt32
value = 0;
156 else if( c >= 0x1D7F6 )
158 else if( c >= 0x1D7EC )
160 else if( c >= 0x1D7E2 )
162 else if( c >= 0x1D7D8 )
164 else if( c >= 0x1D7CE )
166 else if( c >= 0x11066 )
168 else if( c >= 0x104A0 )
170 else if( c >= 0xFF10 )
172 else if( c >= 0xABF0 )
174 else if( c >= 0xAA50 )
176 else if( c >= 0xA9D0 )
178 else if( c >= 0xA900 )
180 else if( c >= 0xA8D0 )
182 else if( c >= 0xA620 )
184 else if( c >= 0x1C50 )
186 else if( c >= 0x1C40 )
188 else if( c >= 0x1BB0 )
190 else if( c >= 0x1B50 )
192 else if( c >= 0x1A90 )
194 else if( c >= 0x1A80 )
196 else if( c >= 0x19D0 )
198 else if( c >= 0x1946 )
200 else if( c >= 0x1810 )
202 else if( c >= 0x17E0 )
204 else if( c >= 0x1090 )
206 else if( c >= 0x1040 )
208 else if( c >= 0x0F20 )
210 else if( c >= 0x0ED0 )
212 else if( c >= 0x0E50 )
214 else if( c >= 0x0D66 )
216 else if( c >= 0x0CE6 )
218 else if( c >= 0x0C66 )
220 else if( c >= 0x0BE6 )
222 else if( c >= 0x0B66 )
224 else if( c >= 0x0AE6 )
226 else if( c >= 0x0A66 )
228 else if( c >= 0x09E6 )
230 else if( c >= 0x0966 )
232 else if( c >= 0x07C0 )
234 else if( c >= 0x06F0 )
236 else if( c >= 0x0660 )
238 result = result * 10 + value;
244 OUString
const & str )
254 uno::Sequence< OUString >
const& i_rSeq)
259 return buf.makeStringAndClear();
262 std::vector<OUString>
265 std::vector< OUString > vec;
270 rStr.getToken(0, cSeparator, idx);
282 uno::Sequence< OUString >
285 std::vector< OUString > vec =
split(i_rString,
',');
289 OString
join(std::string_view rSeparator,
const std::vector<OString>& rSequence)
292 for (
size_t i = 0; i < rSequence.size(); ++i)
295 aBuffer.append(rSeparator);
296 aBuffer.append(rSequence[i]);
298 return aBuffer.makeStringAndClear();
302 const uno::Reference< i18n::XCollator > &rCollator,
303 const uno::Reference< i18n::XBreakIterator > &rBI,
304 const lang::Locale &rLocale )
308 sal_Int32 nLHSLastNonDigitPos = 0;
309 sal_Int32 nRHSLastNonDigitPos = 0;
310 sal_Int32 nLHSFirstDigitPos = 0;
311 sal_Int32 nRHSFirstDigitPos = 0;
313 while (nLHSFirstDigitPos < rLHS.getLength() || nRHSFirstDigitPos < rRHS.getLength())
315 sal_Int32 nLHSChunkLen;
316 sal_Int32 nRHSChunkLen;
319 nLHSFirstDigitPos = rBI->nextCharBlock(rLHS, nLHSLastNonDigitPos,
320 rLocale, i18n::CharType::DECIMAL_DIGIT_NUMBER);
321 nRHSFirstDigitPos = rBI->nextCharBlock(rRHS, nRHSLastNonDigitPos,
322 rLocale, i18n::CharType::DECIMAL_DIGIT_NUMBER);
323 if (nLHSFirstDigitPos == -1)
324 nLHSFirstDigitPos = rLHS.getLength();
325 if (nRHSFirstDigitPos == -1)
326 nRHSFirstDigitPos = rRHS.getLength();
327 nLHSChunkLen = nLHSFirstDigitPos - nLHSLastNonDigitPos;
328 nRHSChunkLen = nRHSFirstDigitPos - nRHSLastNonDigitPos;
330 nRet = rCollator->compareSubstring(rLHS, nLHSLastNonDigitPos,
331 nLHSChunkLen, rRHS, nRHSLastNonDigitPos, nRHSChunkLen);
336 nLHSLastNonDigitPos = rBI->endOfCharBlock(rLHS, nLHSFirstDigitPos,
337 rLocale, i18n::CharType::DECIMAL_DIGIT_NUMBER);
338 nRHSLastNonDigitPos = rBI->endOfCharBlock(rRHS, nRHSFirstDigitPos,
339 rLocale, i18n::CharType::DECIMAL_DIGIT_NUMBER);
340 if (nLHSLastNonDigitPos == -1)
341 nLHSLastNonDigitPos = rLHS.getLength();
342 if (nRHSLastNonDigitPos == -1)
343 nRHSLastNonDigitPos = rRHS.getLength();
344 nLHSChunkLen = nLHSLastNonDigitPos - nLHSFirstDigitPos;
345 nRHSChunkLen = nRHSLastNonDigitPos - nRHSFirstDigitPos;
356 nRet = (nLHS < nRHS) ? -1 : 1;
365 const uno::Reference< uno::XComponentContext > &rContext,
366 const lang::Locale &rLocale) :
m_aLocale(rLocale)
370 m_xBI = i18n::BreakIterator::create( rContext );
376 rString.getStr(), rString.getStr() + rString.getLength(),
377 [](
unsigned char c){
return rtl::isAsciiDigit(c); });
383 rString.getStr(), rString.getStr() + rString.getLength(),
384 [](
sal_Unicode c){
return rtl::isAsciiDigit(c); });
389 template <
typename T,
typename O> T tmpl_reverseString(
const T &rIn)
394 sal_Int32 i = rIn.getLength();
397 sBuf.append(rIn[--i]);
398 return sBuf.makeStringAndClear();
404 return tmpl_reverseString<OUString, OUStringBuffer>(rStr);
409 return tmpl_reverseString<OString, OStringBuffer>(rStr);
413 sal_Unicode const*
const pChars, sal_Int32
const nPos)
415 for (sal_Int32 i = nPos; i < rIn.getLength(); ++i)
434 for (sal_Int32 i = 0; i < rIn.getLength(); ++i)
452 buf.append(rIn.subView(0, i));
462 return isFound ? buf.makeStringAndClear() : rIn;
466 const OUString& rNewToken)
468 sal_Int32 nLen = rIn.getLength();
470 sal_Int32 nFirstChar = 0;
483 else if (nTok > nToken)
491 return rIn.replaceAt(nFirstChar, i-nFirstChar, rNewToken);
OString stripEnd(const OString &rIn, char c)
Strips occurrences of a character from the end of the source string.
css::lang::Locale const m_aLocale
OutputIter intersperse(ForwardIter start, ForwardIter end, OutputIter out, T const &separator)
algorithm similar to std::copy, but inserts a separator between elements.
sal_Int32 getTokenCount(const OString &rIn, char cTok)
Returns number of tokens in an OUString.
std::vector< OUString > split(const OUString &rStr, sal_Unicode cSeparator)
OString join(std::string_view rSeparator, const std::vector< OString > &rSequence)
Return a string which is the concatenation of the strings in the sequence.
bool isdigitAsciiString(const OString &rString)
Determine if an OString contains solely ASCII numeric digits.
css::uno::Reference< css::i18n::XBreakIterator > m_xBI
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)
NaturalStringSorter(const css::uno::Reference< css::uno::XComponentContext > &rContext, const css::lang::Locale &rLocale)
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.
output iterator that appends OUStrings into an OUStringBuffer.
OUString removeAny(OUString const &rIn, sal_Unicode const *const pChars)
Remove any of a list of code units in the string.
static sal_uInt32 decimalStringToNumber(OUString const &str, sal_Int32 nStart, sal_Int32 nLength)
std::unique_ptr< char[]> aBuffer
css::uno::Sequence< DstElementType > containerToSequence(const SrcType &i_Container)
Copy from a container into a Sequence.
OString strip(const OString &rIn, char c)
Strips occurrences of a character from the start and end of the source string.
OString stripStart(const OString &rIn, char c)
Strips occurrences of a character from the start of the source string.
OUString setToken(const OUString &rIn, sal_Int32 nToken, sal_Unicode cTok, const OUString &rNewToken)
Replace a token in a string.
OUString reverseString(const OUString &rStr)
Reverse an OUString.
OUString convertCommaSeparated(uno::Sequence< OUString > const &i_rSeq)
css::uno::Reference< css::i18n::XCollator > m_xCollator