From 35e471bb4d1388cf5afcdcee214cf5111edf44e3 Mon Sep 17 00:00:00 2001 From: Stephan Bergmann Date: Fri, 11 Dec 2020 17:44:34 +0100 Subject: 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 --- i18npool/source/collator/collator_unicode.cxx | 2 +- i18npool/source/localedata/LocaleNode.cxx | 18 +++++++++--------- i18npool/source/localedata/LocaleNode.hxx | 20 +++++++++++--------- i18npool/source/localedata/filewriter.cxx | 8 ++++---- 4 files changed, 25 insertions(+), 23 deletions(-) (limited to 'i18npool/source') diff --git a/i18npool/source/collator/collator_unicode.cxx b/i18npool/source/collator/collator_unicode.cxx index c05a9cb025c6..dd273e687f21 100644 --- a/i18npool/source/collator/collator_unicode.cxx +++ b/i18npool/source/collator/collator_unicode.cxx @@ -403,7 +403,7 @@ Collator_Unicode::loadCollatorAlgorithm(const OUString& rAlgorithm, const lang:: uppercase itself, so we don't have to bother with that. */ icu::Locale icuLocale( LanguageTagIcu::getIcuLocale( LanguageTag( rLocale), - "", rAlgorithm.isEmpty() ? OUString("") : "collation=" + rAlgorithm)); + u"", rAlgorithm.isEmpty() ? OUString("") : "collation=" + rAlgorithm)); // FIXME: apparently we get here in LOKit case only. When the language is Japanese, we pass "ja@collation=phonetic (alphanumeric first)" to ICU // and ICU does not like this (U_ILLEGAL_ARGUMENT_ERROR). Subsequently LOKit crashes, because collator is nullptr. diff --git a/i18npool/source/localedata/LocaleNode.cxx b/i18npool/source/localedata/LocaleNode.cxx index 997355ffab4e..3040f3312d42 100644 --- a/i18npool/source/localedata/LocaleNode.cxx +++ b/i18npool/source/localedata/LocaleNode.cxx @@ -201,7 +201,7 @@ void LocaleNode::incError( const char* pStr ) const fprintf( stderr, "Error: %s\n", pStr); } -void LocaleNode::incError( const OUString& rStr ) const +void LocaleNode::incError( std::u16string_view rStr ) const { incError( OSTR( rStr)); } @@ -212,13 +212,13 @@ void LocaleNode::incErrorInt( const char* pStr, int nVal ) const fprintf( stderr, pStr, nVal); } -void LocaleNode::incErrorStr( const char* pStr, const OUString& rVal ) const +void LocaleNode::incErrorStr( const char* pStr, std::u16string_view rVal ) const { ++nError; fprintf( stderr, pStr, OSTR( rVal)); } -void LocaleNode::incErrorStrStr( const char* pStr, const OUString& rVal1, const OUString& rVal2 ) const +void LocaleNode::incErrorStrStr( const char* pStr, std::u16string_view rVal1, std::u16string_view rVal2 ) const { ++nError; fprintf(stderr, pStr, OSTR(rVal1), OSTR(rVal2)); @@ -1526,8 +1526,8 @@ static void lcl_writeAbbrFullNarrArrays( const OFileWriter & of, sal_Int16 nCoun } } -bool LCCalendarNode::expectedCalendarElement( const OUString& rName, - const LocaleNode* pNode, sal_Int16 nChild, const OUString& rCalendarID ) const +bool LCCalendarNode::expectedCalendarElement( std::u16string_view rName, + const LocaleNode* pNode, sal_Int16 nChild, std::u16string_view rCalendarID ) const { bool bFound = true; if (nChild >= 0) @@ -1734,7 +1734,7 @@ void LCCalendarNode::generateCode (const OFileWriter &of) const } else { if (erasNode == nullptr) erasNode = calNode -> getChildAt(nChild); - if (!expectedCalendarElement("Eras", erasNode, -1, calendarID)) + if (!expectedCalendarElement(u"Eras", erasNode, -1, calendarID)) { --nChild; } @@ -1746,7 +1746,7 @@ void LCCalendarNode::generateCode (const OFileWriter &of) const elementTag = "era"; for (j = 0; j < nbOfEras[i]; j++) { LocaleNode *currNode = erasNode -> getChildAt(j); - if (!expectedCalendarElement("Era", currNode, -1, calendarID)) + if (!expectedCalendarElement(u"Era", currNode, -1, calendarID)) { continue; // for } @@ -1764,7 +1764,7 @@ void LCCalendarNode::generateCode (const OFileWriter &of) const } ++nChild; - if (expectedCalendarElement("StartDayOfWeek", calNode, nChild, calendarID)) + if (expectedCalendarElement(u"StartDayOfWeek", calNode, nChild, calendarID)) { str = calNode->getChildAt(nChild)->getChildAt(0)->getValue(); if (nbOfDays[i]) @@ -1783,7 +1783,7 @@ void LCCalendarNode::generateCode (const OFileWriter &of) const ++nChild; } - if (expectedCalendarElement("MinimalDaysInFirstWeek", calNode, nChild, calendarID)) + if (expectedCalendarElement(u"MinimalDaysInFirstWeek", calNode, nChild, calendarID)) { str = calNode ->getChildAt(nChild)-> getValue(); sal_Int16 nDays = sal::static_int_cast( str.toInt32() ); diff --git a/i18npool/source/localedata/LocaleNode.hxx b/i18npool/source/localedata/LocaleNode.hxx index 0d46a9e80876..b187cc9adbd9 100644 --- a/i18npool/source/localedata/LocaleNode.hxx +++ b/i18npool/source/localedata/LocaleNode.hxx @@ -20,6 +20,7 @@ #define INCLUDED_I18NPOOL_SOURCE_LOCALEDATA_LOCALENODE_HXX #include +#include #include #include @@ -41,13 +42,13 @@ public: void writeAsciiString(const char *str)const ; void writeInt(sal_Int16 nb) const; void writeFunction(const char *func, const char *count, const char *array) const; - void writeRefFunction(const char *func, const OUString& useLocale) const; + void writeRefFunction(const char *func, std::u16string_view useLocale) const; void writeFunction(const char *func, const char *count, const char *array, const char *from, const char *to) const; - void writeRefFunction(const char *func, const OUString& useLocale, const char *to) const; + void writeRefFunction(const char *func, std::u16string_view useLocale, const char *to) const; void writeFunction2(const char *func, const char *style, const char* attr, const char *array) const; - void writeRefFunction2(const char *func, const OUString& useLocale) const; + void writeRefFunction2(const char *func, std::u16string_view useLocale) const; void writeFunction3(const char *func, const char *style, const char* levels, const char* attr, const char *array) const; - void writeRefFunction3(const char *func, const OUString& useLocale) const; + void writeRefFunction3(const char *func, std::u16string_view useLocale) const; void writeIntParameter(const char* pAsciiStr, const sal_Int16 count, sal_Int16 val) const; bool writeDefaultParameter(const char* pAsciiStr, std::u16string_view str, sal_Int16 count) const; void writeParameter(const char* pAsciiStr, const OUString& aChars) const; @@ -109,13 +110,14 @@ public: // ++nError with output to stderr void incError( const char* pStr ) const; // ++nError with output to stderr - void incError( const OUString& rStr ) const; + void incError( std::u16string_view rStr ) const; // ++nError with output to stderr, pStr should contain "%d" void incErrorInt( const char* pStr, int nVal ) const; // ++nError with output to stderr, pStr should contain "%s" - void incErrorStr( const char* pStr, const OUString& rVal ) const; + void incErrorStr( const char* pStr, std::u16string_view rVal ) const; // ++nError with output to stderr, pStr should contain "%s %s" - void incErrorStrStr( const char* pStr, const OUString& rVal1, const OUString& rVal2 ) const; + void incErrorStrStr( const char* pStr, std::u16string_view rVal1, std::u16string_view rVal2 ) + const; static LocaleNode* createNode (const OUString& name,const Reference< XAttributeList > & attr); }; @@ -176,8 +178,8 @@ public: virtual void generateCode (const OFileWriter &of) const override; - bool expectedCalendarElement( const OUString& rName, - const LocaleNode* pNode, sal_Int16 nChild, const OUString& rCalendarID ) const; + bool expectedCalendarElement( std::u16string_view rName, + const LocaleNode* pNode, sal_Int16 nChild, std::u16string_view rCalendarID ) const; }; class LCCurrencyNode : public LocaleNode { diff --git a/i18npool/source/localedata/filewriter.cxx b/i18npool/source/localedata/filewriter.cxx index f8643025d91d..4c095b14bc84 100644 --- a/i18npool/source/localedata/filewriter.cxx +++ b/i18npool/source/localedata/filewriter.cxx @@ -57,7 +57,7 @@ void OFileWriter::writeFunction(const char *func, const char *count, const char fprintf(m_f, "\treturn (sal_Unicode**)%s;\n}\n", array); } -void OFileWriter::writeRefFunction(const char *func, const OUString& useLocale) const +void OFileWriter::writeRefFunction(const char *func, std::u16string_view useLocale) const { OString aRefLocale( OUStringToOString(useLocale, RTL_TEXTENCODING_ASCII_US) ); const char* locale = aRefLocale.getStr(); @@ -75,7 +75,7 @@ void OFileWriter::writeFunction(const char *func, const char *count, const char fprintf(m_f, "\treturn (sal_Unicode**)%s;\n}\n", array); } -void OFileWriter::writeRefFunction(const char *func, const OUString& useLocale, const char *to) const +void OFileWriter::writeRefFunction(const char *func, std::u16string_view useLocale, const char *to) const { OString aRefLocale( OUStringToOString(useLocale, RTL_TEXTENCODING_ASCII_US) ); const char* locale = aRefLocale.getStr(); @@ -94,7 +94,7 @@ void OFileWriter::writeFunction2(const char *func, const char *style, const char fprintf(m_f, "\treturn %s;\n}\n", array); } -void OFileWriter::writeRefFunction2(const char *func, const OUString& useLocale) const +void OFileWriter::writeRefFunction2(const char *func, std::u16string_view useLocale) const { OString aRefLocale( OUStringToOString(useLocale, RTL_TEXTENCODING_ASCII_US) ); const char* locale = aRefLocale.getStr(); @@ -112,7 +112,7 @@ void OFileWriter::writeFunction3(const char *func, const char *style, const char fprintf(m_f, "\treturn %s;\n}\n", array); } -void OFileWriter::writeRefFunction3(const char *func, const OUString& useLocale) const +void OFileWriter::writeRefFunction3(const char *func, std::u16string_view useLocale) const { OString aRefLocale( OUStringToOString(useLocale, RTL_TEXTENCODING_ASCII_US) ); const char* locale = aRefLocale.getStr(); -- cgit