diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2021-01-27 16:45:22 +0100 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2021-01-27 23:24:42 +0100 |
commit | aa2064c5c5f23f6f4b7bc44e12345b37f66995bc (patch) | |
tree | a5073b6d0b0c5846575671975341f0e0b393d98d | |
parent | Update git submodules (diff) | |
download | core-aa2064c5c5f23f6f4b7bc44e12345b37f66995bc.tar.gz core-aa2064c5c5f23f6f4b7bc44e12345b37f66995bc.zip |
Improve loplugin:stringliteralvar
...to also consider O[U]String ctors taking pointer and length
Change-Id: Iea5041634bfbf5054a1317701e30b56f72e940fb
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/110025
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
-rw-r--r-- | compilerplugins/clang/stringliteralvar.cxx | 14 | ||||
-rw-r--r-- | compilerplugins/clang/test/stringliteralvar.cxx | 9 | ||||
-rw-r--r-- | editeng/qa/unit/core-test.cxx | 5 | ||||
-rw-r--r-- | i18npool/qa/cppunit/test_breakiterator.cxx | 219 | ||||
-rw-r--r-- | i18npool/qa/cppunit/test_characterclassification.cxx | 6 | ||||
-rw-r--r-- | sal/qa/rtl/oustring/rtl_OUString2.cxx | 13 | ||||
-rw-r--r-- | sax/source/tools/fastserializer.cxx | 6 | ||||
-rw-r--r-- | svl/qa/unit/svl.cxx | 8 | ||||
-rw-r--r-- | svtools/source/misc/sampletext.cxx | 347 | ||||
-rw-r--r-- | sw/qa/core/uwriter.cxx | 92 | ||||
-rw-r--r-- | sw/qa/extras/ooxmlexport/ooxmlexport10.cxx | 4 | ||||
-rw-r--r-- | sw/qa/extras/ooxmlimport/ooxmlimport2.cxx | 7 | ||||
-rw-r--r-- | sw/qa/extras/rtfimport/rtfimport.cxx | 18 | ||||
-rw-r--r-- | sw/source/filter/ww8/ww8par3.cxx | 8 | ||||
-rw-r--r-- | vcl/qa/cppunit/complextext.cxx | 14 | ||||
-rw-r--r-- | vcl/qa/cppunit/mnemonic.cxx | 8 |
16 files changed, 342 insertions, 436 deletions
diff --git a/compilerplugins/clang/stringliteralvar.cxx b/compilerplugins/clang/stringliteralvar.cxx index 348193421a61..ed1aa9e717d6 100644 --- a/compilerplugins/clang/stringliteralvar.cxx +++ b/compilerplugins/clang/stringliteralvar.cxx @@ -120,12 +120,14 @@ public: return true; } auto const e2 = expr->getArg(1); - if (!(isa<CXXDefaultArgExpr>(e2) - && loplugin::TypeCheck(e2->getType()) - .Struct("Dummy") - .Namespace("libreoffice_internal") - .Namespace("rtl") - .GlobalNamespace())) + if (!((isa<CXXDefaultArgExpr>(e2) + && loplugin::TypeCheck(e2->getType()) + .Struct("Dummy") + .Namespace("libreoffice_internal") + .Namespace("rtl") + .GlobalNamespace()) + || (loplugin::TypeCheck(e2->getType()).Typedef("sal_Int32").GlobalNamespace() + && e2->isIntegerConstantExpr(compiler.getASTContext())))) { return true; } diff --git a/compilerplugins/clang/test/stringliteralvar.cxx b/compilerplugins/clang/test/stringliteralvar.cxx index 25a85f90a5a3..de67de5c7679 100644 --- a/compilerplugins/clang/test/stringliteralvar.cxx +++ b/compilerplugins/clang/test/stringliteralvar.cxx @@ -12,6 +12,7 @@ #include <vector> #include <rtl/ustring.hxx> +#include <sal/macros.h> // expected-error@+1 {{change type of variable 'literal1' from constant character array ('const char [4]') to OStringLiteral [loplugin:stringliteralvar]}} char const literal1[] = "foo"; @@ -78,4 +79,12 @@ void f8() (void)sizeof literal; } +void f9() +{ + // expected-error@+1 {{change type of variable 'literal' from constant character array ('const sal_Unicode [3]') to OUStringLiteral [loplugin:stringliteralvar]}} + static sal_Unicode const literal[] = { 'f', 'o', 'o' }; + // expected-note@+1 {{first passed into a 'rtl::OUString' constructor here [loplugin:stringliteralvar]}} + f(OUString(literal, SAL_N_ELEMENTS(literal))); +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/editeng/qa/unit/core-test.cxx b/editeng/qa/unit/core-test.cxx index 35094ca07af2..32136c944091 100644 --- a/editeng/qa/unit/core-test.cxx +++ b/editeng/qa/unit/core-test.cxx @@ -501,8 +501,7 @@ void Test::testAutocorrect() { OUString sInput("T\x01"); sal_Unicode const cNextChar('"'); - const sal_Unicode EXPECTED[] = { 'T', 0x01, 0x0201d }; - OUString sExpected(EXPECTED, SAL_N_ELEMENTS(EXPECTED)); + static constexpr OUStringLiteral sExpected = u"T\x01\u201d"; bool bNbspRunNext = false; TestAutoCorrDoc aFoo(sInput, LANGUAGE_ENGLISH_US); @@ -510,7 +509,7 @@ void Test::testAutocorrect() aAutoCorrect.DoAutoCorrect(aFoo, sInput, sInput.getLength(), cNextChar, true, bNbspRunNext); fprintf(stderr, "text is %x\n", aFoo.getResult()[aFoo.getResult().getLength() - 1]); - CPPUNIT_ASSERT_EQUAL_MESSAGE("autocorrect", sExpected, aFoo.getResult()); + CPPUNIT_ASSERT_EQUAL_MESSAGE("autocorrect", OUString(sExpected), aFoo.getResult()); } } diff --git a/i18npool/qa/cppunit/test_breakiterator.cxx b/i18npool/qa/cppunit/test_breakiterator.cxx index 384041ccd5db..2e7dde17e937 100644 --- a/i18npool/qa/cppunit/test_breakiterator.cxx +++ b/i18npool/qa/cppunit/test_breakiterator.cxx @@ -95,8 +95,7 @@ void TestBreakIterator::testLineBreaking() //See https://bugs.libreoffice.org/show_bug.cgi?id=49849 { - const sal_Unicode HEBREW1[] = { 0x05DE, 0x05D9, 0x05DC, 0x05D9, 0x5DD }; - OUString aWord(HEBREW1, SAL_N_ELEMENTS(HEBREW1)); + constexpr OUStringLiteral aWord = u"\u05DE\u05D9\u05DC\u05D9\u05DD"; OUString aTest(aWord + " " + aWord); aLocale.Language = "he"; @@ -138,10 +137,8 @@ void TestBreakIterator::testLineBreaking() //this is an example sequence from tdf92993-1.docx caught by the load crashtesting { - const sal_Unicode WEIRD1[] = { 0xd83c, 0xdf56, 0xd83c, 0xdf57, 0xd83c, 0xdf46, - 0xd83c, 0xdf64, 0x2668, 0xfe0f, 0xd83c, 0xdfc6}; - - OUString aTest(WEIRD1, SAL_N_ELEMENTS(WEIRD1)); + static constexpr OUStringLiteral aTest = u"\U0001f356\U0001f357\U0001f346" + "\U0001f364\u2668\ufe0f\U0001f3c6"; aLocale.Language = "en"; aLocale.Country = "US"; @@ -154,9 +151,8 @@ void TestBreakIterator::testLineBreaking() //See https://bugs.documentfoundation.org/show_bug.cgi?id=96197 { - const sal_Unicode HANGUL[] = { 0xc560, 0xad6D, 0xac00, 0xc758, 0x0020, 0xac00, - 0xc0ac, 0xb294}; - OUString aTest(HANGUL, SAL_N_ELEMENTS(HANGUL)); + static constexpr OUStringLiteral aTest = u"\uc560\uad6D\uac00\uc758 \uac00" + "\uc0ac\ub294"; aLocale.Language = "ko"; aLocale.Country = "KR"; @@ -228,18 +224,15 @@ void TestBreakIterator::testWordBoundaries() //See https://bz.apache.org/ooo/show_bug.cgi?id=14904 { - const sal_Unicode TEST[] = - { - 'W', 'o', 'r', 'k', 'i', 'n', 'g', ' ', 0x201C, 'W', 'o', 'r', 'd', 's', - ' ', 's', 't', 'a', 'r', 't', 'i', 'n', 'g', ' ', 'w', 'i', 't', - 'h', ' ', 'q', 'u', 'o', 't', 'e', 's', 0x201D, ' ', 'W', 'o', 'r', 'k', - 'i', 'n', 'g', ' ', 0x2018, 'B', 'r', 'o', 'k', 'e', 'n', 0x2019, ' ', - '?', 'S', 'p', 'a', 'n', 'i', 's', 'h', '?', ' ', 'd', 'o', 'e', - 's', 'n', 0x2019, 't', ' ', 'w', 'o', 'r', 'k', '.', ' ', 'N', 'o', - 't', ' ', 'e', 'v', 'e', 'n', ' ' , 0x00BF, 'r', 'e', 'a', 'l', '?', ' ', - 'S', 'p', 'a', 'n', 'i', 's', 'h' - }; - OUString aTest(TEST, SAL_N_ELEMENTS(TEST)); + static constexpr OUStringLiteral aTest = + u"Working \u201CWords" + " starting wit" + "h quotes\u201D Work" + "ing \u2018Broken\u2019 " + "?Spanish? doe" + "sn\u2019t work. No" + "t even \u00BFreal? " + "Spanish"; aBounds = m_xBreak->getWordBoundary(aTest, 4, aLocale, i18n::WordType::DICTIONARY_WORD, false); CPPUNIT_ASSERT(aBounds.startPos == 0 && aBounds.endPos == 7); @@ -458,11 +451,8 @@ void TestBreakIterator::testWordBoundaries() break; } - const sal_Unicode TEST[] = - { - 'I', 0x200B, 'w', 'a', 'n', 't', 0x200B, 't', 'o', 0x200B, 'g', 'o' - }; - OUString aTest(TEST, SAL_N_ELEMENTS(TEST)); + static constexpr OUStringLiteral aTest = + u"I\u200Bwant\u200Bto\u200Bgo"; sal_Int32 nPos = 0; sal_Int32 aExpected[] = {1, 6, 9, 12}; @@ -497,14 +487,11 @@ void TestBreakIterator::testWordBoundaries() break; } - const sal_Unicode TEST[] = - { - 0x1F0C, 0x03BD, 0x03B4, 0x03C1, 0x03B1, 0x0020, 0x1F00, - 0x03C1, 0x03BD, 0x1F7B, 0x03BC, 0x03B5, 0x03BD, 0x03BF, - 0x03C2, 0x0020, 0x1F00, 0x03BB, 0x03BB, 0x0020, 0x1F24, - 0x03C3, 0x03B8, 0x03B9, 0x03BF, 0x03BD - }; - OUString aTest(TEST, SAL_N_ELEMENTS(TEST)); + static constexpr OUStringLiteral aTest = + u"\u1F0C\u03BD\u03B4\u03C1\u03B1 \u1F00" + "\u03C1\u03BD\u1F7B\u03BC\u03B5\u03BD\u03BF" + "\u03C2 \u1F00\u03BB\u03BB \u1F24" + "\u03C3\u03B8\u03B9\u03BF\u03BD"; sal_Int32 nPos = 0; sal_Int32 aExpected[] = {5, 15, 19, 26}; @@ -571,11 +558,8 @@ void TestBreakIterator::testWordBoundaries() aLocale.Language = "en"; aLocale.Country = "US"; - const sal_Unicode TEST[] = - { - 'r', 'u', 0xFB00, 'l', 'e', ' ', 0xFB01, 's', 'h' - }; - OUString aTest(TEST, SAL_N_ELEMENTS(TEST)); + static constexpr OUStringLiteral aTest = + u"ru\uFB00le \uFB01sh"; aBounds = m_xBreak->getWordBoundary(aTest, 1, aLocale, i18n::WordType::DICTIONARY_WORD, false); CPPUNIT_ASSERT(aBounds.startPos == 0 && aBounds.endPos == 5); @@ -589,11 +573,8 @@ void TestBreakIterator::testWordBoundaries() aLocale.Language = "en"; aLocale.Country = "US"; - const sal_Unicode TEST[] = - { - 'a', 0x2013, 'b', 0x2014, 'c' - }; - OUString aTest(TEST, SAL_N_ELEMENTS(TEST)); + static constexpr OUStringLiteral aTest = + u"a\u2013b\u2014c"; aBounds = m_xBreak->getWordBoundary(aTest, 0, aLocale, i18n::WordType::DICTIONARY_WORD, true); CPPUNIT_ASSERT(aBounds.startPos == 0 && aBounds.endPos == 1); @@ -617,43 +598,42 @@ void TestBreakIterator::testGraphemeIteration() aLocale.Country = "IN"; { - const sal_Unicode BA_HALANT_LA[] = { 0x09AC, 0x09CD, 0x09AF }; - OUString aTest(BA_HALANT_LA, SAL_N_ELEMENTS(BA_HALANT_LA)); + static constexpr OUStringLiteral aTest = u"\u09AC\u09CD\u09AF"; // BA HALANT LA sal_Int32 nDone=0; sal_Int32 nPos; nPos = m_xBreak->nextCharacters(aTest, 0, aLocale, i18n::CharacterIteratorMode::SKIPCELL, 1, nDone); - CPPUNIT_ASSERT_EQUAL_MESSAGE("Should skip full grapheme", static_cast<sal_Int32>(SAL_N_ELEMENTS(BA_HALANT_LA)), nPos); - nPos = m_xBreak->previousCharacters(aTest, SAL_N_ELEMENTS(BA_HALANT_LA), aLocale, + CPPUNIT_ASSERT_EQUAL_MESSAGE("Should skip full grapheme", aTest.getLength(), nPos); + nPos = m_xBreak->previousCharacters(aTest, aTest.getLength(), aLocale, i18n::CharacterIteratorMode::SKIPCELL, 1, nDone); CPPUNIT_ASSERT_EQUAL_MESSAGE("Should skip full grapheme", static_cast<sal_Int32>(0), nPos); } { - const sal_Unicode HA_HALANT_NA_VOWELSIGNI[] = { 0x09B9, 0x09CD, 0x09A3, 0x09BF }; - OUString aTest(HA_HALANT_NA_VOWELSIGNI, SAL_N_ELEMENTS(HA_HALANT_NA_VOWELSIGNI)); + static constexpr OUStringLiteral aTest = u"\u09B9\u09CD\u09A3\u09BF"; + // HA HALANT NA VOWELSIGNI sal_Int32 nDone=0; sal_Int32 nPos; nPos = m_xBreak->nextCharacters(aTest, 0, aLocale, i18n::CharacterIteratorMode::SKIPCELL, 1, nDone); - CPPUNIT_ASSERT_EQUAL_MESSAGE("Should skip full grapheme", static_cast<sal_Int32>(SAL_N_ELEMENTS(HA_HALANT_NA_VOWELSIGNI)), nPos); - nPos = m_xBreak->previousCharacters(aTest, SAL_N_ELEMENTS(HA_HALANT_NA_VOWELSIGNI), aLocale, + CPPUNIT_ASSERT_EQUAL_MESSAGE("Should skip full grapheme", aTest.getLength(), nPos); + nPos = m_xBreak->previousCharacters(aTest, aTest.getLength(), aLocale, i18n::CharacterIteratorMode::SKIPCELL, 1, nDone); CPPUNIT_ASSERT_EQUAL_MESSAGE("Should skip full grapheme", static_cast<sal_Int32>(0), nPos); } { - const sal_Unicode TA_HALANT_MA_HALANT_YA [] = { 0x09A4, 0x09CD, 0x09AE, 0x09CD, 0x09AF }; - OUString aTest(TA_HALANT_MA_HALANT_YA, SAL_N_ELEMENTS(TA_HALANT_MA_HALANT_YA)); + static constexpr OUStringLiteral aTest = u"\u09A4\u09CD\u09AE\u09CD\u09AF"; + // TA HALANT MA HALANT YA sal_Int32 nDone=0; sal_Int32 nPos; nPos = m_xBreak->nextCharacters(aTest, 0, aLocale, i18n::CharacterIteratorMode::SKIPCELL, 1, nDone); - CPPUNIT_ASSERT_EQUAL_MESSAGE("Should skip full grapheme", static_cast<sal_Int32>(SAL_N_ELEMENTS(TA_HALANT_MA_HALANT_YA)), nPos); - nPos = m_xBreak->previousCharacters(aTest, SAL_N_ELEMENTS(TA_HALANT_MA_HALANT_YA), aLocale, + CPPUNIT_ASSERT_EQUAL_MESSAGE("Should skip full grapheme", aTest.getLength(), nPos); + nPos = m_xBreak->previousCharacters(aTest, aTest.getLength(), aLocale, i18n::CharacterIteratorMode::SKIPCELL, 1, nDone); CPPUNIT_ASSERT_EQUAL_MESSAGE("Should skip full grapheme", static_cast<sal_Int32>(0), nPos); } @@ -662,9 +642,7 @@ void TestBreakIterator::testGraphemeIteration() aLocale.Country = "IN"; { - const sal_Unicode CA_VOWELSIGNI_TA_VIRAMA_TA_VOWELSIGNI_RA_VOWELSIGNAI [] = { 0x0B9A, 0x0BBF, 0x0BA4, 0x0BCD, 0x0BA4, 0x0BBF, 0x0BB0, 0x0BC8 }; - - OUString aTest(CA_VOWELSIGNI_TA_VIRAMA_TA_VOWELSIGNI_RA_VOWELSIGNAI, SAL_N_ELEMENTS(CA_VOWELSIGNI_TA_VIRAMA_TA_VOWELSIGNI_RA_VOWELSIGNAI)); + static constexpr OUStringLiteral aTest = u"\u0B9A\u0BBF\u0BA4\u0BCD\u0BA4\u0BBF\u0BB0\u0BC8"; // CA VOWELSIGNI TA VIRAMA TA VOWELSIGNI RA VOWELSIGNAI sal_Int32 nDone=0; sal_Int32 nPos = 0; @@ -676,8 +654,8 @@ void TestBreakIterator::testGraphemeIteration() nPos = m_xBreak->nextCharacters(aTest, nPos, aLocale, i18n::CharacterIteratorMode::SKIPCELL, 1, nDone); CPPUNIT_ASSERT_EQUAL_MESSAGE("Should skip full grapheme", static_cast<sal_Int32>(6), nPos); nPos = m_xBreak->nextCharacters(aTest, nPos, aLocale, i18n::CharacterIteratorMode::SKIPCELL, 1, nDone); - CPPUNIT_ASSERT_EQUAL_MESSAGE("Should skip full grapheme", static_cast<sal_Int32>(SAL_N_ELEMENTS(CA_VOWELSIGNI_TA_VIRAMA_TA_VOWELSIGNI_RA_VOWELSIGNAI)), nPos); - nPos = m_xBreak->previousCharacters(aTest, SAL_N_ELEMENTS(CA_VOWELSIGNI_TA_VIRAMA_TA_VOWELSIGNI_RA_VOWELSIGNAI), aLocale, + CPPUNIT_ASSERT_EQUAL_MESSAGE("Should skip full grapheme", aTest.getLength(), nPos); + nPos = m_xBreak->previousCharacters(aTest, aTest.getLength(), aLocale, i18n::CharacterIteratorMode::SKIPCELL, 1, nDone); CPPUNIT_ASSERT_EQUAL_MESSAGE("Should skip full grapheme", static_cast<sal_Int32>(6), nPos); nPos = m_xBreak->previousCharacters(aTest, nPos, aLocale, i18n::CharacterIteratorMode::SKIPCELL, 1, nDone); @@ -689,25 +667,23 @@ void TestBreakIterator::testGraphemeIteration() } { - const sal_Unicode KA_VOWELSIGNU[] = { 0x0B95, 0x0BC1 }; - OUString aTest(KA_VOWELSIGNU, SAL_N_ELEMENTS(KA_VOWELSIGNU)); + static constexpr OUStringLiteral aTest = u"\u0B95\u0BC1"; // KA VOWELSIGNU sal_Int32 nDone=0; sal_Int32 nPos = 0; nPos = m_xBreak->nextCharacters(aTest, 0, aLocale, i18n::CharacterIteratorMode::SKIPCELL, 1, nDone); - CPPUNIT_ASSERT_EQUAL_MESSAGE("Should skip full grapheme", static_cast<sal_Int32>(SAL_N_ELEMENTS(KA_VOWELSIGNU)), nPos); - nPos = m_xBreak->previousCharacters(aTest, SAL_N_ELEMENTS(KA_VOWELSIGNU), aLocale, + CPPUNIT_ASSERT_EQUAL_MESSAGE("Should skip full grapheme", aTest.getLength(), nPos); + nPos = m_xBreak->previousCharacters(aTest, aTest.getLength(), aLocale, i18n::CharacterIteratorMode::SKIPCELL, 1, nDone); CPPUNIT_ASSERT_EQUAL_MESSAGE("Should skip full grapheme", static_cast<sal_Int32>(0), nPos); } { - const sal_Unicode CA_VOWELSIGNI_TA_VIRAMA_TA_VOWELSIGNI_RA_VOWELSIGNAI[] = - { 0x0B9A, 0x0BBF, 0x0BA4, 0x0BCD, 0x0BA4, 0x0BBF, 0x0BB0, 0x0BC8 }; - OUString aTest(CA_VOWELSIGNI_TA_VIRAMA_TA_VOWELSIGNI_RA_VOWELSIGNAI, - SAL_N_ELEMENTS(CA_VOWELSIGNI_TA_VIRAMA_TA_VOWELSIGNI_RA_VOWELSIGNAI)); + static constexpr OUStringLiteral aTest = + u"\u0B9A\u0BBF\u0BA4\u0BCD\u0BA4\u0BBF\u0BB0\u0BC8"; + // CA VOWELSIGNI TA VIRAMA TA VOWELSIGNI RA VOWELSIGNAI sal_Int32 nDone=0; sal_Int32 nPos=0; @@ -730,8 +706,7 @@ void TestBreakIterator::testGraphemeIteration() } { - const sal_Unicode ALEF_QAMATS [] = { 0x05D0, 0x05B8 }; - OUString aText(ALEF_QAMATS, SAL_N_ELEMENTS(ALEF_QAMATS)); + static constexpr OUStringLiteral aText = u"\u05D0\u05B8"; // ALEF QAMATS sal_Int32 nGraphemeCount = 0; @@ -751,16 +726,15 @@ void TestBreakIterator::testGraphemeIteration() aLocale.Country = "IN"; { - const sal_Unicode SHA_VOWELSIGNII[] = { 0x936, 0x940 }; - OUString aTest(SHA_VOWELSIGNII, SAL_N_ELEMENTS(SHA_VOWELSIGNII)); + static constexpr OUStringLiteral aTest = u"\u0936\u0940"; // SHA VOWELSIGNII sal_Int32 nDone=0; sal_Int32 nPos = 0; nPos = m_xBreak->nextCharacters(aTest, 0, aLocale, i18n::CharacterIteratorMode::SKIPCELL, 1, nDone); - CPPUNIT_ASSERT_EQUAL_MESSAGE("Should skip full grapheme", static_cast<sal_Int32>(SAL_N_ELEMENTS(SHA_VOWELSIGNII)), nPos); - nPos = m_xBreak->previousCharacters(aTest, SAL_N_ELEMENTS(SHA_VOWELSIGNII), aLocale, + CPPUNIT_ASSERT_EQUAL_MESSAGE("Should skip full grapheme", aTest.getLength(), nPos); + nPos = m_xBreak->previousCharacters(aTest, aTest.getLength(), aLocale, i18n::CharacterIteratorMode::SKIPCELL, 1, nDone); CPPUNIT_ASSERT_EQUAL_MESSAGE("Should skip full grapheme", static_cast<sal_Int32>(0), nPos); } @@ -776,33 +750,30 @@ void TestBreakIterator::testWeak() aLocale.Country = "US"; { - const sal_Unicode WEAKS[] = - { - 0x0001, 0x0002, - 0x0020, 0x00A0, - 0x0300, 0x036F, //Combining Diacritical Marks - 0x1AB0, 0x1AFF, //Combining Diacritical Marks Extended - 0x1DC0, 0x1DFF, //Combining Diacritical Marks Supplement - 0x20D0, 0x20FF, //Combining Diacritical Marks for Symbols - 0x2150, 0x215F, //Number Forms, fractions - 0x2160, 0x2180, //Number Forms, roman numerals - 0x2200, 0x22FF, //Mathematical Operators - 0x27C0, 0x27EF, //Miscellaneous Mathematical Symbols-A - 0x2980, 0x29FF, //Miscellaneous Mathematical Symbols-B - 0x2A00, 0x2AFF, //Supplemental Mathematical Operators - 0x2100, 0x214F, //Letterlike Symbols - 0x2308, 0x230B, //Miscellaneous technical - 0x25A0, 0x25FF, //Geometric Shapes - 0x2B30, 0x2B4C //Miscellaneous Symbols and Arrows - }; - OUString aWeaks(WEAKS, SAL_N_ELEMENTS(WEAKS)); + static constexpr OUStringLiteral aWeaks = + u"\u0001\u0002" + " \u00A0" + "\u0300\u036F" //Combining Diacritical Marks + "\u1AB0\u1AFF" //Combining Diacritical Marks Extended + "\u1DC0\u1DFF" //Combining Diacritical Marks Supplement + "\u20D0\u20FF" //Combining Diacritical Marks for Symbols + "\u2150\u215F" //Number Forms, fractions + "\u2160\u2180" //Number Forms, roman numerals + "\u2200\u22FF" //Mathematical Operators + "\u27C0\u27EF" //Miscellaneous Mathematical Symbols-A + "\u2980\u29FF" //Miscellaneous Mathematical Symbols-B + "\u2A00\u2AFF" //Supplemental Mathematical Operators + "\u2100\u214F" //Letterlike Symbols + "\u2308\u230B" //Miscellaneous technical + "\u25A0\u25FF" //Geometric Shapes + "\u2B30\u2B4C"; //Miscellaneous Symbols and Arrows for (sal_Int32 i = 0; i < aWeaks.getLength(); ++i) { sal_Int16 nScript = m_xBreak->getScriptType(aWeaks, i); OString aMsg = "Char 0x" + - OString::number(static_cast<sal_Int32>(aWeaks[i]), 16) + + OString::number(static_cast<sal_Int32>(OUString(aWeaks)[i]), 16) + " should have been weak"; CPPUNIT_ASSERT_EQUAL_MESSAGE(aMsg.getStr(), i18n::ScriptType::WEAK, nScript); @@ -821,27 +792,24 @@ void TestBreakIterator::testAsian() aLocale.Country = "US"; { - const sal_Unicode ASIANS[] = - { + static constexpr OUStringLiteral aAsians = //some typical CJK chars - 0x4E00, 0x62FF, + u"\u4E00\u62FF" //The full HalfWidth and FullWidth block has historically been //designated as taking the CJK font :-( //HalfWidth and FullWidth forms of ASCII 0-9, categorized under //UAX24 as "Common" i.e. by that logic WEAK - 0xFF10, 0xFF19, + "\uFF10\uFF19" //HalfWidth and FullWidth forms of ASCII A-z, categorized under //UAX25 as "Latin", i.e. by that logic LATIN - 0xFF21, 0xFF5A - }; - OUString aAsians(ASIANS, SAL_N_ELEMENTS(ASIANS)); + "\uFF21\uFF5A"; for (sal_Int32 i = 0; i < aAsians.getLength(); ++i) { sal_Int16 nScript = m_xBreak->getScriptType(aAsians, i); OString aMsg = "Char 0x" + - OString::number(static_cast<sal_Int32>(aAsians[i]), 16) + + OString::number(static_cast<sal_Int32>(OUString(aAsians)[i]), 16) + " should have been asian"; CPPUNIT_ASSERT_EQUAL_MESSAGE(aMsg.getStr(), i18n::ScriptType::ASIAN, nScript); @@ -857,8 +825,7 @@ void TestBreakIterator::testLao() aLocale.Language = "lo"; aLocale.Country = "LA"; - const sal_Unicode LAO[] = { 0x0e8d, 0x0eb4, 0x0e99, 0x0e94, 0x0eb5, 0x0e95, 0x0ec9, 0x0ead, 0x0e99, 0x0eae, 0x0eb1, 0x0e9a }; - OUString aTest(LAO, SAL_N_ELEMENTS(LAO)); + static constexpr OUStringLiteral aTest = u"\u0e8d\u0eb4\u0e99\u0e94\u0eb5\u0e95\u0ec9\u0ead\u0e99\u0eae\u0eb1\u0e9a"; i18n::Boundary aBounds = m_xBreak->getWordBoundary(aTest, 0, aLocale, i18n::WordType::DICTIONARY_WORD, true); @@ -882,8 +849,7 @@ void TestBreakIterator::testThai() //See http://lists.freedesktop.org/archives/libreoffice/2012-February/025959.html { - const sal_Unicode THAI[] = { 0x0E01, 0x0E38, 0x0E2B, 0x0E25, 0x0E32, 0x0E1A }; - OUString aTest(THAI, SAL_N_ELEMENTS(THAI)); + static constexpr OUStringLiteral aTest = u"\u0E01\u0E38\u0E2B\u0E25\u0E32\u0E1A"; i18n::Boundary aBounds = m_xBreak->getWordBoundary(aTest, 0, aLocale, i18n::WordType::DICTIONARY_WORD, true); CPPUNIT_ASSERT_MESSAGE("Should skip full word", @@ -893,16 +859,13 @@ void TestBreakIterator::testThai() //See https://bz.apache.org/ooo/show_bug.cgi?id=29548 //make sure forwards and back are consistent { - const sal_Unicode THAI[] = - { - 0x0E2D, 0x0E38, 0x0E17, 0x0E22, 0x0E32, 0x0E19, 0x0E41, - 0x0E2B, 0x0E48, 0x0E07, 0x0E0A, 0x0E32, 0x0E15, 0x0E34, - 0x0E19, 0x0E49, 0x0E33, 0x0E2B, 0x0E19, 0x0E32, 0x0E27, - 0x0E2D, 0x0E38, 0x0E17, 0x0E22, 0x0E32, 0x0E19, 0x0E41, - 0x0E2B, 0x0E48, 0x0E07, 0x0E0A, 0x0E32, 0x0E15, 0x0E34, - 0x0E19, 0x0E49, 0x0E33, 0x0E2B, 0x0E19, 0x0E32, 0x0E27 - }; - OUString aTest(THAI, SAL_N_ELEMENTS(THAI)); + static constexpr OUStringLiteral aTest = + u"\u0E2D\u0E38\u0E17\u0E22\u0E32\u0E19\u0E41" + "\u0E2B\u0E48\u0E07\u0E0A\u0E32\u0E15\u0E34" + "\u0E19\u0E49\u0E33\u0E2B\u0E19\u0E32\u0E27" + "\u0E2D\u0E38\u0E17\u0E22\u0E32\u0E19\u0E41" + "\u0E2B\u0E48\u0E07\u0E0A\u0E32\u0E15\u0E34" + "\u0E19\u0E49\u0E33\u0E2B\u0E19\u0E32\u0E27"; std::stack<sal_Int32> aPositions; sal_Int32 nPos = -1; @@ -927,23 +890,22 @@ void TestBreakIterator::testThai() // tdf#113694 { - const sal_Unicode NON_BMP[] = { 0xD800, 0xDC00 }; - OUString aTest(NON_BMP, SAL_N_ELEMENTS(NON_BMP)); + static constexpr OUStringLiteral aTest = u"\U00010000"; sal_Int32 nDone=0; sal_Int32 nPos; nPos = m_xBreak->nextCharacters(aTest, 0, aLocale, i18n::CharacterIteratorMode::SKIPCELL, 1, nDone); - CPPUNIT_ASSERT_EQUAL_MESSAGE("Should skip full surrogate pair", static_cast<sal_Int32>(SAL_N_ELEMENTS(NON_BMP)), nPos); - nPos = m_xBreak->previousCharacters(aTest, SAL_N_ELEMENTS(NON_BMP), aLocale, + CPPUNIT_ASSERT_EQUAL_MESSAGE("Should skip full surrogate pair", aTest.getLength(), nPos); + nPos = m_xBreak->previousCharacters(aTest, aTest.getLength(), aLocale, i18n::CharacterIteratorMode::SKIPCELL, 1, nDone); CPPUNIT_ASSERT_EQUAL_MESSAGE("Should skip full surrogate pair", static_cast<sal_Int32>(0), nPos); nPos = m_xBreak->nextCharacters(aTest, 0, aLocale, i18n::CharacterIteratorMode::SKIPCHARACTER, 1, nDone); - CPPUNIT_ASSERT_EQUAL_MESSAGE("Should skip full surrogate pair", static_cast<sal_Int32>(SAL_N_ELEMENTS(NON_BMP)), nPos); - nPos = m_xBreak->previousCharacters(aTest, SAL_N_ELEMENTS(NON_BMP), aLocale, + CPPUNIT_ASSERT_EQUAL_MESSAGE("Should skip full surrogate pair", aTest.getLength(), nPos); + nPos = m_xBreak->previousCharacters(aTest, aTest.getLength(), aLocale, i18n::CharacterIteratorMode::SKIPCHARACTER, 1, nDone); CPPUNIT_ASSERT_EQUAL_MESSAGE("Should skip full surrogate pair", static_cast<sal_Int32>(0), nPos); } @@ -1001,9 +963,8 @@ void TestBreakIterator::doTestJapanese(uno::Reference< i18n::XBreakIterator > co i18n::Boundary aBounds; { - const sal_Unicode JAPANESE[] = { 0x30B7, 0x30E3, 0x30C3, 0x30C8, 0x30C0, 0x30A6, 0x30F3 }; + static constexpr OUStringLiteral aTest = u"\u30B7\u30E3\u30C3\u30C8\u30C0\u30A6\u30F3"; - OUString aTest(JAPANESE, SAL_N_ELEMENTS(JAPANESE)); aBounds = xBreak->getWordBoundary(aTest, 5, aLocale, i18n::WordType::DICTIONARY_WORD, true); @@ -1011,9 +972,8 @@ void TestBreakIterator::doTestJapanese(uno::Reference< i18n::XBreakIterator > co } { - const sal_Unicode JAPANESE[] = { 0x9EBB, 0x306E, 0x8449, 0x9EBB, 0x306E, 0x8449 }; + static constexpr OUStringLiteral aTest = u"\u9EBB\u306E\u8449\u9EBB\u306E\u8449"; - OUString aTest(JAPANESE, SAL_N_ELEMENTS(JAPANESE)); aBounds = xBreak->getWordBoundary(aTest, 1, aLocale, i18n::WordType::DICTIONARY_WORD, true); @@ -1044,9 +1004,8 @@ void TestBreakIterator::testChinese() aLocale.Country = "CN"; { - const sal_Unicode CHINESE[] = { 0x6A35, 0x6A30, 0x69FE, 0x8919, 0xD867, 0xDEDB }; + static constexpr OUStringLiteral aTest = u"\u6A35\u6A30\u69FE\u8919\U00029EDB"; - OUString aTest(CHINESE, SAL_N_ELEMENTS(CHINESE)); i18n::Boundary aBounds = m_xBreak->getWordBoundary(aTest, 4, aLocale, i18n::WordType::DICTIONARY_WORD, true); CPPUNIT_ASSERT(aBounds.startPos == 4 && aBounds.endPos == 6); diff --git a/i18npool/qa/cppunit/test_characterclassification.cxx b/i18npool/qa/cppunit/test_characterclassification.cxx index 4af3984409a7..e2ea659eaccb 100644 --- a/i18npool/qa/cppunit/test_characterclassification.cxx +++ b/i18npool/qa/cppunit/test_characterclassification.cxx @@ -51,8 +51,7 @@ void TestCharacterClassification::testTitleCase() { //tricky one - const sal_Unicode LATINSMALLLETTERDZ[] = { 0x01F3 }; - OUString aTest(LATINSMALLLETTERDZ, SAL_N_ELEMENTS(LATINSMALLLETTERDZ)); + static constexpr OUStringLiteral aTest = u"\u01F3"; // LATIN SMALL LETTER DZ OUString sTitleCase = m_xCC->toTitle(aTest, 0, aTest.getLength(), aLocale); CPPUNIT_ASSERT_MESSAGE("Should be title", sTitleCase.getLength() == 1 && sTitleCase[0] == 0x01F2); OUString sUpperCase = m_xCC->toUpper(aTest, 0, aTest.getLength(), aLocale); @@ -78,8 +77,7 @@ void TestCharacterClassification::testStringType() { //tricky case - const sal_Unicode MATHEMATICAL_ITALIC_SMALL_THETA[] = { 0xD835, 0xDF03 }; - OUString sTest(MATHEMATICAL_ITALIC_SMALL_THETA, SAL_N_ELEMENTS(MATHEMATICAL_ITALIC_SMALL_THETA)); + static constexpr OUStringLiteral sTest = u"\U0001D703"; // MATHEMATICAL ITALIC SMALL THETA sal_Int32 nResult = m_xCC->getStringType(sTest, 0, sTest.getLength(), aLocale); CPPUNIT_ASSERT_EQUAL(sal_Int32(228), nResult); } diff --git a/sal/qa/rtl/oustring/rtl_OUString2.cxx b/sal/qa/rtl/oustring/rtl_OUString2.cxx index 516378dc14a7..0e85a066f33f 100644 --- a/sal/qa/rtl/oustring/rtl_OUString2.cxx +++ b/sal/qa/rtl/oustring/rtl_OUString2.cxx @@ -792,10 +792,10 @@ public: }; void convertToString::test() { - static sal_Unicode const utf16[] = { 0x0041, 0x00E4, 0x0061 }; + static constexpr OUStringLiteral utf16 = u"A\u00E4a"; OString s; CPPUNIT_ASSERT( - OUString(utf16, SAL_N_ELEMENTS(utf16)).convertToString( + OUString(utf16).convertToString( &s, RTL_TEXTENCODING_UTF7, (RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR | RTL_UNICODETOTEXT_FLAGS_INVALID_ERROR))); @@ -932,7 +932,8 @@ void createFromCodePoints::test() { CPPUNIT_ASSERT_EQUAL( sal_Int32(0), OUString(static_cast< sal_uInt32 const * >(nullptr), 0).getLength()); - static sal_uInt32 const cp[] = { 0, 0xD800, 0xFFFF, 0x10000, 0x10FFFF }; + sal_uInt32 cp[] = { 0, 0xD800, 0xFFFF, 0x10000, 0x10FFFF }; + // non-const, to avoid loplugin:stringliteralvar OUString s(cp, SAL_N_ELEMENTS(cp)); CPPUNIT_ASSERT_EQUAL(sal_Int32(7), s.getLength()); CPPUNIT_ASSERT_EQUAL(u'\0', s[0]); @@ -954,9 +955,9 @@ public: }; void iterateCodePoints::testNotWellFormed() { - static sal_Unicode const utf16[] = - { 0xD800, 0xDC00, 0x0041, 0xDBFF, 0xDFFF, 0xDDEF, 0xD9AB }; - OUString s(utf16, SAL_N_ELEMENTS(utf16)); + static constexpr OUStringLiteral utf16 = + u"\U00010000A\U0010FFFF\xDDEF\xD9AB"; + OUString s(utf16); sal_Int32 i = 0; CPPUNIT_ASSERT_EQUAL(sal_uInt32(0x10000), s.iterateCodePoints(&i)); CPPUNIT_ASSERT_EQUAL(sal_Int32(2), i); diff --git a/sax/source/tools/fastserializer.cxx b/sax/source/tools/fastserializer.cxx index e6538424891c..77ed2b29c3d5 100644 --- a/sax/source/tools/fastserializer.cxx +++ b/sax/source/tools/fastserializer.cxx @@ -44,7 +44,7 @@ using ::com::sun::star::io::XOutputStream; const char sClosingBracket[] = ">"; const char sSlashAndClosingBracket[] = "/>"; -const char sColon[] = ":"; +constexpr OStringLiteral sColon = ":"; const char sOpeningBracket[] = "<"; const char sOpeningBracketAndSlash[] = "</"; const char sQuote[] = "\""; @@ -296,7 +296,7 @@ namespace sax_fastparser { auto const Namespace(mxFastTokenHandler->getUTF8Identifier(NAMESPACE(nElement))); assert(Namespace.hasElements()); writeBytes(Namespace); - writeBytes(sColon, N_CHARS(sColon)); + writeBytes(sColon.getStr(), sColon.getLength()); auto const Element(mxFastTokenHandler->getUTF8Identifier(TOKEN(nElement))); assert(Element.hasElements()); writeBytes(Element); @@ -316,7 +316,7 @@ namespace sax_fastparser { Sequence<sal_Int8> const name( mxFastTokenHandler->getUTF8Identifier(TOKEN(nElement))); return OString(reinterpret_cast<char const*>(ns.getConstArray()), ns.getLength()) - + OString(sColon, N_CHARS(sColon)) + + sColon + OString(reinterpret_cast<char const*>(name.getConstArray()), name.getLength()); } else { Sequence<sal_Int8> const name( diff --git a/svl/qa/unit/svl.cxx b/svl/qa/unit/svl.cxx index beaf62ad39ec..da966596e398 100644 --- a/svl/qa/unit/svl.cxx +++ b/svl/qa/unit/svl.cxx @@ -539,12 +539,12 @@ void Test::testTdf103060() sExpected = "H"; // Heisei era checkPreviewString(aFormatter, sCode, fPreviewNumber, eLang, sExpected); sCode = "GG"; - const sal_Unicode EXPECTED_G2[] = {0x5E73}; - sExpected = OUString(EXPECTED_G2, SAL_N_ELEMENTS(EXPECTED_G2)); + constexpr OUStringLiteral EXPECTED_G2 = u"\u5E73"; + sExpected = EXPECTED_G2; checkPreviewString(aFormatter, sCode, fPreviewNumber, eLang, sExpected); sCode = "GGG"; - const sal_Unicode EXPECTED_G3[] = {0x5E73, 0x6210}; - sExpected = OUString(EXPECTED_G3, SAL_N_ELEMENTS(EXPECTED_G3)); + constexpr OUStringLiteral EXPECTED_G3 = u"\u5E73\u6210"; + sExpected = EXPECTED_G3; checkPreviewString(aFormatter, sCode, fPreviewNumber, eLang, sExpected); } diff --git a/svtools/source/misc/sampletext.cxx b/svtools/source/misc/sampletext.cxx index 950193cce994..13809a57eb12 100644 --- a/svtools/source/misc/sampletext.cxx +++ b/svtools/source/misc/sampletext.cxx @@ -224,303 +224,267 @@ OUString makeShortRepresentativeTextForScript(UScriptCode eScript) { case USCRIPT_GREEK: { - static const sal_Unicode aGrek[] = { - 0x0391, 0x03BB, 0x03C6, 0x03AC, 0x03B2, 0x03B7, 0x03C4, 0x03BF - }; - sSampleText = OUString(aGrek, SAL_N_ELEMENTS(aGrek)); + static constexpr OUStringLiteral aGrek = + u"\u0391\u03BB\u03C6\u03AC\u03B2\u03B7\u03C4\u03BF"; + sSampleText = aGrek; break; } case USCRIPT_HEBREW: { - static const sal_Unicode aHebr[] = { - 0x05D0, 0x05B8, 0x05DC, 0x05B6, 0x05E3, 0x05BE, 0x05D1, 0x05B5, - 0x05BC, 0x05D9, 0x05EA, 0x0020, 0x05E2, 0x05B4, 0x05D1, 0x05B0, - 0x05E8, 0x05B4, 0x05D9 - }; - sSampleText = OUString(aHebr, SAL_N_ELEMENTS(aHebr)); + static constexpr OUStringLiteral aHebr = + u"\u05D0\u05B8\u05DC\u05B6\u05E3\u05BE\u05D1\u05B5" + "\u05BC\u05D9\u05EA \u05E2\u05B4\u05D1\u05B0" + "\u05E8\u05B4\u05D9"; + sSampleText = aHebr; break; } case USCRIPT_ARABIC: { - static const sal_Unicode aArab[] = { - 0x0623, 0x0628, 0x062C, 0x062F, 0x064A, 0x0629, 0x0020, 0x0639, - 0x0631, 0x0628, 0x064A, 0x0629 - }; - sSampleText = OUString(aArab, SAL_N_ELEMENTS(aArab)); + static constexpr OUStringLiteral aArab = + u"\u0623\u0628\u062C\u062F\u064A\u0629 \u0639" + "\u0631\u0628\u064A\u0629"; + sSampleText = aArab; break; } case USCRIPT_ARMENIAN: { - static const sal_Unicode aArmenian[] = { - 0x0561, 0x0575, 0x0562, 0x0578, 0x0582, 0x0562, 0x0565, - 0x0576 - }; - sSampleText = OUString(aArmenian, SAL_N_ELEMENTS(aArmenian)); + static constexpr OUStringLiteral aArmenian = + u"\u0561\u0575\u0562\u0578\u0582\u0562\u0565" + "\u0576"; + sSampleText = aArmenian; break; } case USCRIPT_DEVANAGARI: { - static const sal_Unicode aDeva[] = { - 0x0926, 0x0947, 0x0935, 0x0928, 0x093E, 0x0917, 0x0930, 0x0940 - }; - sSampleText = OUString(aDeva, SAL_N_ELEMENTS(aDeva)); + static constexpr OUStringLiteral aDeva = + u"\u0926\u0947\u0935\u0928\u093E\u0917\u0930\u0940"; + sSampleText = aDeva; break; } case USCRIPT_BENGALI: { - static const sal_Unicode aBeng[] = { - 0x09AC, 0x09BE, 0x0982, 0x09B2, 0x09BE, 0x0020, 0x09B2, 0x09BF, - 0x09AA, 0x09BF - }; - sSampleText = OUString(aBeng, SAL_N_ELEMENTS(aBeng)); + static constexpr OUStringLiteral aBeng = + u"\u09AC\u09BE\u0982\u09B2\u09BE \u09B2\u09BF" + "\u09AA\u09BF"; + sSampleText = aBeng; break; } case USCRIPT_GURMUKHI: { - static const sal_Unicode aGuru[] = { - 0x0A17, 0x0A41, 0x0A30, 0x0A2E, 0x0A41, 0x0A16, 0x0A40 - }; - sSampleText = OUString(aGuru, SAL_N_ELEMENTS(aGuru)); + static constexpr OUStringLiteral aGuru = + u"\u0A17\u0A41\u0A30\u0A2E\u0A41\u0A16\u0A40"; + sSampleText = aGuru; break; } case USCRIPT_GUJARATI: { - static const sal_Unicode aGujr[] = { - 0x0A97, 0x0AC1, 0x0A9C, 0x0AB0, 0x0ABE, 0x0AA4, 0x0aC0, 0x0020, - 0x0AB2, 0x0ABF, 0x0AAA, 0x0ABF - }; - sSampleText = OUString(aGujr, SAL_N_ELEMENTS(aGujr)); + static constexpr OUStringLiteral aGujr = + u"\u0A97\u0AC1\u0A9C\u0AB0\u0ABE\u0AA4\u0aC0 " + "\u0AB2\u0ABF\u0AAA\u0ABF"; + sSampleText = aGujr; break; } case USCRIPT_ORIYA: { - static const sal_Unicode aOrya[] = { - 0x0B09, 0x0B24, 0x0B4D, 0x0B15, 0x0B33, 0x0020, 0x0B32, 0x0B3F, - 0x0B2A, 0x0B3F - }; - sSampleText = OUString(aOrya, SAL_N_ELEMENTS(aOrya)); + static constexpr OUStringLiteral aOrya = + u"\u0B09\u0B24\u0B4D\u0B15\u0B33 \u0B32\u0B3F" + "\u0B2A\u0B3F"; + sSampleText = aOrya; break; } case USCRIPT_TAMIL: { - static const sal_Unicode aTaml[] = { - 0x0B85, 0x0BB0, 0x0BBF, 0x0B9A, 0x0BCD, 0x0B9A, 0x0BC1, 0x0BB5, - 0x0B9F, 0x0BBF - }; - sSampleText = OUString(aTaml, SAL_N_ELEMENTS(aTaml)); + static constexpr OUStringLiteral aTaml = + u"\u0B85\u0BB0\u0BBF\u0B9A\u0BCD\u0B9A\u0BC1\u0BB5" + "\u0B9F\u0BBF"; + sSampleText = aTaml; break; } case USCRIPT_TELUGU: { - static const sal_Unicode aTelu[] = { - 0x0C24, 0x0C46, 0x0C32, 0x0C41, 0x0C17, 0x0C41 - }; - sSampleText = OUString(aTelu, SAL_N_ELEMENTS(aTelu)); + static constexpr OUStringLiteral aTelu = + u"\u0C24\u0C46\u0C32\u0C41\u0C17\u0C41"; + sSampleText = aTelu; break; } case USCRIPT_KANNADA: { - static const sal_Unicode aKnda[] = { - 0x0C95, 0x0CA8, 0x0CCD, 0x0CA8, 0x0CA1, 0x0020, 0x0CB2, 0x0CBF, - 0x0CAA, 0x0CBF - }; - sSampleText = OUString(aKnda, SAL_N_ELEMENTS(aKnda)); + static constexpr OUStringLiteral aKnda = + u"\u0C95\u0CA8\u0CCD\u0CA8\u0CA1 \u0CB2\u0CBF" + "\u0CAA\u0CBF"; + sSampleText = aKnda; break; } case USCRIPT_MALAYALAM: { - static const sal_Unicode aMlym[] = { - 0x0D2E, 0x0D32, 0x0D2F, 0x0D3E, 0x0D33, 0x0D32, 0x0D3F, 0x0D2A, - 0x0D3F - }; - sSampleText = OUString(aMlym, SAL_N_ELEMENTS(aMlym)); + static constexpr OUStringLiteral aMlym = + u"\u0D2E\u0D32\u0D2F\u0D3E\u0D33\u0D32\u0D3F\u0D2A" + "\u0D3F"; + sSampleText = aMlym; break; } case USCRIPT_THAI: { - static const sal_Unicode aThai[] = { - 0x0E2D, 0x0E31, 0x0E01, 0x0E29, 0x0E23, 0x0E44, 0x0E17, 0x0E22 - }; - sSampleText = OUString(aThai, SAL_N_ELEMENTS(aThai)); + static constexpr OUStringLiteral aThai = + u"\u0E2D\u0E31\u0E01\u0E29\u0E23\u0E44\u0E17\u0E22"; + sSampleText = aThai; break; } case USCRIPT_LAO: { - static const sal_Unicode aLao[] = { - 0x0EAD, 0x0EB1, 0x0E81, 0x0EAA, 0x0EAD, 0x0E99, 0x0EA5, 0x0EB2, - 0x0EA7 - }; - sSampleText = OUString(aLao, SAL_N_ELEMENTS(aLao)); + static constexpr OUStringLiteral aLao = + u"\u0EAD\u0EB1\u0E81\u0EAA\u0EAD\u0E99\u0EA5\u0EB2" + "\u0EA7"; + sSampleText = aLao; break; } case USCRIPT_GEORGIAN: { - static const sal_Unicode aGeorgian[] = { - 0x10D3, 0x10D0, 0x10DB, 0x10EC, 0x10D4, 0x10E0, 0x10DA, 0x10DD, - 0x10D1, 0x10D0 - }; - sSampleText = OUString(aGeorgian, SAL_N_ELEMENTS(aGeorgian)); + static constexpr OUStringLiteral aGeorgian = + u"\u10D3\u10D0\u10DB\u10EC\u10D4\u10E0\u10DA\u10DD" + "\u10D1\u10D0"; + sSampleText = aGeorgian; break; } case USCRIPT_JAMO: case USCRIPT_HANGUL: case USCRIPT_KOREAN: { - static const sal_Unicode aHang[] = { - 0xD55C, 0xAE00 - }; - sSampleText = OUString(aHang, SAL_N_ELEMENTS(aHang)); + static constexpr OUStringLiteral aHang = + u"\uD55C\uAE00"; + sSampleText = aHang; break; } case USCRIPT_TIBETAN: { - static const sal_Unicode aTibt[] = { - 0x0F51, 0x0F56, 0x0F74, 0x0F0B, 0x0F45, 0x0F53, 0x0F0B - }; - sSampleText = OUString(aTibt, SAL_N_ELEMENTS(aTibt)); + static constexpr OUStringLiteral aTibt = + u"\u0F51\u0F56\u0F74\u0F0B\u0F45\u0F53\u0F0B"; + sSampleText = aTibt; break; } case USCRIPT_SYRIAC: { - static const sal_Unicode aSyri[] = { - 0x0723, 0x071B, 0x072A, 0x0722, 0x0713, 0x0720, 0x0710 - }; - sSampleText = OUString(aSyri, SAL_N_ELEMENTS(aSyri)); + static constexpr OUStringLiteral aSyri = + u"\u0723\u071B\u072A\u0722\u0713\u0720\u0710"; + sSampleText = aSyri; break; } case USCRIPT_THAANA: { - static const sal_Unicode aThaa[] = { - 0x078C, 0x07A7, 0x0782, 0x07A6 - }; - sSampleText = OUString(aThaa, SAL_N_ELEMENTS(aThaa)); + static constexpr OUStringLiteral aThaa = + u"\u078C\u07A7\u0782\u07A6"; + sSampleText = aThaa; break; } case USCRIPT_SINHALA: { - static const sal_Unicode aSinh[] = { - 0x0DC1, 0x0DD4, 0x0DAF, 0x0DCA, 0x0DB0, 0x0020, 0x0DC3, 0x0DD2, - 0x0D82, 0x0DC4, 0x0DBD - }; - sSampleText = OUString(aSinh, SAL_N_ELEMENTS(aSinh)); + static constexpr OUStringLiteral aSinh = + u"\u0DC1\u0DD4\u0DAF\u0DCA\u0DB0 \u0DC3\u0DD2" + "\u0D82\u0DC4\u0DBD"; + sSampleText = aSinh; break; } case USCRIPT_MYANMAR: { - static const sal_Unicode aMymr[] = { - 0x1019, 0x103C, 0x1014, 0x103A, 0x1019, 0x102C, 0x1021, 0x1000, - 0x1039, 0x1001, 0x101B, 0x102C - }; - sSampleText = OUString(aMymr, SAL_N_ELEMENTS(aMymr)); + static constexpr OUStringLiteral aMymr = + u"\u1019\u103C\u1014\u103A\u1019\u102C\u1021\u1000" + "\u1039\u1001\u101B\u102C"; + sSampleText = aMymr; break; } case USCRIPT_ETHIOPIC: { - static const sal_Unicode aEthi[] = { - 0x130D, 0x12D5, 0x12DD - }; - sSampleText = OUString(aEthi, SAL_N_ELEMENTS(aEthi)); + static constexpr OUStringLiteral aEthi = + u"\u130D\u12D5\u12DD"; + sSampleText = aEthi; break; } case USCRIPT_CHEROKEE: { - static const sal_Unicode aCher[] = { - 0x13D7, 0x13AA, 0x13EA, 0x13B6, 0x13D9, 0x13D7 - }; - sSampleText = OUString(aCher, SAL_N_ELEMENTS(aCher)); + static constexpr OUStringLiteral aCher = + u"\u13D7\u13AA\u13EA\u13B6\u13D9\u13D7"; + sSampleText = aCher; break; } case USCRIPT_KHMER: { - static const sal_Unicode aKhmr[] = { - 0x17A2, 0x1780, 0x17D2, 0x1781, 0x179A, 0x1780, 0x17D2, 0x179A, - 0x1798, 0x1781, 0x17C1, 0x1798, 0x179A, 0x1797, 0x17B6, 0x179F, - 0x17B6 - }; - sSampleText = OUString(aKhmr, SAL_N_ELEMENTS(aKhmr)); + static constexpr OUStringLiteral aKhmr = + u"\u17A2\u1780\u17D2\u1781\u179A\u1780\u17D2\u179A" + "\u1798\u1781\u17C1\u1798\u179A\u1797\u17B6\u179F" + "\u17B6"; + sSampleText = aKhmr; break; } case USCRIPT_MONGOLIAN: { - static const sal_Unicode aMongolian[] = { - 0x182A, 0x1822, 0x1834, 0x1822, 0x182D, 0x180C - }; - sSampleText = OUString(aMongolian, SAL_N_ELEMENTS(aMongolian)); + static constexpr OUStringLiteral aMongolian = + u"\u182A\u1822\u1834\u1822\u182D\u180C"; + sSampleText = aMongolian; break; } case USCRIPT_TAGALOG: { - static const sal_Unicode aTagalog[] = { - 0x170A, 0x170A, 0x170C, 0x1712 - }; - sSampleText = OUString(aTagalog, SAL_N_ELEMENTS(aTagalog)); + static constexpr OUStringLiteral aTagalog = + u"\u170A\u170A\u170C\u1712"; + sSampleText = aTagalog; break; } case USCRIPT_NEW_TAI_LUE: { - static const sal_Unicode aTalu[] = { - 0x1991, 0x19BA, 0x199F, 0x19B9, 0x19C9 - }; - sSampleText = OUString(aTalu, SAL_N_ELEMENTS(aTalu)); + static constexpr OUStringLiteral aTalu = + u"\u1991\u19BA\u199F\u19B9\u19C9"; + sSampleText = aTalu; break; } case USCRIPT_TRADITIONAL_HAN: { - static const sal_Unicode aHant[] = { - 0x7E41 - }; - sSampleText = OUString(aHant, SAL_N_ELEMENTS(aHant)); + static constexpr OUStringLiteral aHant = + u"\u7E41"; + sSampleText = aHant; break; } case USCRIPT_SIMPLIFIED_HAN: { - static const sal_Unicode aHans[] = { - 0x7B80 - }; - sSampleText = OUString(aHans, SAL_N_ELEMENTS(aHans)); + static constexpr OUStringLiteral aHans = + u"\u7B80"; + sSampleText = aHans; break; } case USCRIPT_HAN: { - static const sal_Unicode aSimplifiedAndTraditionalChinese[] = { - 0x7B80, 0x7E41 - }; - sSampleText = OUString(aSimplifiedAndTraditionalChinese, - SAL_N_ELEMENTS(aSimplifiedAndTraditionalChinese)); + static constexpr OUStringLiteral aSimplifiedAndTraditionalChinese = + u"\u7B80\u7E41"; + sSampleText = aSimplifiedAndTraditionalChinese; break; } case USCRIPT_JAPANESE: { - static const sal_Unicode aJpan[] = { - 0x65E5, 0x672C, 0x8A9E - }; - sSampleText = OUString(aJpan, SAL_N_ELEMENTS(aJpan)); + static constexpr OUStringLiteral aJpan = + u"\u65E5\u672C\u8A9E"; + sSampleText = aJpan; break; } case USCRIPT_YI: { - static const sal_Unicode aYiii[] = { - 0xA188, 0xA320, 0xA071, 0xA0B7 - }; - sSampleText = OUString(aYiii, SAL_N_ELEMENTS(aYiii)); + static constexpr OUStringLiteral aYiii = + u"\uA188\uA320\uA071\uA0B7"; + sSampleText = aYiii; break; } case USCRIPT_PHAGS_PA: { - static const sal_Unicode aPhag[] = { - 0xA84F, 0xA861, 0xA843, 0x0020, 0xA863, 0xA861, 0xA859, 0x0020, - 0xA850, 0xA85C, 0xA85E - }; - sSampleText = OUString(aPhag, SAL_N_ELEMENTS(aPhag)); + static constexpr OUStringLiteral aPhag = + u"\uA84F\uA861\uA843 \uA863\uA861\uA859 " + u"\uA850\uA85C\uA85E"; + sSampleText = aPhag; break; } case USCRIPT_TAI_LE: { - static const sal_Unicode aTale[] = { - 0x1956, 0x196D, 0x1970, 0x1956, 0x196C, 0x1973, 0x1951, 0x1968, - 0x1952, 0x1970 - }; - sSampleText = OUString(aTale, SAL_N_ELEMENTS(aTale)); + static constexpr OUStringLiteral aTale = + u"\u1956\u196D\u1970\u1956\u196C\u1973\u1951\u1968" + "\u1952\u1970"; + sSampleText = aTale; break; } case USCRIPT_LATIN: @@ -542,19 +506,17 @@ static OUString makeRepresentativeTextForScript(UScriptCode eScript) case USCRIPT_HAN: { //Three Character Classic - static const sal_Unicode aZh[] = { - 0x4EBA, 0x4E4B, 0x521D, 0x0020, 0x6027, 0x672C, 0x5584 - }; - sSampleText = OUString(aZh, SAL_N_ELEMENTS(aZh)); + static constexpr OUStringLiteral aZh = + u"\u4EBA\u4E4B\u521D \u6027\u672C\u5584"; + sSampleText = aZh; break; } case USCRIPT_JAPANESE: { //'Beautiful Japanese' - static const sal_Unicode aJa[] = { - 0x7F8E, 0x3057, 0x3044, 0x65E5, 0x672C, 0x8A9E - }; - sSampleText = OUString(aJa, SAL_N_ELEMENTS(aJa)); + static constexpr OUStringLiteral aJa = + u"\u7F8E\u3057\u3044\u65E5\u672C\u8A9E"; + sSampleText = aJa; break; } case USCRIPT_JAMO: @@ -562,11 +524,10 @@ static OUString makeRepresentativeTextForScript(UScriptCode eScript) case USCRIPT_HANGUL: { //The essential condition for... - static const sal_Unicode aKo[] = { - 0xD0A4, 0xC2A4, 0xC758, 0x0020, 0xACE0, 0xC720, 0xC870, - 0xAC74, 0xC740 - }; - sSampleText = OUString(aKo, SAL_N_ELEMENTS(aKo)); + static constexpr OUStringLiteral aKo = + u"\uD0A4\uC2A4\uC758 \uACE0\uC720\uC870" + "\uAC74\uC740"; + sSampleText = aKo; break; } default: @@ -585,18 +546,16 @@ OUString makeShortMinimalTextForScript(UScriptCode eScript) { case USCRIPT_GREEK: { - static const sal_Unicode aGrek[] = { - 0x0391, 0x0392 - }; - sSampleText = OUString(aGrek, SAL_N_ELEMENTS(aGrek)); + static constexpr OUStringLiteral aGrek = + u"\u0391\u0392"; + sSampleText = aGrek; break; } case USCRIPT_HEBREW: { - static const sal_Unicode aHebr[] = { - 0x05D0, 0x05D1 - }; - sSampleText = OUString(aHebr, SAL_N_ELEMENTS(aHebr)); + static constexpr OUStringLiteral aHebr = + u"\u05D0\u05D1"; + sSampleText = aHebr; break; } default: @@ -638,11 +597,10 @@ static OUString makeRepresentativeTextForLanguage(LanguageType eLang) sRet = makeRepresentativeTextForScript(USCRIPT_DEVANAGARI); else if( pri == primary(LANGUAGE_ASSAMESE) ) { - static const sal_Unicode aAs[] = { - 0x0985, 0x09B8, 0x09AE, 0x09C0, 0x09AF, 0x09BC, 0x09BE, - 0x0020, 0x0986, 0x0996, 0x09F0 - }; - sRet = OUString(aAs, SAL_N_ELEMENTS(aAs)); + static constexpr OUStringLiteral aAs = + u"\u0985\u09B8\u09AE\u09C0\u09AF\u09BC\u09BE" + " \u0986\u0996\u09F0"; + sRet = aAs; } else if( pri == primary(LANGUAGE_BENGALI) ) sRet = makeRepresentativeTextForScript(USCRIPT_BENGALI); @@ -696,10 +654,9 @@ static OUString makeRepresentativeTextForLanguage(LanguageType eLang) sRet = makeRepresentativeTextForScript(USCRIPT_YI); else if( pri == primary(LANGUAGE_GAELIC_IRELAND) ) { - static const sal_Unicode aGa[] = { - 'T', 0x00E9, 'a', 'c', 's', ' ', 'S', 'a', 'm', 'p', 'l', 'a', 'c', 'h' - }; - sRet = OUString(aGa, SAL_N_ELEMENTS(aGa)); + static constexpr OUStringLiteral aGa = + u"T\u00E9acs Samplach"; + sRet = aGa; } return sRet; @@ -1234,23 +1191,19 @@ namespace bool bKore = false, bJpan = false, bHant = false, bHans = false; - static const sal_Unicode aKorean[] = { 0x4E6D, 0x4E76, 0x596C }; - OUString sKorean(aKorean, SAL_N_ELEMENTS(aKorean)); + static constexpr OUStringLiteral sKorean = u"\u4E6D\u4E76\u596C"; if (-1 == rDevice.HasGlyphs(rFont, sKorean)) bKore = true; - static const sal_Unicode aJapanese[] = { 0x5968, 0x67A0, 0x9D8F }; - OUString sJapanese(aJapanese, SAL_N_ELEMENTS(aJapanese)); + static constexpr OUStringLiteral sJapanese = u"\u5968\u67A0\u9D8F"; if (-1 == rDevice.HasGlyphs(rFont, sJapanese)) bJpan = true; - static const sal_Unicode aTraditionalChinese[] = { 0x555F, 0x96DE }; - OUString sTraditionalChinese(aTraditionalChinese, SAL_N_ELEMENTS(aTraditionalChinese)); + static constexpr OUStringLiteral sTraditionalChinese = u"\u555F\u96DE"; if (-1 == rDevice.HasGlyphs(rFont, sTraditionalChinese)) bHant = true; - static const sal_Unicode aSimplifiedChinese[] = { 0x4E61, 0x542F, 0x5956 }; - OUString sSimplifiedChinese(aSimplifiedChinese, SAL_N_ELEMENTS(aSimplifiedChinese)); + static constexpr OUStringLiteral sSimplifiedChinese = u"\u4E61\u542F\u5956"; if (-1 == rDevice.HasGlyphs(rFont, sSimplifiedChinese)) bHans = true; diff --git a/sw/qa/core/uwriter.cxx b/sw/qa/core/uwriter.cxx index 02202d6fe8e2..ee394002e115 100644 --- a/sw/qa/core/uwriter.cxx +++ b/sw/qa/core/uwriter.cxx @@ -287,15 +287,13 @@ void SwDocTest::testUserPerceivedCharCount() //Grapheme example, two different unicode code-points perceived by the user as a single //glyph - const sal_Unicode ALEF_QAMATS [] = { 0x05D0, 0x05B8 }; - OUString sALEF_QAMATS(ALEF_QAMATS, SAL_N_ELEMENTS(ALEF_QAMATS)); + static constexpr OUStringLiteral sALEF_QAMATS = u"\u05D0\u05B8"; sal_Int32 nGraphemeCount = pBreakIter->getGraphemeCount(sALEF_QAMATS); CPPUNIT_ASSERT_EQUAL_MESSAGE("Grapheme Count should be 1", static_cast<sal_Int32>(1), nGraphemeCount); //Surrogate pair example, one single unicode code-point (U+1D11E) //represented as two code units in UTF-16 - const sal_Unicode GCLEF[] = { 0xD834, 0xDD1E }; - OUString sGCLEF(GCLEF, SAL_N_ELEMENTS(GCLEF)); + static constexpr OUStringLiteral sGCLEF = u"\U0001D11E"; sal_Int32 nCount = pBreakIter->getGraphemeCount(sGCLEF); CPPUNIT_ASSERT_EQUAL_MESSAGE("Surrogate Pair should be counted as single character", static_cast<sal_Int32>(1), nCount); } @@ -616,10 +614,9 @@ void SwDocTest::testSwScanner() //See https://www.libreoffice.org/bugzilla/show_bug.cgi?id=45271 { - const sal_Unicode IDEOGRAPHICFULLSTOP_D[] = { 0x3002, 'D' }; + static constexpr OUStringLiteral IDEOGRAPHICFULLSTOP_D = u"\u3002D"; - m_pDoc->getIDocumentContentOperations().InsertString(aPaM, OUString(IDEOGRAPHICFULLSTOP_D, - SAL_N_ELEMENTS(IDEOGRAPHICFULLSTOP_D))); + m_pDoc->getIDocumentContentOperations().InsertString(aPaM, IDEOGRAPHICFULLSTOP_D); SvxLanguageItem aCJKLangItem( LANGUAGE_CHINESE_SIMPLIFIED, RES_CHRATR_CJK_LANGUAGE ); SvxLanguageItem aWestLangItem( LANGUAGE_ENGLISH_US, RES_CHRATR_LANGUAGE ); @@ -628,34 +625,31 @@ void SwDocTest::testSwScanner() SwDocStat aDocStat; pTextNode = aPaM.GetNode().GetTextNode(); - pTextNode->CountWords(aDocStat, 0, SAL_N_ELEMENTS(IDEOGRAPHICFULLSTOP_D)); + pTextNode->CountWords(aDocStat, 0, IDEOGRAPHICFULLSTOP_D.getLength()); CPPUNIT_ASSERT_EQUAL(static_cast<sal_uLong>(2), aDocStat.nChar); CPPUNIT_ASSERT_EQUAL(static_cast<sal_uLong>(2), aDocStat.nCharExcludingSpaces); } { - const sal_Unicode test[] = - { - 0x3053, 0x306E, 0x65E5, 0x672C, 0x8A9E, 0x306F, 0x6B63, 0x3057, - 0x304F, 0x6570, 0x3048, 0x3089, 0x308C, 0x308B, 0x3067, 0x3057, - 0x3087, 0x3046, 0x304B, 0x3002, 0x0041, 0x006E, 0x0064, 0x0020, - 0x006C, 0x0065, 0x0074, 0x0027, 0x0073, 0x0020, 0x0074, 0x0068, - 0x0072, 0x006F, 0x0077, 0x0020, 0x0073, 0x006F, 0x006D, 0x0065, - 0x0020, 0x0045, 0x006E, 0x0067, 0x006C, 0x0069, 0x0073, 0x0068, - 0x0020, 0x0069, 0x006E, 0x0020, 0x0074, 0x006F, 0x0020, 0x006D, - 0x0061, 0x006B, 0x0065, 0x0020, 0x0069, 0x0074, 0x0020, 0x0069, - 0x006E, 0x0074, 0x0065, 0x0072, 0x0065, 0x0073, 0x0074, 0x0069, - 0x006E, 0x0067, 0x002E, 0x0020, 0x0020, 0x305D, 0x3057, 0x3066, - 0x3001, 0x307E, 0x305F, 0x65E5, 0x672C, 0x8A9E, 0x3000, 0x3000, - 0x3067, 0x3082, 0x4ECA, 0x56DE, 0x306F, 0x7A7A, 0x767D, 0x3092, - 0x3000, 0x3000, 0x5165, 0x308C, 0x307E, 0x3057, 0x305F, 0x3002, - 0x0020, 0x0020, 0x0053, 0x006F, 0x0020, 0x0068, 0x006F, 0x0077, - 0x0020, 0x0064, 0x006F, 0x0065, 0x0073, 0x0020, 0x0074, 0x0068, - 0x0069, 0x0073, 0x0020, 0x0064, 0x006F, 0x003F, 0x0020, 0x0020 - }; + static constexpr OUStringLiteral test = + u"\u3053\u306E\u65E5\u672C\u8A9E\u306F\u6B63\u3057" + "\u304F\u6570\u3048\u3089\u308C\u308B\u3067\u3057" + "\u3087\u3046\u304B\u3002And " + "let's th" + "row some" + " English" + " in to m" + "ake it i" + "nteresti" + "ng. \u305D\u3057\u3066" + "\u3001\u307E\u305F\u65E5\u672C\u8A9E\u3000\u3000" + "\u3067\u3082\u4ECA\u56DE\u306F\u7A7A\u767D\u3092" + "\u3000\u3000\u5165\u308C\u307E\u3057\u305F\u3002" + " So how" + " does th" + "is do? "; m_pDoc->getIDocumentContentOperations().AppendTextNode(*aPaM.GetPoint()); - m_pDoc->getIDocumentContentOperations().InsertString(aPaM, OUString(test, - SAL_N_ELEMENTS(test))); + m_pDoc->getIDocumentContentOperations().InsertString(aPaM, test); SvxLanguageItem aCJKLangItem( LANGUAGE_JAPANESE, RES_CHRATR_CJK_LANGUAGE ); SvxLanguageItem aWestLangItem( LANGUAGE_ENGLISH_US, RES_CHRATR_LANGUAGE ); @@ -664,7 +658,7 @@ void SwDocTest::testSwScanner() SwDocStat aDocStat; pTextNode = aPaM.GetNode().GetTextNode(); - pTextNode->CountWords(aDocStat, 0, SAL_N_ELEMENTS(test)); + pTextNode->CountWords(aDocStat, 0, test.getLength()); CPPUNIT_ASSERT_EQUAL_MESSAGE("words", static_cast<sal_uLong>(58), aDocStat.nWord); CPPUNIT_ASSERT_EQUAL_MESSAGE("Asian characters and Korean syllables", static_cast<sal_uLong>(43), aDocStat.nAsianWord); CPPUNIT_ASSERT_EQUAL_MESSAGE("non-whitespace chars", static_cast<sal_uLong>(105), aDocStat.nCharExcludingSpaces); @@ -676,34 +670,31 @@ void SwDocTest::testSwScanner() { SwDocStat aDocStat; - const sal_Unicode aShouldBeThree[] = { - 0x0053, 0x0068, 0x006F, 0x0075, 0x006C, 0x0064, 0x0020, - 0x2018, 0x0062, 0x0065, 0x0020, 0x0074, 0x0068, 0x0072, - 0x0065, 0x0065, 0x2019 - }; + static constexpr OUStringLiteral aShouldBeThree = + u"Should " + "\u2018be thr" + "ee\u2019"; m_pDoc->getIDocumentContentOperations().AppendTextNode(*aPaM.GetPoint()); - m_pDoc->getIDocumentContentOperations().InsertString(aPaM, OUString(aShouldBeThree, SAL_N_ELEMENTS(aShouldBeThree))); + m_pDoc->getIDocumentContentOperations().InsertString(aPaM, aShouldBeThree); pTextNode = aPaM.GetNode().GetTextNode(); - pTextNode->CountWords(aDocStat, 0, SAL_N_ELEMENTS(aShouldBeThree)); + pTextNode->CountWords(aDocStat, 0, aShouldBeThree.getLength()); CPPUNIT_ASSERT_EQUAL(static_cast<sal_uLong>(3), aDocStat.nWord); - const sal_Unicode aShouldBeFive[] = { - // f r e n c h space - 0x0046, 0x0072, 0x0065, 0x006E, 0x0063, 0x0068, 0x0020, - // << nbsp s a v o i - 0x00AB, 0x00A0, 0x0073, 0x0061, 0x0076, 0x006F, 0x0069, - // r nnbsp c a l c u - 0x0072, 0x202f, 0x0063, 0x0061, 0x006C, 0x0063, 0x0075, - // l e r idspace >> - 0x006C, 0x0065, 0x0072, 0x3000, 0x00BB - }; + static constexpr OUStringLiteral aShouldBeFive = + u"french " + // << nbsp + "\u00AB\u00A0savoi" + // nnbsp + "r\u202fcalcu" + // idspace >> + "ler\u3000\u00BB"; m_pDoc->getIDocumentContentOperations().AppendTextNode(*aPaM.GetPoint()); - m_pDoc->getIDocumentContentOperations().InsertString(aPaM, OUString(aShouldBeFive, SAL_N_ELEMENTS(aShouldBeFive))); + m_pDoc->getIDocumentContentOperations().InsertString(aPaM, aShouldBeFive); pTextNode = aPaM.GetNode().GetTextNode(); aDocStat.Reset(); - pTextNode->CountWords(aDocStat, 0, SAL_N_ELEMENTS(aShouldBeFive)); + pTextNode->CountWords(aDocStat, 0, aShouldBeFive.getLength()); CPPUNIT_ASSERT_EQUAL(static_cast<sal_uLong>(5), aDocStat.nWord); } @@ -934,8 +925,7 @@ void SwDocTest::testSwScanner() aDocStat.nChar == 15); aDocStat.Reset(); - const sal_Unicode aChunk[] = {' ', 0x2013, ' '}; - OUString sChunk(aChunk, SAL_N_ELEMENTS(aChunk)); + static constexpr OUStringLiteral sChunk = u" \u2013 "; m_pDoc->getIDocumentContentOperations().AppendTextNode(*aPaM.GetPoint()); m_pDoc->getIDocumentContentOperations().InsertString(aPaM, sTemplate.replaceAll("X", sChunk)); pTextNode = aPaM.GetNode().GetTextNode(); diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport10.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport10.cxx index 626157e803dd..45f9a46000e1 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport10.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport10.cxx @@ -881,10 +881,10 @@ DECLARE_OOXMLEXPORT_TEST(testTdf65955_2, "tdf65955_2.odt") DECLARE_OOXMLEXPORT_TEST(testChtOutlineNumberingOoxml, "chtoutline.docx") { - const sal_Unicode aExpectedNumbering[] = { 0x7b2c, ' ', '1', ' ', 0x7ae0 }; + static constexpr OUStringLiteral aExpectedNumbering = u"\u7b2c 1 \u7ae0"; uno::Reference<beans::XPropertySet> xPara(getParagraph(1), uno::UNO_QUERY); - CPPUNIT_ASSERT_EQUAL(OUString(aExpectedNumbering,SAL_N_ELEMENTS(aExpectedNumbering)), + CPPUNIT_ASSERT_EQUAL(OUString(aExpectedNumbering), getProperty<OUString>(xPara, "ListLabelString")); } diff --git a/sw/qa/extras/ooxmlimport/ooxmlimport2.cxx b/sw/qa/extras/ooxmlimport/ooxmlimport2.cxx index b0589b913248..f7114235cc77 100644 --- a/sw/qa/extras/ooxmlimport/ooxmlimport2.cxx +++ b/sw/qa/extras/ooxmlimport/ooxmlimport2.cxx @@ -669,10 +669,9 @@ DECLARE_OOXMLIMPORT_TEST(testTdf129912, "tdf129912.docx") // the expected footnote labels // TODO: the 5th label is actually wrong (missing the "PR" after the symbol part), but the "b" is there?! - const sal_Unicode pLabel5[] = { u'\xF0D1', u'\xF031', u'\xF032', u'\x0062' }; - const OUString sFootnoteLabels[] = { - OUString(u'\xF0A7'), "1", "2", OUString(u'\xF020'), { pLabel5, SAL_N_ELEMENTS(pLabel5) } - }; + static constexpr OUStringLiteral pLabel5 = u"\uF0D1\uF031\uF032b"; + const OUString sFootnoteLabels[] + = { OUString(u'\xF0A7'), "1", "2", OUString(u'\xF020'), pLabel5 }; CPPUNIT_ASSERT_EQUAL(sal_Int32(SAL_N_ELEMENTS(sFootnoteLabels)), nCount); pWrtShell->GotoPrevFootnoteAnchor(); diff --git a/sw/qa/extras/rtfimport/rtfimport.cxx b/sw/qa/extras/rtfimport/rtfimport.cxx index 4749fa3acf6f..ae99eab0d49a 100644 --- a/sw/qa/extras/rtfimport/rtfimport.cxx +++ b/sw/qa/extras/rtfimport/rtfimport.cxx @@ -1093,10 +1093,10 @@ CPPUNIT_TEST_FIXTURE(Test, testCp950listleveltext1) load(mpTestDocumentPath, "cp950listleveltext1.rtf"); // suffix with Chinese only ( most common case generated by MSO2010 TC) // This is a dot that is generally used as suffix of Chinese list number - const sal_Unicode aExpectedNumbering[] = { 0x4e00, 0x3001 }; + static constexpr OUStringLiteral aExpectedNumbering = u"\u4e00\u3001"; uno::Reference<beans::XPropertySet> xPara(getParagraph(1), uno::UNO_QUERY); - CPPUNIT_ASSERT_EQUAL(OUString(aExpectedNumbering, SAL_N_ELEMENTS(aExpectedNumbering)), + CPPUNIT_ASSERT_EQUAL(OUString(aExpectedNumbering), getProperty<OUString>(xPara, "ListLabelString")); } @@ -1105,10 +1105,10 @@ CPPUNIT_TEST_FIXTURE(Test, testCp950listleveltext2) { load(mpTestDocumentPath, "cp950listleveltext2.rtf"); // Prefix and suffix with Chinese only ( tweaked from default in MSO2010 TC) - const sal_Unicode aExpectedNumbering[] = { 0x524d, 0x7f6e, 0x7532, 0x3001, 0x5f8c, 0x7f6e }; + static constexpr OUStringLiteral aExpectedNumbering = u"\u524d\u7f6e\u7532\u3001\u5f8c\u7f6e"; uno::Reference<beans::XPropertySet> xPara(getParagraph(1), uno::UNO_QUERY); - CPPUNIT_ASSERT_EQUAL(OUString(aExpectedNumbering, SAL_N_ELEMENTS(aExpectedNumbering)), + CPPUNIT_ASSERT_EQUAL(OUString(aExpectedNumbering), getProperty<OUString>(xPara, "ListLabelString")); } @@ -1117,11 +1117,11 @@ CPPUNIT_TEST_FIXTURE(Test, testCp950listleveltext3) { load(mpTestDocumentPath, "cp950listleveltext3.rtf"); // Numbering is a mix Chinese and English ( tweaked from default in MSO2010 TC) - const sal_Unicode aExpectedNumbering[] = { 0x524d, 0x0061, 0x7f6e, 0x0062, 0x7532, 0x3001, - 0x0063, 0x5f8c, 0x0064, 0x7f6e, 0x0065 }; + static constexpr OUStringLiteral aExpectedNumbering = u"\u524da\u7f6eb\u7532\u3001" + "c\u5f8cd\u7f6ee"; uno::Reference<beans::XPropertySet> xPara(getParagraph(1), uno::UNO_QUERY); - CPPUNIT_ASSERT_EQUAL(OUString(aExpectedNumbering, SAL_N_ELEMENTS(aExpectedNumbering)), + CPPUNIT_ASSERT_EQUAL(OUString(aExpectedNumbering), getProperty<OUString>(xPara, "ListLabelString")); } @@ -1129,10 +1129,10 @@ CPPUNIT_TEST_FIXTURE(Test, testChtOutlineNumberingRtf) { load(mpTestDocumentPath, "chtoutline.rtf"); - const sal_Unicode aExpectedNumbering[] = { 0x7b2c, ' ', '1', ' ', 0x7ae0 }; + static constexpr OUStringLiteral aExpectedNumbering = u"\u7b2c 1 \u7ae0"; uno::Reference<beans::XPropertySet> xPara(getParagraph(1), uno::UNO_QUERY); - CPPUNIT_ASSERT_EQUAL(OUString(aExpectedNumbering, SAL_N_ELEMENTS(aExpectedNumbering)), + CPPUNIT_ASSERT_EQUAL(OUString(aExpectedNumbering), getProperty<OUString>(xPara, "ListLabelString")); } diff --git a/sw/source/filter/ww8/ww8par3.cxx b/sw/source/filter/ww8/ww8par3.cxx index b7df7589a5e7..6f2ce9f0aa5f 100644 --- a/sw/source/filter/ww8/ww8par3.cxx +++ b/sw/source/filter/ww8/ww8par3.cxx @@ -2400,11 +2400,9 @@ bool WW8FormulaListBox::Import(const uno::Reference < } else { - static const sal_Unicode aBlank[] = - { - 0x2002,0x2002,0x2002,0x2002,0x2002 - }; - rSz = mrRdr.MiserableDropDownFormHack(OUString(aBlank, SAL_N_ELEMENTS(aBlank)), xPropSet); + static constexpr OUStringLiteral aBlank = + u"\u2002\u2002\u2002\u2002\u2002"; + rSz = mrRdr.MiserableDropDownFormHack(aBlank, xPropSet); } return true; diff --git a/vcl/qa/cppunit/complextext.cxx b/vcl/qa/cppunit/complextext.cxx index f76dce72f42d..f769fe4688b4 100644 --- a/vcl/qa/cppunit/complextext.cxx +++ b/vcl/qa/cppunit/complextext.cxx @@ -141,14 +141,12 @@ void VclComplexTextTest::testKashida() void VclComplexTextTest::testTdf95650() { - const sal_Unicode pTxt[] = { - 0x0131, 0x0302, 0x0504, 0x4E44, 0x3031, 0x3030, 0x3531, 0x2D30, - 0x3037, 0x0706, 0x0908, 0x0B0A, 0x0D0C, 0x0F0E, 0x072E, 0x100A, - 0x0D11, 0x1312, 0x0105, 0x020A, 0x0512, 0x1403, 0x030C, 0x1528, - 0x2931, 0x632E, 0x7074, 0x0D20, 0x0E0A, 0x100A, 0xF00D, 0x0D20, - 0x030A, 0x0C0B, 0x20E0, 0x0A0D - }; - OUString aTxt(pTxt, SAL_N_ELEMENTS(pTxt) - 1); + static constexpr OUStringLiteral aTxt = + u"\u0131\u0302\u0504\u4E44\u3031\u3030\u3531\u2D30" + "\u3037\u0706\u0908\u0B0A\u0D0C\u0F0E\u072E\u100A" + "\u0D11\u1312\u0105\u020A\u0512\u1403\u030C\u1528" + "\u2931\u632E\u7074\u0D20\u0E0A\u100A\uF00D\u0D20" + "\u030A\u0C0B\u20E0\u0A0D"; ScopedVclPtrInstance<WorkWindow> pWin(static_cast<vcl::Window *>(nullptr)); CPPUNIT_ASSERT(pWin); diff --git a/vcl/qa/cppunit/mnemonic.cxx b/vcl/qa/cppunit/mnemonic.cxx index 59456503b54f..ed4c8a86f61e 100644 --- a/vcl/qa/cppunit/mnemonic.cxx +++ b/vcl/qa/cppunit/mnemonic.cxx @@ -40,14 +40,14 @@ void VclMnemonicTest::testMnemonic() } { - const sal_Unicode TEST[] = { 0x4E00, 'b' }; - OUString sResult = aGenerator.CreateMnemonic(OUString(TEST, SAL_N_ELEMENTS(TEST))); + static constexpr OUStringLiteral TEST = u"\u4E00b"; + OUString sResult = aGenerator.CreateMnemonic(TEST); CPPUNIT_ASSERT_EQUAL(u'~', sResult[1]); } { - const sal_Unicode TEST[] = { 0x4E00 }; - OUString sResult = aGenerator.CreateMnemonic(OUString(TEST, SAL_N_ELEMENTS(TEST))); + static constexpr OUStringLiteral TEST = u"\u4E00"; + OUString sResult = aGenerator.CreateMnemonic(TEST); CPPUNIT_ASSERT_EQUAL(OUString("(~C)"), sResult.copy(sResult.getLength() - 4)); } } |