diff options
author | Kohei Yoshida <kyoshida@novell.com> | 2011-02-24 18:13:28 -0500 |
---|---|---|
committer | Kohei Yoshida <kyoshida@novell.com> | 2011-02-24 18:13:28 -0500 |
commit | 65493885df5c5d6dc1ade2f311f01e74d270fa57 (patch) | |
tree | 4d66d0692daa23217c54392bdae3ac89c36b448a /svl | |
parent | 8bd3bc3f698278e9fbe57dfe990b9500c2dd3588 (diff) |
Generate locale code that includes numeral shape and calendar type.
Diffstat (limited to 'svl')
-rw-r--r-- | svl/qa/unit/svl.cxx | 9 | ||||
-rw-r--r-- | svl/source/numbers/zformat.cxx | 54 |
2 files changed, 58 insertions, 5 deletions
diff --git a/svl/qa/unit/svl.cxx b/svl/qa/unit/svl.cxx index 0b54b2ca5d19..4e16b4990b4c 100644 --- a/svl/qa/unit/svl.cxx +++ b/svl/qa/unit/svl.cxx @@ -264,7 +264,14 @@ void Test::testNumberFormat() xub_StrLen nPos; short nType = NUMBERFORMAT_DEFINED; sal_uInt32 nKey; - String aCode(RTL_CONSTASCII_USTRINGPARAM("[$-1070000]d/mm/yyyy;@")); // Thai date format. + String aCode; + aCode = String(RTL_CONSTASCII_USTRINGPARAM("[$-1070000]d/mm/yyyy;@")); // Thai date format (implicit locale). + if (!aFormatter.PutEntry(aCode, nPos, nType, nKey)) + { + CPPUNIT_ASSERT_MESSAGE("failed to insert format code '[$-1070000]d/mm/yyyy;@'", false); + } + + aCode = String(RTL_CONSTASCII_USTRINGPARAM("[$-107041E]d/mm/yyyy;@")); // Thai date format (explicit locale) if (!aFormatter.PutEntry(aCode, nPos, nType, nKey)) { CPPUNIT_ASSERT_MESSAGE("failed to insert format code '[$-1070000]d/mm/yyyy;@'", false); diff --git a/svl/source/numbers/zformat.cxx b/svl/source/numbers/zformat.cxx index fc3b31651701..461fac7066ac 100644 --- a/svl/source/numbers/zformat.cxx +++ b/svl/source/numbers/zformat.cxx @@ -58,6 +58,8 @@ #include <cmath> using namespace svt; +using ::rtl::OUString; +using ::rtl::OUStringBuffer; namespace { struct Gregorian @@ -807,7 +809,7 @@ SvNumberformat::SvNumberformat(String& rString, else { sStr.AssignAscii( RTL_CONSTASCII_STRINGPARAM("$-") ); - sStr += String::CreateFromInt32(sal_Int32(aLocale.meLanguage), 16).ToUpperAscii(); + sStr = sStr + aLocale.generateCode(); NumFor[nIndex].SetNatNumLang(aLocale.meLanguage); } } @@ -1095,10 +1097,54 @@ xub_StrLen SvNumberformat::ImpGetNumber(String& rString, return nPos - nStartPos; } -::rtl::OUString SvNumberformat::LocaleType::generateCode() const +namespace { + +sal_Unicode toUniChar(sal_uInt8 n) { - // TODO: to be worked on ..... - return ::rtl::OUString(); + sal_Char c; + if (n < 10) + c = '0' + n; + else + c = 'A' + n - 10; + return sal_Unicode(c); +} + +} + +OUString SvNumberformat::LocaleType::generateCode() const +{ + OUStringBuffer aBuf; + if (mnNumeralShape) + { + sal_uInt8 nVal = mnNumeralShape; + for (sal_uInt8 i = 0; i < 2; ++i) + { + sal_uInt8 n = (nVal & 0xF0) >> 4; + aBuf.append(toUniChar(n)); + nVal = nVal << 4; + } + } + + if (mnNumeralShape || mnCalendarType) + { + sal_uInt8 nVal = mnCalendarType; + for (sal_uInt8 i = 0; i < 2; ++i) + { + sal_uInt8 n = (nVal & 0xF0) >> 4; + aBuf.append(toUniChar(n)); + nVal = nVal << 4; + } + } + + sal_uInt16 n16 = static_cast<sal_uInt16>(meLanguage); + for (sal_uInt8 i = 0; i < 4; ++i) + { + sal_uInt8 n = static_cast<sal_uInt8>((n16 & 0xF000) >> 12); + aBuf.append(toUniChar(n)); + n16 = n16 << 4; + } + + return aBuf.makeStringAndClear(); } SvNumberformat::LocaleType::LocaleType() : |