diff options
author | Caolán McNamara <caolanm@redhat.com> | 2013-10-28 15:39:20 +0000 |
---|---|---|
committer | Eike Rathke <erack@redhat.com> | 2013-10-29 12:02:44 +0000 |
commit | f1ade1468f26d70c49bd3697f10497e914dd8121 (patch) | |
tree | 0355719dd1965fec9ead8349f582e25ee863e558 /i18npool | |
parent | eae6ac5550d28379a55231111af022da7f1f936d (diff) |
Related: fdo#69641 double iterateCodePoints doesn't make sense to me
This came in with 04212c3015cd4ab118a0aec2bb04bc153a64af41 but
the bug number of #i86439# appears to be the wrong id. It doesn't
make sense to me. Rework cclass_Unicode::getStringType to iterate
safely over the codepoints of the requested range. Perhaps that
was the reason for the original commit.
Change-Id: Ice4287eb6f9fc6a9705845c0cf995263815de2e7
(cherry picked from commit 507e627d83dbfb6a35677450a3fc42d10c79a82e)
Related: fdo#69641 check index against length before iterateCodePoints
Change-Id: I71346b12fcfe3e02015038c3c78db574ada873d6
(cherry picked from commit 08b7af126e546bdbd175023429f544baa9861dba)
Related: fdo#69641 add a regression test
Change-Id: Icf3324a224d02425acd679a286f3c4a0b7e3ed1c
(cherry picked from commit 9d5b07b9085f97edfff5d4ac474e9711036bb0c4)
lets be super sure in the face of falling between surrogates
Change-Id: I6d8259df3d4f2e73f9236b7c0547f87c89801082
(cherry picked from commit 8f0ecf253531963144d3d1c9ee5c12a6cda99c4e)
Reviewed-on: https://gerrit.libreoffice.org/6473
Reviewed-by: Eike Rathke <erack@redhat.com>
Tested-by: Eike Rathke <erack@redhat.com>
Diffstat (limited to 'i18npool')
-rw-r--r-- | i18npool/qa/cppunit/test_characterclassification.cxx | 26 | ||||
-rw-r--r-- | i18npool/source/characterclassification/cclass_unicode.cxx | 12 |
2 files changed, 35 insertions, 3 deletions
diff --git a/i18npool/qa/cppunit/test_characterclassification.cxx b/i18npool/qa/cppunit/test_characterclassification.cxx index a683c3a50c9a..92066c7395db 100644 --- a/i18npool/qa/cppunit/test_characterclassification.cxx +++ b/i18npool/qa/cppunit/test_characterclassification.cxx @@ -27,9 +27,11 @@ public: virtual void tearDown(); void testTitleCase(); + void testStringType(); CPPUNIT_TEST_SUITE(TestCharacterClassification); CPPUNIT_TEST(testTitleCase); + CPPUNIT_TEST(testStringType); CPPUNIT_TEST_SUITE_END(); private: uno::Reference<i18n::XCharacterClassification> m_xCC; @@ -68,6 +70,30 @@ void TestCharacterClassification::testTitleCase() } } +//https://bugs.freedesktop.org/show_bug.cgi?id=69641 +void TestCharacterClassification::testStringType() +{ + lang::Locale aLocale; + aLocale.Language = OUString("en"); + aLocale.Country = OUString("US"); + + { + //simple case + OUString sTest("Some text"); + sal_Int32 nResult = m_xCC->getStringType(sTest, 0, sTest.getLength(), aLocale); + CPPUNIT_ASSERT_EQUAL(nResult, sal_Int32(230)); + } + + { + //tricky case + const sal_Unicode MATHEMATICAL_ITALIC_SMALL_THETA[] = { 0xD835, 0xDF03 }; + OUString sTest(MATHEMATICAL_ITALIC_SMALL_THETA, SAL_N_ELEMENTS(MATHEMATICAL_ITALIC_SMALL_THETA)); + sal_Int32 nResult = m_xCC->getStringType(sTest, 0, sTest.getLength(), aLocale); + CPPUNIT_ASSERT_EQUAL(nResult, sal_Int32(228)); + } + +} + void TestCharacterClassification::setUp() { BootstrapFixtureBase::setUp(); diff --git a/i18npool/source/characterclassification/cclass_unicode.cxx b/i18npool/source/characterclassification/cclass_unicode.cxx index 045de399227a..a729ca8f4c3b 100644 --- a/i18npool/source/characterclassification/cclass_unicode.cxx +++ b/i18npool/source/characterclassification/cclass_unicode.cxx @@ -132,7 +132,6 @@ cclass_Unicode::getCharType( const OUString& Text, sal_Int32* nPos, sal_Int32 in using namespace ::com::sun::star::i18n::KCharacterType; sal_uInt32 ch = Text.iterateCodePoints(nPos, increment); - if (increment > 0) ch = Text.iterateCodePoints(nPos, 0); switch ( u_charType(ch) ) { // Upper case U_UPPERCASE_LETTER : @@ -204,9 +203,16 @@ sal_Int32 SAL_CALL cclass_Unicode::getStringType( const OUString& Text, sal_Int32 nPos, sal_Int32 nCount, const Locale& /*rLocale*/ ) throw(RuntimeException) { if ( nPos < 0 || Text.getLength() <= nPos ) return 0; - sal_Int32 result = getCharType(Text, &nPos, 0); - for (sal_Int32 i = 1; i < nCount && nPos < Text.getLength(); i++) + sal_Int32 result = 0; + + while (nCount > 0 && nPos < Text.getLength()) + { + sal_Int32 nOrigPos = nPos; result |= getCharType(Text, &nPos, 1); + sal_Int32 nUtf16Units = nPos - nOrigPos; + nCount -= nUtf16Units; + } + return result; } |