/src/icu/source/i18n/number_notation.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | // © 2017 and later: Unicode, Inc. and others. |
2 | | // License & terms of use: http://www.unicode.org/copyright.html |
3 | | |
4 | | #include "unicode/utypes.h" |
5 | | |
6 | | #if !UCONFIG_NO_FORMATTING |
7 | | |
8 | | #include "unicode/numberformatter.h" |
9 | | #include "number_types.h" |
10 | | |
11 | | using namespace icu; |
12 | | using namespace icu::number; |
13 | | using namespace icu::number::impl; |
14 | | |
15 | | |
16 | 0 | ScientificNotation Notation::scientific() { |
17 | | // NOTE: ISO C++ does not allow C99 designated initializers. |
18 | 0 | ScientificSettings settings; |
19 | 0 | settings.fEngineeringInterval = 1; |
20 | 0 | settings.fRequireMinInt = false; |
21 | 0 | settings.fMinExponentDigits = 1; |
22 | 0 | settings.fExponentSignDisplay = UNUM_SIGN_AUTO; |
23 | 0 | NotationUnion union_; |
24 | 0 | union_.scientific = settings; |
25 | 0 | return {NTN_SCIENTIFIC, union_}; |
26 | 0 | } |
27 | | |
28 | 0 | ScientificNotation Notation::engineering() { |
29 | 0 | ScientificSettings settings; |
30 | 0 | settings.fEngineeringInterval = 3; |
31 | 0 | settings.fRequireMinInt = false; |
32 | 0 | settings.fMinExponentDigits = 1; |
33 | 0 | settings.fExponentSignDisplay = UNUM_SIGN_AUTO; |
34 | 0 | NotationUnion union_; |
35 | 0 | union_.scientific = settings; |
36 | 0 | return {NTN_SCIENTIFIC, union_}; |
37 | 0 | } |
38 | | |
39 | | ScientificNotation::ScientificNotation(int8_t fEngineeringInterval, bool fRequireMinInt, |
40 | | impl::digits_t fMinExponentDigits, |
41 | 0 | UNumberSignDisplay fExponentSignDisplay) { |
42 | 0 | ScientificSettings settings; |
43 | 0 | settings.fEngineeringInterval = fEngineeringInterval; |
44 | 0 | settings.fRequireMinInt = fRequireMinInt; |
45 | 0 | settings.fMinExponentDigits = fMinExponentDigits; |
46 | 0 | settings.fExponentSignDisplay = fExponentSignDisplay; |
47 | 0 | NotationUnion union_; |
48 | 0 | union_.scientific = settings; |
49 | 0 | *this = {NTN_SCIENTIFIC, union_}; |
50 | 0 | } |
51 | | |
52 | 0 | Notation Notation::compactShort() { |
53 | 0 | NotationUnion union_; |
54 | 0 | union_.compactStyle = CompactStyle::UNUM_SHORT; |
55 | 0 | return {NTN_COMPACT, union_}; |
56 | 0 | } |
57 | | |
58 | 0 | Notation Notation::compactLong() { |
59 | 0 | NotationUnion union_; |
60 | 0 | union_.compactStyle = CompactStyle::UNUM_LONG; |
61 | 0 | return {NTN_COMPACT, union_}; |
62 | 0 | } |
63 | | |
64 | 0 | Notation Notation::simple() { |
65 | 0 | return {}; |
66 | 0 | } |
67 | | |
68 | | ScientificNotation |
69 | 0 | ScientificNotation::withMinExponentDigits(int32_t minExponentDigits) const { |
70 | 0 | if (minExponentDigits >= 1 && minExponentDigits <= kMaxIntFracSig) { |
71 | 0 | ScientificSettings settings = fUnion.scientific; |
72 | 0 | settings.fMinExponentDigits = static_cast<digits_t>(minExponentDigits); |
73 | 0 | NotationUnion union_ = {settings}; |
74 | 0 | return {NTN_SCIENTIFIC, union_}; |
75 | 0 | } else { |
76 | 0 | return {U_NUMBER_ARG_OUTOFBOUNDS_ERROR}; |
77 | 0 | } |
78 | 0 | } |
79 | | |
80 | | ScientificNotation |
81 | 0 | ScientificNotation::withExponentSignDisplay(UNumberSignDisplay exponentSignDisplay) const { |
82 | 0 | ScientificSettings settings = fUnion.scientific; |
83 | 0 | settings.fExponentSignDisplay = exponentSignDisplay; |
84 | 0 | NotationUnion union_ = {settings}; |
85 | 0 | return {NTN_SCIENTIFIC, union_}; |
86 | 0 | } |
87 | | |
88 | | #endif /* #if !UCONFIG_NO_FORMATTING */ |