summaryrefslogtreecommitdiff
path: root/svl
diff options
context:
space:
mode:
authorLászló Németh <nemeth@numbertext.org>2022-10-27 08:36:37 +0200
committerLászló Németh <nemeth@numbertext.org>2022-11-03 22:20:36 +0100
commit2a1d2d42af7f365330479f4032ddfdd9eeba7c1d (patch)
tree079e5d9995d8fe86e4290604011897f057eb6d0f /svl
parent142d3e15916afd1c38bcccf0d23cac292ea357fc (diff)
tdf#115007 add NatNum12 number format list items, fix title case
Add NumberText NatNum12 number formats, e.g. "One Hundred", and currency formats, e.g. "One U.S. Dollar and Twenty Cents" to number formatting dialog windows, i.e. Format Cells->Numbers in Calc and Format Numbers in Writer (Edit Fields->Format-> Additional formats...). Fix also bad English title case: "One Euro *and* *Twenty-Two* cents" (not *And* and *Twenty-two*) Details: – svl: list NatNum12 NumberText currency codes in Currency formats (i.e. after choosing Currency category). – svx: Recognize bank symbol "CURRENCY" in NatNum12 parameters defined in locale resource files. For example, "[NatNum12 CURRENCY]" is converted to "[NatNum12 USD]" in the number format dialog windows, using bank symbol of the current locale settings. Recognize compatible (old) bank symbol "CCC" in NatNum12 parameters defined in locale resource files. For example, "[NatNum12 CCC]" is converted to "[NatNum12 DEM]" in the number format dialog windows, using bank symbol of the compatible currency of the German locale settings. User-defined formats with arbitrary bank codes are recognized as currency formats, e.g. modifying "[NatNum12 USD]" to "[NatNum12 EUR]" in the dialog window results a new currency format item. – i18npool/*en_US.xml: define four Standard NatNum12 formats (lower case, sentence case, title case, upper case) and four Currency NatNum12 formats (title case, title case with digits, upper case, upper case with digits). – cui: use lower sample numbers for spell out formats: – 100 for Standard: One Hundred one hundred One hundred ONE HUNDRED – 1.2 for Currency: One U.S. Dollar ONE U.S. DOLLAR One U.S. Dollar and Twenty Cents ONE U.S. DOLLAR AND TWENTY CENTS – i18npool: fix English title casing of NatNum12 conversions: – Don't apply casing on "and", according to the title case rules, for example: "One Euro and One Cent" instead of "One Euro And One Cent". – Apply casing on the second element of the hyphenated compound words: "Twenty-One" instead of the bad "Twenty-one". – add unit test for extended Number and Currency categories. Note: according to the changes, update user-defined number format id in chart2/qa/extras/chart2dump/reference/chartdatatest/simple_chart.txt Change-Id: Ieaf9a8f75a4f197b858eaf67f83484df70295834 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/141994 Tested-by: Jenkins Reviewed-by: László Németh <nemeth@numbertext.org>
Diffstat (limited to 'svl')
-rw-r--r--svl/source/numbers/zformat.cxx38
1 files changed, 37 insertions, 1 deletions
diff --git a/svl/source/numbers/zformat.cxx b/svl/source/numbers/zformat.cxx
index 4aa5543ed5d3..54f3ce6276d2 100644
--- a/svl/source/numbers/zformat.cxx
+++ b/svl/source/numbers/zformat.cxx
@@ -721,6 +721,32 @@ bool NatNumTakesParameters(sal_Int16 nNum)
}
}
+// is there a 3-letter bank code in NatNum12 param (but not
+// followed by an equal mark, like in the date code "NNN=")?
+static bool lcl_isNatNum12Currency( const OUString& sParam )
+{
+ sal_Int32 nUpper = 0;
+ sal_Int32 nLen = sParam.getLength();
+ for (sal_Int32 n = 0; n < nLen; ++n)
+ {
+ sal_Unicode c = sParam[n];
+ if ( 'A' <= c && c <= 'Z' )
+ {
+ ++nUpper;
+ }
+ else if ( c == ' ' && nUpper == 3 && (n == 3 || sParam[n - 4] == ' ') )
+ {
+ return true;
+ }
+ else
+ {
+ nUpper = 0;
+ }
+ }
+
+ return nUpper == 3 && (nLen == 3 || sParam[nLen - 4] == ' ');
+}
+
SvNumberformat::SvNumberformat(OUString& rString,
ImpSvNumberformatScan* pSc,
ImpSvNumberInputScan* pISc,
@@ -938,6 +964,12 @@ SvNumberformat::SvNumberformat(OUString& rString,
{
if (sParams.isEmpty())
sParams = "cardinal"; // default NatNum12 format is "cardinal"
+ else if (sParams.indexOf("CURRENCY") >= 0)
+ sParams = sParams.replaceAll("CURRENCY",
+ GetFormatter().GetLocaleData()->getCurrBankSymbol());
+ // compatible (old) currency format
+ else if (sParams.indexOf("CCC") >= 0)
+ sParams = sParams.replaceAll("CCC", rScan.GetCurAbbrev());
NumFor[nIndex].SetNatNumParams(sParams);
sStr += " " + sParams;
}
@@ -1176,7 +1208,11 @@ SvNumberformat::SvNumberformat(OUString& rString,
// type check
if (nIndex == 0)
{
- eType = NumFor[nIndex].Info().eScannedType;
+ if ( NumFor[nIndex].GetNatNum().GetNatNum() == 12 &&
+ lcl_isNatNum12Currency(NumFor[nIndex].GetNatNum().GetParams()) )
+ eType = SvNumFormatType::CURRENCY;
+ else
+ eType = NumFor[nIndex].Info().eScannedType;
}
else if (nIndex == 3)
{ // #77026# Everything recognized IS text