[Libreoffice-commits] core.git: Branch 'libreoffice-4-1' - i18npool/qa i18npool/source sc/source

Caolán McNamara caolanm at redhat.com
Tue Oct 29 13:03:05 CET 2013


 i18npool/qa/cppunit/test_characterclassification.cxx       |   26 +++++++++++++
 i18npool/source/characterclassification/cclass_unicode.cxx |   12 ++++--
 sc/source/core/tool/interpr1.cxx                           |    4 +-
 3 files changed, 37 insertions(+), 5 deletions(-)

New commits:
commit f1ade1468f26d70c49bd3697f10497e914dd8121
Author: Caolán McNamara <caolanm at redhat.com>
Date:   Mon Oct 28 15:39:20 2013 +0000

    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 at redhat.com>
    Tested-by: Eike Rathke <erack at redhat.com>

diff --git a/i18npool/qa/cppunit/test_characterclassification.cxx b/i18npool/qa/cppunit/test_characterclassification.cxx
index a683c3a..92066c7 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 045de39..a729ca8 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;
 }
 
diff --git a/sc/source/core/tool/interpr1.cxx b/sc/source/core/tool/interpr1.cxx
index 29050bb..a03b13a 100644
--- a/sc/source/core/tool/interpr1.cxx
+++ b/sc/source/core/tool/interpr1.cxx
@@ -3467,11 +3467,11 @@ void ScInterpreter::ScNumberValue()
     {
         OUString aTemporary( nDecSep >= 0 ? aInputString.copy( 0, nDecSep ) : aInputString );
         sal_Int32 nIndex = 0;
-        do
+        while (nIndex < aGroupSeparator.getLength())
         {
             sal_uInt32 nChar = aGroupSeparator.iterateCodePoints( &nIndex );
             aTemporary = aTemporary.replaceAll( OUString( &nChar, 1 ), "" );
-        } while ( nIndex < aGroupSeparator.getLength() );
+        }
         if ( nDecSep >= 0 )
             aInputString = aTemporary + aInputString.copy( nDecSep );
         else


More information about the Libreoffice-commits mailing list