[Libreoffice-commits] .: svl/inc svl/qa svl/source

Kohei Yoshida kohei at kemper.freedesktop.org
Thu Feb 24 12:47:15 PST 2011


 svl/inc/svl/zformat.hxx        |   21 +++++++++++++++----
 svl/qa/unit/svl.cxx            |    9 ++++++++
 svl/source/numbers/zformat.cxx |   45 +++++++++++++++++++++++++++++++----------
 3 files changed, 61 insertions(+), 14 deletions(-)

New commits:
commit 26ab3db800dec0654dddf5ac29d2e78d956a6fe5
Author: Kohei Yoshida <kyoshida at novell.com>
Date:   Thu Feb 24 15:44:30 2011 -0500

    Pick up numeral shape and calendar type as well as the language.
    
    So far this change doesn't affect the behavior of the number formatter
    but only to pick up extra data that Excel provides (that we need to
    map to our own later on).

diff --git a/svl/inc/svl/zformat.hxx b/svl/inc/svl/zformat.hxx
index 25268de..fb14f87 100644
--- a/svl/inc/svl/zformat.hxx
+++ b/svl/inc/svl/zformat.hxx
@@ -489,6 +489,18 @@ private:
                    xub_StrLen& nPos,
                    String& sSymbol );
 
+    struct LocaleType
+    {
+        sal_uInt8 mnNumeralShape;
+        sal_uInt8 mnCalendarType;
+        LanguageType meLanguage;
+
+        ::rtl::OUString generateCode() const;
+
+        LocaleType();
+        LocaleType(sal_uInt32 nRawCode);
+    };
+
     /**
      * Parse the content of '[$-xxx] or '[$-xxxxxxxx]' and extract the
      * language type from it.  Given the string, start parsing at position
@@ -502,11 +514,12 @@ private:
      * @param rString input string
      * @param nPos position (see above).
      *
-     * @return LCID that specifies language type.  See i18npool/lang.h for a
-     *         complete list of language types.  These numbers also correspond
-     *         with the numbers used by Microsoft Office.
+     * @return struct containing numeral shape, calendar type, and LCID that
+     *         specifies language type. See i18npool/lang.h for a complete
+     *         list of language types. These numbers also correspond with the
+     *         numbers used by Microsoft Office.
      */
-    SVL_DLLPRIVATE static LanguageType ImpGetLanguageType( const String& rString, xub_StrLen& nPos );
+    SVL_DLLPRIVATE static LocaleType ImpGetLocaleType( const String& rString, xub_StrLen& nPos );
 
     // standard number output
     SVL_DLLPRIVATE void ImpGetOutputStandard( double& fNumber, String& OutString );
diff --git a/svl/qa/unit/svl.cxx b/svl/qa/unit/svl.cxx
index a56c90f..91f406d 100644
--- a/svl/qa/unit/svl.cxx
+++ b/svl/qa/unit/svl.cxx
@@ -242,6 +242,15 @@ void Test::testNumberFormat()
             CPPUNIT_ASSERT_MESSAGE("Unexpected number format code.", bEqual);
         }
     }
+
+    xub_StrLen nPos;
+    short nType = NUMBERFORMAT_DEFINED;
+    sal_uInt32 nKey;
+    String aCode(RTL_CONSTASCII_USTRINGPARAM("[$-1070000]d/mm/yyyy;@")); // Thai date format.
+    if (!aFormatter.PutEntry(aCode, nPos, nType, nKey))
+    {
+        CPPUNIT_ASSERT_MESSAGE("failed to insert format code '[$-1070000]d/mm/yyyy;@'", false);
+    }
 }
 
 CPPUNIT_TEST_SUITE_REGISTRATION(Test);
diff --git a/svl/source/numbers/zformat.cxx b/svl/source/numbers/zformat.cxx
index 882c8a5..fc3b316 100644
--- a/svl/source/numbers/zformat.cxx
+++ b/svl/source/numbers/zformat.cxx
@@ -798,17 +798,17 @@ SvNumberformat::SvNumberformat(String& rString,
                         else
                         {
                             xub_StrLen nTmp = 2;
-                            LanguageType eLang = ImpGetLanguageType( sStr, nTmp );
-                            if ( eLang == LANGUAGE_DONTKNOW )
+                            LocaleType aLocale = ImpGetLocaleType( sStr, nTmp );
+                            if (aLocale.meLanguage == LANGUAGE_DONTKNOW)
                             {
                                 bCancel = TRUE;         // break for
                                 nCheckPos = nPosOld;
                             }
                             else
                             {
-                                sStr.AssignAscii( RTL_CONSTASCII_STRINGPARAM( "$-" ) );
-                                sStr += String::CreateFromInt32( sal_Int32( eLang ), 16 ).ToUpperAscii();
-                                NumFor[nIndex].SetNatNumLang( eLang );
+                                sStr.AssignAscii( RTL_CONSTASCII_STRINGPARAM("$-") );
+                                sStr += String::CreateFromInt32(sal_Int32(aLocale.meLanguage), 16).ToUpperAscii();
+                                NumFor[nIndex].SetNatNumLang(aLocale.meLanguage);
                             }
                         }
                     }
@@ -1095,11 +1095,36 @@ xub_StrLen SvNumberformat::ImpGetNumber(String& rString,
     return nPos - nStartPos;
 }
 
+::rtl::OUString SvNumberformat::LocaleType::generateCode() const
+{
+    // TODO: to be worked on .....
+    return ::rtl::OUString();
+}
+
+SvNumberformat::LocaleType::LocaleType() :
+    mnNumeralShape(0),
+    mnCalendarType(0),
+    meLanguage(LANGUAGE_DONTKNOW)
+{
+}
+
+SvNumberformat::LocaleType::LocaleType(sal_uInt32 nRawNum) :
+    mnNumeralShape(0),
+    mnCalendarType(0),
+    meLanguage(LANGUAGE_DONTKNOW)
+{
+    meLanguage = static_cast<LanguageType>(nRawNum & 0x0000FFFF);
+    nRawNum = (nRawNum >> 16);
+    mnCalendarType = static_cast<sal_uInt8>(nRawNum & 0xFF);
+    nRawNum = (nRawNum >> 8);
+    mnNumeralShape = static_cast<sal_uInt8>(nRawNum & 0xFF);
+}
+
 // static
-LanguageType SvNumberformat::ImpGetLanguageType( const String& rString,
-        xub_StrLen& nPos )
+SvNumberformat::LocaleType SvNumberformat::ImpGetLocaleType(
+    const String& rString, xub_StrLen& nPos )
 {
-    sal_Int32 nNum = 0;
+    sal_uInt32 nNum = 0;
     sal_Unicode cToken = 0;
     xub_StrLen nLen = rString.Len();
     while ( nPos < nLen && ((cToken = rString.GetChar(nPos)) != ']') )
@@ -1123,8 +1148,8 @@ LanguageType SvNumberformat::ImpGetLanguageType( const String& rString,
             return LANGUAGE_DONTKNOW;
         ++nPos;
     }
-    return (nNum && (cToken == ']' || nPos == nLen)) ? (LanguageType)nNum :
-        LANGUAGE_DONTKNOW;
+
+    return (nNum && (cToken == ']' || nPos == nLen)) ? LocaleType(nNum) : LocaleType();
 }
 
 short SvNumberformat::ImpNextSymbol(String& rString,


More information about the Libreoffice-commits mailing list