summaryrefslogtreecommitdiffstats
path: root/include/rtl
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2020-12-11 17:44:34 +0100
committerStephan Bergmann <sbergman@redhat.com>2020-12-11 21:25:10 +0100
commit35e471bb4d1388cf5afcdcee214cf5111edf44e3 (patch)
treebb78f4f13f131f0cb206a9707cc3cfc495a3876a /include/rtl
parentalign anchor south-west to dropdown north-east (diff)
downloadcore-35e471bb4d1388cf5afcdcee214cf5111edf44e3.tar.gz
core-35e471bb4d1388cf5afcdcee214cf5111edf44e3.zip
Adapt the remaining OUString functions to std string_view
...for LIBO_INTERNAL_ONLY. These had been missed by 1b43cceaea2084a0489db68cd0113508f34b6643 "Make many OUString functions take std::u16string_view parameters" because they did not match the multi-overload pattern that was addressed there, but they nevertheless benefit from being changed just as well (witness e.g. the various resulting changes from copy() to subView()). This showed a conversion from OStringChar to std::string_view to be missing (while the corresponding conversion form OUStringChar to std::u16string_view was already present). The improvement to loplugin:stringadd became necessary to fix > [CPT] compilerplugins/clang/test/stringadd.cxx > error: 'error' diagnostics expected but not seen: > File ~/lo/core/compilerplugins/clang/test/stringadd.cxx Line 43 (directive at ~/lo/core/compilerplugins/clang/test/stringadd.cxx:42): simplify by merging with the preceding assignment [loplugin:stringadd] > File ~/lo/core/compilerplugins/clang/test/stringadd.cxx Line 61 (directive at ~/lo/core/compilerplugins/clang/test/stringadd.cxx:60): simplify by merging with the preceding assignment [loplugin:stringadd] > 2 errors generated. Change-Id: Ie40de0616a66e60e289c1af0ca60aed6f9ecc279 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/107602 Tested-by: Jenkins Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
Diffstat (limited to 'include/rtl')
-rw-r--r--include/rtl/stringutils.hxx1
-rw-r--r--include/rtl/ustring.hxx49
2 files changed, 50 insertions, 0 deletions
diff --git a/include/rtl/stringutils.hxx b/include/rtl/stringutils.hxx
index 7a1bc606ff5b..5208c06c3d12 100644
--- a/include/rtl/stringutils.hxx
+++ b/include/rtl/stringutils.hxx
@@ -45,6 +45,7 @@ namespace rtl
struct SAL_WARN_UNUSED OStringChar {
constexpr OStringChar(char theC): c(theC) {}
template<typename T> OStringChar(T &&) = delete;
+ constexpr operator std::string_view() const { return {&c, 1}; }
char const c;
};
diff --git a/include/rtl/ustring.hxx b/include/rtl/ustring.hxx
index 48aca3243383..9f8d08c8f9a5 100644
--- a/include/rtl/ustring.hxx
+++ b/include/rtl/ustring.hxx
@@ -800,11 +800,19 @@ public:
< 0 - if this string is less than the string argument
> 0 - if this string is greater than the string argument
*/
+#if defined LIBO_INTERNAL_ONLY
+ sal_Int32 compareTo( std::u16string_view str ) const
+ {
+ return rtl_ustr_compare_WithLength( pData->buffer, pData->length,
+ str.data(), str.length() );
+ }
+#else
sal_Int32 compareTo( const OUString & str ) const
{
return rtl_ustr_compare_WithLength( pData->buffer, pData->length,
str.pData->buffer, str.pData->length );
}
+#endif
/**
Compares two strings with a maximum count of characters.
@@ -821,11 +829,19 @@ public:
@since UDK 3.2.7
*/
+#if defined LIBO_INTERNAL_ONLY
+ sal_Int32 compareTo( std::u16string_view str, sal_Int32 maxLength ) const
+ {
+ return rtl_ustr_shortenedCompare_WithLength( pData->buffer, pData->length,
+ str.data(), str.length(), maxLength );
+ }
+#else
sal_Int32 compareTo( const OUString & str, sal_Int32 maxLength ) const
{
return rtl_ustr_shortenedCompare_WithLength( pData->buffer, pData->length,
str.pData->buffer, str.pData->length, maxLength );
}
+#endif
/**
Compares two strings in reverse order.
@@ -3101,6 +3117,20 @@ public:
*
* @since LibreOffice 4.4
*/
+#if defined LIBO_INTERNAL_ONLY
+ static OUString fromUtf8(std::string_view rSource)
+ {
+ OUString aTarget;
+ bool bSuccess = rtl_convertStringToUString(&aTarget.pData,
+ rSource.data(),
+ rSource.length(),
+ RTL_TEXTENCODING_UTF8,
+ RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_ERROR|RTL_TEXTTOUNICODE_FLAGS_MBUNDEFINED_ERROR|RTL_TEXTTOUNICODE_FLAGS_INVALID_ERROR);
+ (void) bSuccess;
+ assert(bSuccess);
+ return aTarget;
+ }
+#else
static OUString fromUtf8(const OString& rSource)
{
OUString aTarget;
@@ -3113,6 +3143,7 @@ public:
assert(bSuccess);
return aTarget;
}
+#endif
/**
* Convert this string to an OString, assuming that the string can be
@@ -3519,12 +3550,21 @@ struct OUStringHash
<http://udk.openoffice.org/cpp/man/spec/textconversion.html> for more
details.
*/
+#if defined LIBO_INTERNAL_ONLY
+inline OUString OStringToOUString( std::string_view rStr,
+ rtl_TextEncoding encoding,
+ sal_uInt32 convertFlags = OSTRING_TO_OUSTRING_CVTFLAGS )
+{
+ return OUString( rStr.data(), rStr.length(), encoding, convertFlags );
+}
+#else
inline OUString OStringToOUString( const OString & rStr,
rtl_TextEncoding encoding,
sal_uInt32 convertFlags = OSTRING_TO_OUSTRING_CVTFLAGS )
{
return OUString( rStr.getStr(), rStr.getLength(), encoding, convertFlags );
}
+#endif
/** Convert an OUString to an OString, using a specific text encoding.
@@ -3543,12 +3583,21 @@ inline OUString OStringToOUString( const OString & rStr,
<http://udk.openoffice.org/cpp/man/spec/textconversion.html> for more
details.
*/
+#if defined LIBO_INTERNAL_ONLY
+inline OString OUStringToOString( std::u16string_view rUnicode,
+ rtl_TextEncoding encoding,
+ sal_uInt32 convertFlags = OUSTRING_TO_OSTRING_CVTFLAGS )
+{
+ return OString( rUnicode.data(), rUnicode.length(), encoding, convertFlags );
+}
+#else
inline OString OUStringToOString( const OUString & rUnicode,
rtl_TextEncoding encoding,
sal_uInt32 convertFlags = OUSTRING_TO_OSTRING_CVTFLAGS )
{
return OString( rUnicode.getStr(), rUnicode.getLength(), encoding, convertFlags );
}
+#endif
/* ======================================================================= */