[Libreoffice-commits] .: svl/qa svl/source
Kohei Yoshida
kohei at kemper.freedesktop.org
Thu Feb 24 15:15:43 PST 2011
svl/qa/unit/svl.cxx | 9 ++++++
svl/source/numbers/zformat.cxx | 54 +++++++++++++++++++++++++++++++++++++----
2 files changed, 58 insertions(+), 5 deletions(-)
New commits:
commit 2efd2c6715dc31ec6d7831f70bd520d93489c47a
Author: Kohei Yoshida <kyoshida at novell.com>
Date: Thu Feb 24 18:13:28 2011 -0500
Generate locale code that includes numeral shape and calendar type.
diff --git a/svl/qa/unit/svl.cxx b/svl/qa/unit/svl.cxx
index 0b54b2c..4e16b49 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 fc3b316..461fac7 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() :
More information about the Libreoffice-commits
mailing list