Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(81)

Side by Side Diff: source/i18n/nfsubs.cpp

Issue 845603002: Update ICU to 54.1 step 1 (Closed) Base URL: https://chromium.googlesource.com/chromium/deps/icu.git@master
Patch Set: remove unusued directories Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « source/i18n/nfsubs.h ('k') | source/i18n/numfmt.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 ****************************************************************************** 2 ******************************************************************************
3 * Copyright (C) 1997-2012, International Business Machines 3 * Copyright (C) 1997-2014, International Business Machines
4 * Corporation and others. All Rights Reserved. 4 * Corporation and others. All Rights Reserved.
5 ****************************************************************************** 5 ******************************************************************************
6 * file name: nfsubs.cpp 6 * file name: nfsubs.cpp
7 * encoding: US-ASCII 7 * encoding: US-ASCII
8 * tab size: 8 (not used) 8 * tab size: 8 (not used)
9 * indentation:4 9 * indentation:4
10 * 10 *
11 * Modification history 11 * Modification history
12 * Date Name Comments 12 * Date Name Comments
13 * 10/11/2001 Doug Ported from ICU4J 13 * 10/11/2001 Doug Ported from ICU4J
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 divisor = uprv_pow(radix, exponent); 142 divisor = uprv_pow(radix, exponent);
143 ldivisor = util64_fromDouble(divisor); 143 ldivisor = util64_fromDouble(divisor);
144 144
145 if (divisor == 0) { 145 if (divisor == 0) {
146 status = U_PARSE_ERROR; 146 status = U_PARSE_ERROR;
147 } 147 }
148 } 148 }
149 149
150 virtual UBool operator==(const NFSubstitution& rhs) const; 150 virtual UBool operator==(const NFSubstitution& rhs) const;
151 151
152 virtual void doSubstitution(int64_t number, UnicodeString& toInsertInto, int 32_t pos) const; 152 virtual void doSubstitution(int64_t number, UnicodeString& toInsertInto, int 32_t pos, UErrorCode& status) const;
153 virtual void doSubstitution(double number, UnicodeString& toInsertInto, int3 2_t pos) const; 153 virtual void doSubstitution(double number, UnicodeString& toInsertInto, int3 2_t pos, UErrorCode& status) const;
154 154
155 virtual int64_t transformNumber(int64_t number) const { return number % ldiv isor; } 155 virtual int64_t transformNumber(int64_t number) const { return number % ldiv isor; }
156 virtual double transformNumber(double number) const { return uprv_fmod(numbe r, divisor); } 156 virtual double transformNumber(double number) const { return uprv_fmod(numbe r, divisor); }
157 157
158 virtual UBool doParse(const UnicodeString& text, 158 virtual UBool doParse(const UnicodeString& text,
159 ParsePosition& parsePosition, 159 ParsePosition& parsePosition,
160 double baseValue, 160 double baseValue,
161 double upperBound, 161 double upperBound,
162 UBool lenientParse, 162 UBool lenientParse,
163 Formattable& result) const; 163 Formattable& result) const;
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 public: 211 public:
212 FractionalPartSubstitution(int32_t pos, 212 FractionalPartSubstitution(int32_t pos,
213 const NFRuleSet* ruleSet, 213 const NFRuleSet* ruleSet,
214 const RuleBasedNumberFormat* formatter, 214 const RuleBasedNumberFormat* formatter,
215 const UnicodeString& description, 215 const UnicodeString& description,
216 UErrorCode& status); 216 UErrorCode& status);
217 virtual ~FractionalPartSubstitution(); 217 virtual ~FractionalPartSubstitution();
218 218
219 virtual UBool operator==(const NFSubstitution& rhs) const; 219 virtual UBool operator==(const NFSubstitution& rhs) const;
220 220
221 virtual void doSubstitution(double number, UnicodeString& toInsertInto, int3 2_t pos) const; 221 virtual void doSubstitution(double number, UnicodeString& toInsertInto, int3 2_t pos, UErrorCode& status) const;
222 virtual void doSubstitution(int64_t /*number*/, UnicodeString& /*toInsertInt o*/, int32_t /*_pos*/) const {} 222 virtual void doSubstitution(int64_t /*number*/, UnicodeString& /*toInsertInt o*/, int32_t /*_pos*/, UErrorCode& /*status*/) const {}
223 virtual int64_t transformNumber(int64_t /*number*/) const { return 0; } 223 virtual int64_t transformNumber(int64_t /*number*/) const { return 0; }
224 virtual double transformNumber(double number) const { return number - uprv_f loor(number); } 224 virtual double transformNumber(double number) const { return number - uprv_f loor(number); }
225 225
226 virtual UBool doParse(const UnicodeString& text, 226 virtual UBool doParse(const UnicodeString& text,
227 ParsePosition& parsePosition, 227 ParsePosition& parsePosition,
228 double baseValue, 228 double baseValue,
229 double upperBound, 229 double upperBound,
230 UBool lenientParse, 230 UBool lenientParse,
231 Formattable& result) const; 231 Formattable& result) const;
232 232
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 ldenominator = util64_fromDouble(denominator); 287 ldenominator = util64_fromDouble(denominator);
288 withZeros = description.endsWith(LTLT, 2); 288 withZeros = description.endsWith(LTLT, 2);
289 } 289 }
290 virtual ~NumeratorSubstitution(); 290 virtual ~NumeratorSubstitution();
291 291
292 virtual UBool operator==(const NFSubstitution& rhs) const; 292 virtual UBool operator==(const NFSubstitution& rhs) const;
293 293
294 virtual int64_t transformNumber(int64_t number) const { return number * lden ominator; } 294 virtual int64_t transformNumber(int64_t number) const { return number * lden ominator; }
295 virtual double transformNumber(double number) const { return uprv_round(numb er * denominator); } 295 virtual double transformNumber(double number) const { return uprv_round(numb er * denominator); }
296 296
297 virtual void doSubstitution(int64_t /*number*/, UnicodeString& /*toInsertInt o*/, int32_t /*_pos*/) const {} 297 virtual void doSubstitution(int64_t /*number*/, UnicodeString& /*toInsertInt o*/, int32_t /*_pos*/, UErrorCode& /*status*/) const {}
298 virtual void doSubstitution(double number, UnicodeString& toInsertInto, int3 2_t pos) const; 298 virtual void doSubstitution(double number, UnicodeString& toInsertInto, int3 2_t pos, UErrorCode& status) const;
299 virtual UBool doParse(const UnicodeString& text, 299 virtual UBool doParse(const UnicodeString& text,
300 ParsePosition& parsePosition, 300 ParsePosition& parsePosition,
301 double baseValue, 301 double baseValue,
302 double upperBound, 302 double upperBound,
303 UBool /*lenientParse*/, 303 UBool /*lenientParse*/,
304 Formattable& result) const; 304 Formattable& result) const;
305 305
306 virtual double composeRuleValue(double newRuleValue, double oldRuleValue) co nst { return newRuleValue / oldRuleValue; } 306 virtual double composeRuleValue(double newRuleValue, double oldRuleValue) co nst { return newRuleValue / oldRuleValue; }
307 virtual double calcUpperBound(double /*oldUpperBound*/) const { return denom inator; } 307 virtual double calcUpperBound(double /*oldUpperBound*/) const { return denom inator; }
308 virtual UChar tokenChar() const { return (UChar)0x003c; } // '<' 308 virtual UChar tokenChar() const { return (UChar)0x003c; } // '<'
(...skipping 11 matching lines...) Expand all
320 public: 320 public:
321 NullSubstitution(int32_t _pos, 321 NullSubstitution(int32_t _pos,
322 const NFRuleSet* _ruleSet, 322 const NFRuleSet* _ruleSet,
323 const RuleBasedNumberFormat* formatter, 323 const RuleBasedNumberFormat* formatter,
324 const UnicodeString& description, 324 const UnicodeString& description,
325 UErrorCode& status) 325 UErrorCode& status)
326 : NFSubstitution(_pos, _ruleSet, formatter, description, status) {} 326 : NFSubstitution(_pos, _ruleSet, formatter, description, status) {}
327 virtual ~NullSubstitution(); 327 virtual ~NullSubstitution();
328 328
329 virtual void toString(UnicodeString& /*result*/) const {} 329 virtual void toString(UnicodeString& /*result*/) const {}
330 virtual void doSubstitution(double /*number*/, UnicodeString& /*toInsertInto */, int32_t /*_pos*/) const {} 330 virtual void doSubstitution(double /*number*/, UnicodeString& /*toInsertInto */, int32_t /*_pos*/, UErrorCode& /*status*/) const {}
331 virtual void doSubstitution(int64_t /*number*/, UnicodeString& /*toInsertInt o*/, int32_t /*_pos*/) const {} 331 virtual void doSubstitution(int64_t /*number*/, UnicodeString& /*toInsertInt o*/, int32_t /*_pos*/, UErrorCode& /*status*/) const {}
332 virtual int64_t transformNumber(int64_t /*number*/) const { return 0; } 332 virtual int64_t transformNumber(int64_t /*number*/) const { return 0; }
333 virtual double transformNumber(double /*number*/) const { return 0; } 333 virtual double transformNumber(double /*number*/) const { return 0; }
334 virtual UBool doParse(const UnicodeString& /*text*/, 334 virtual UBool doParse(const UnicodeString& /*text*/,
335 ParsePosition& /*parsePosition*/, 335 ParsePosition& /*parsePosition*/,
336 double baseValue, 336 double baseValue,
337 double /*upperBound*/, 337 double /*upperBound*/,
338 UBool /*lenientParse*/, 338 UBool /*lenientParse*/,
339 Formattable& result) const 339 Formattable& result) const
340 { result.setDouble(baseValue); return TRUE; } 340 { result.setDouble(baseValue); return TRUE; }
341 virtual double composeRuleValue(double /*newRuleValue*/, double /*oldRuleVal ue*/) const { return 0.0; } // never called 341 virtual double composeRuleValue(double /*newRuleValue*/, double /*oldRuleVal ue*/) const { return 0.0; } // never called
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
595 * Performs a mathematical operation on the number, formats it using 595 * Performs a mathematical operation on the number, formats it using
596 * either ruleSet or decimalFormat, and inserts the result into 596 * either ruleSet or decimalFormat, and inserts the result into
597 * toInsertInto. 597 * toInsertInto.
598 * @param number The number being formatted. 598 * @param number The number being formatted.
599 * @param toInsertInto The string we insert the result into 599 * @param toInsertInto The string we insert the result into
600 * @param pos The position in toInsertInto where the owning rule's 600 * @param pos The position in toInsertInto where the owning rule's
601 * rule text begins (this value is added to this substitution's 601 * rule text begins (this value is added to this substitution's
602 * position to determine exactly where to insert the new text) 602 * position to determine exactly where to insert the new text)
603 */ 603 */
604 void 604 void
605 NFSubstitution::doSubstitution(int64_t number, UnicodeString& toInsertInto, int3 2_t _pos) const 605 NFSubstitution::doSubstitution(int64_t number, UnicodeString& toInsertInto, int3 2_t _pos, UErrorCode& status) const
606 { 606 {
607 if (ruleSet != NULL) { 607 if (ruleSet != NULL) {
608 // perform a transformation on the number that is dependent 608 // perform a transformation on the number that is dependent
609 // on the type of substitution this is, then just call its 609 // on the type of substitution this is, then just call its
610 // rule set's format() method to format the result 610 // rule set's format() method to format the result
611 ruleSet->format(transformNumber(number), toInsertInto, _pos + this->pos) ; 611 ruleSet->format(transformNumber(number), toInsertInto, _pos + this->pos, status);
612 } else if (numberFormat != NULL) { 612 } else if (numberFormat != NULL) {
613 // or perform the transformation on the number (preserving 613 // or perform the transformation on the number (preserving
614 // the result's fractional part if the formatter it set 614 // the result's fractional part if the formatter it set
615 // to show it), then use that formatter's format() method 615 // to show it), then use that formatter's format() method
616 // to format the result 616 // to format the result
617 double numberToFormat = transformNumber((double)number); 617 double numberToFormat = transformNumber((double)number);
618 if (numberFormat->getMaximumFractionDigits() == 0) { 618 if (numberFormat->getMaximumFractionDigits() == 0) {
619 numberToFormat = uprv_floor(numberToFormat); 619 numberToFormat = uprv_floor(numberToFormat);
620 } 620 }
621 621
622 UnicodeString temp; 622 UnicodeString temp;
623 numberFormat->format(numberToFormat, temp); 623 numberFormat->format(numberToFormat, temp, status);
624 toInsertInto.insert(_pos + this->pos, temp); 624 toInsertInto.insert(_pos + this->pos, temp);
625 } 625 }
626 } 626 }
627 627
628 /** 628 /**
629 * Performs a mathematical operation on the number, formats it using 629 * Performs a mathematical operation on the number, formats it using
630 * either ruleSet or decimalFormat, and inserts the result into 630 * either ruleSet or decimalFormat, and inserts the result into
631 * toInsertInto. 631 * toInsertInto.
632 * @param number The number being formatted. 632 * @param number The number being formatted.
633 * @param toInsertInto The string we insert the result into 633 * @param toInsertInto The string we insert the result into
634 * @param pos The position in toInsertInto where the owning rule's 634 * @param pos The position in toInsertInto where the owning rule's
635 * rule text begins (this value is added to this substitution's 635 * rule text begins (this value is added to this substitution's
636 * position to determine exactly where to insert the new text) 636 * position to determine exactly where to insert the new text)
637 */ 637 */
638 void 638 void
639 NFSubstitution::doSubstitution(double number, UnicodeString& toInsertInto, int32 _t _pos) const { 639 NFSubstitution::doSubstitution(double number, UnicodeString& toInsertInto, int32 _t _pos, UErrorCode& status) const {
640 // perform a transformation on the number being formatted that 640 // perform a transformation on the number being formatted that
641 // is dependent on the type of substitution this is 641 // is dependent on the type of substitution this is
642 double numberToFormat = transformNumber(number); 642 double numberToFormat = transformNumber(number);
643 643
644 // if the result is an integer, from here on out we work in integer 644 // if the result is an integer, from here on out we work in integer
645 // space (saving time and memory and preserving accuracy) 645 // space (saving time and memory and preserving accuracy)
646 if (numberToFormat == uprv_floor(numberToFormat) && ruleSet != NULL) { 646 if (numberToFormat == uprv_floor(numberToFormat) && ruleSet != NULL) {
647 ruleSet->format(util64_fromDouble(numberToFormat), toInsertInto, _pos + this->pos); 647 ruleSet->format(util64_fromDouble(numberToFormat), toInsertInto, _pos + this->pos, status);
648 648
649 // if the result isn't an integer, then call either our rule set's 649 // if the result isn't an integer, then call either our rule set's
650 // format() method or our DecimalFormat's format() method to 650 // format() method or our DecimalFormat's format() method to
651 // format the result 651 // format the result
652 } else { 652 } else {
653 if (ruleSet != NULL) { 653 if (ruleSet != NULL) {
654 ruleSet->format(numberToFormat, toInsertInto, _pos + this->pos); 654 ruleSet->format(numberToFormat, toInsertInto, _pos + this->pos, stat us);
655 } else if (numberFormat != NULL) { 655 } else if (numberFormat != NULL) {
656 UnicodeString temp; 656 UnicodeString temp;
657 numberFormat->format(numberToFormat, temp); 657 numberFormat->format(numberToFormat, temp);
658 toInsertInto.insert(_pos + this->pos, temp); 658 toInsertInto.insert(_pos + this->pos, temp);
659 } 659 }
660 } 660 }
661 } 661 }
662 662
663 663
664 //----------------------------------------------------------------------- 664 //-----------------------------------------------------------------------
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
887 887
888 /** 888 /**
889 * If this is a &gt;&gt;&gt; substitution, use ruleToUse to fill in 889 * If this is a &gt;&gt;&gt; substitution, use ruleToUse to fill in
890 * the substitution. Otherwise, just use the superclass function. 890 * the substitution. Otherwise, just use the superclass function.
891 * @param number The number being formatted 891 * @param number The number being formatted
892 * @toInsertInto The string to insert the result of this substitution 892 * @toInsertInto The string to insert the result of this substitution
893 * into 893 * into
894 * @param pos The position of the rule text in toInsertInto 894 * @param pos The position of the rule text in toInsertInto
895 */ 895 */
896 void 896 void
897 ModulusSubstitution::doSubstitution(int64_t number, UnicodeString& toInsertInto, int32_t _pos) const 897 ModulusSubstitution::doSubstitution(int64_t number, UnicodeString& toInsertInto, int32_t _pos, UErrorCode& status) const
898 { 898 {
899 // if this isn't a >>> substitution, just use the inherited version 899 // if this isn't a >>> substitution, just use the inherited version
900 // of this function (which uses either a rule set or a DecimalFormat 900 // of this function (which uses either a rule set or a DecimalFormat
901 // to format its substitution value) 901 // to format its substitution value)
902 if (ruleToUse == NULL) { 902 if (ruleToUse == NULL) {
903 NFSubstitution::doSubstitution(number, toInsertInto, _pos); 903 NFSubstitution::doSubstitution(number, toInsertInto, _pos, status);
904 904
905 // a >>> substitution goes straight to a particular rule to 905 // a >>> substitution goes straight to a particular rule to
906 // format the substitution value 906 // format the substitution value
907 } else { 907 } else {
908 int64_t numberToFormat = transformNumber(number); 908 int64_t numberToFormat = transformNumber(number);
909 ruleToUse->doFormat(numberToFormat, toInsertInto, _pos + getPos()); 909 ruleToUse->doFormat(numberToFormat, toInsertInto, _pos + getPos(), statu s);
910 } 910 }
911 } 911 }
912 912
913 /** 913 /**
914 * If this is a &gt;&gt;&gt; substitution, use ruleToUse to fill in 914 * If this is a &gt;&gt;&gt; substitution, use ruleToUse to fill in
915 * the substitution. Otherwise, just use the superclass function. 915 * the substitution. Otherwise, just use the superclass function.
916 * @param number The number being formatted 916 * @param number The number being formatted
917 * @toInsertInto The string to insert the result of this substitution 917 * @toInsertInto The string to insert the result of this substitution
918 * into 918 * into
919 * @param pos The position of the rule text in toInsertInto 919 * @param pos The position of the rule text in toInsertInto
920 */ 920 */
921 void 921 void
922 ModulusSubstitution::doSubstitution(double number, UnicodeString& toInsertInto, int32_t _pos) const 922 ModulusSubstitution::doSubstitution(double number, UnicodeString& toInsertInto, int32_t _pos, UErrorCode& status) const
923 { 923 {
924 // if this isn't a >>> substitution, just use the inherited version 924 // if this isn't a >>> substitution, just use the inherited version
925 // of this function (which uses either a rule set or a DecimalFormat 925 // of this function (which uses either a rule set or a DecimalFormat
926 // to format its substitution value) 926 // to format its substitution value)
927 if (ruleToUse == NULL) { 927 if (ruleToUse == NULL) {
928 NFSubstitution::doSubstitution(number, toInsertInto, _pos); 928 NFSubstitution::doSubstitution(number, toInsertInto, _pos, status);
929 929
930 // a >>> substitution goes straight to a particular rule to 930 // a >>> substitution goes straight to a particular rule to
931 // format the substitution value 931 // format the substitution value
932 } else { 932 } else {
933 double numberToFormat = transformNumber(number); 933 double numberToFormat = transformNumber(number);
934 934
935 ruleToUse->doFormat(numberToFormat, toInsertInto, _pos + getPos()); 935 ruleToUse->doFormat(numberToFormat, toInsertInto, _pos + getPos(), statu s);
936 } 936 }
937 } 937 }
938 938
939 //----------------------------------------------------------------------- 939 //-----------------------------------------------------------------------
940 // parsing 940 // parsing
941 //----------------------------------------------------------------------- 941 //-----------------------------------------------------------------------
942 942
943 /** 943 /**
944 * If this is a &gt;&gt;&gt; substitution, match only against ruleToUse. 944 * If this is a &gt;&gt;&gt; substitution, match only against ruleToUse.
945 * Otherwise, use the superclass function. 945 * Otherwise, use the superclass function.
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
1050 * If in "by digits" mode, fills in the substitution one decimal digit 1050 * If in "by digits" mode, fills in the substitution one decimal digit
1051 * at a time using the rule set containing this substitution. 1051 * at a time using the rule set containing this substitution.
1052 * Otherwise, uses the superclass function. 1052 * Otherwise, uses the superclass function.
1053 * @param number The number being formatted 1053 * @param number The number being formatted
1054 * @param toInsertInto The string to insert the result of formatting 1054 * @param toInsertInto The string to insert the result of formatting
1055 * the substitution into 1055 * the substitution into
1056 * @param pos The position of the owning rule's rule text in 1056 * @param pos The position of the owning rule's rule text in
1057 * toInsertInto 1057 * toInsertInto
1058 */ 1058 */
1059 void 1059 void
1060 FractionalPartSubstitution::doSubstitution(double number, UnicodeString& toInser tInto, int32_t _pos) const 1060 FractionalPartSubstitution::doSubstitution(double number, UnicodeString& toInser tInto,
1061 int32_t _pos, UErrorCode& status) con st
1061 { 1062 {
1062 // if we're not in "byDigits" mode, just use the inherited 1063 // if we're not in "byDigits" mode, just use the inherited
1063 // doSubstitution() routine 1064 // doSubstitution() routine
1064 if (!byDigits) { 1065 if (!byDigits) {
1065 NFSubstitution::doSubstitution(number, toInsertInto, _pos); 1066 NFSubstitution::doSubstitution(number, toInsertInto, _pos, status);
1066 1067
1067 // if we're in "byDigits" mode, transform the value into an integer 1068 // if we're in "byDigits" mode, transform the value into an integer
1068 // by moving the decimal point eight places to the right and 1069 // by moving the decimal point eight places to the right and
1069 // pulling digits off the right one at a time, formatting each digit 1070 // pulling digits off the right one at a time, formatting each digit
1070 // as an integer using this substitution's owning rule set 1071 // as an integer using this substitution's owning rule set
1071 // (this is slower, but more accurate, than doing it from the 1072 // (this is slower, but more accurate, than doing it from the
1072 // other end) 1073 // other end)
1073 } else { 1074 } else {
1074 // int32_t numberToFormat = (int32_t)uprv_round(transformNumber(num ber) * uprv_pow(10, kMaxDecimalDigits)); 1075 // int32_t numberToFormat = (int32_t)uprv_round(transformNumber(num ber) * uprv_pow(10, kMaxDecimalDigits));
1075 // // this flag keeps us from formatting trailing zeros. It starts 1076 // // this flag keeps us from formatting trailing zeros. It starts
(...skipping 21 matching lines...) Expand all
1097 for (int32_t didx = dl.getCount()-1; didx>=dl.getDecimalAt(); didx--) { 1098 for (int32_t didx = dl.getCount()-1; didx>=dl.getDecimalAt(); didx--) {
1098 // Loop iterates over fraction digits, starting with the LSD. 1099 // Loop iterates over fraction digits, starting with the LSD.
1099 // include both real digits from the number, and zeros 1100 // include both real digits from the number, and zeros
1100 // to the left of the MSD but to the right of the decimal point. 1101 // to the left of the MSD but to the right of the decimal point.
1101 if (pad && useSpaces) { 1102 if (pad && useSpaces) {
1102 toInsertInto.insert(_pos + getPos(), gSpace); 1103 toInsertInto.insert(_pos + getPos(), gSpace);
1103 } else { 1104 } else {
1104 pad = TRUE; 1105 pad = TRUE;
1105 } 1106 }
1106 int64_t digit = didx>=0 ? dl.getDigit(didx) - '0' : 0; 1107 int64_t digit = didx>=0 ? dl.getDigit(didx) - '0' : 0;
1107 getRuleSet()->format(digit, toInsertInto, _pos + getPos()); 1108 getRuleSet()->format(digit, toInsertInto, _pos + getPos(), status);
1108 } 1109 }
1109 1110
1110 if (!pad) { 1111 if (!pad) {
1111 // hack around lack of precision in digitlist. if we would end up with 1112 // hack around lack of precision in digitlist. if we would end up with
1112 // "foo point" make sure we add a " zero" to the end. 1113 // "foo point" make sure we add a " zero" to the end.
1113 getRuleSet()->format((int64_t)0, toInsertInto, _pos + getPos()); 1114 getRuleSet()->format((int64_t)0, toInsertInto, _pos + getPos(), status);
1114 } 1115 }
1115 } 1116 }
1116 } 1117 }
1117 1118
1118 //----------------------------------------------------------------------- 1119 //-----------------------------------------------------------------------
1119 // parsing 1120 // parsing
1120 //----------------------------------------------------------------------- 1121 //-----------------------------------------------------------------------
1121 1122
1122 /** 1123 /**
1123 * If in "by digits" mode, parses the string as if it were a string 1124 * If in "by digits" mode, parses the string as if it were a string
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
1222 // AbsoluteValueSubstitution 1223 // AbsoluteValueSubstitution
1223 //=================================================================== 1224 //===================================================================
1224 1225
1225 UOBJECT_DEFINE_RTTI_IMPLEMENTATION(AbsoluteValueSubstitution) 1226 UOBJECT_DEFINE_RTTI_IMPLEMENTATION(AbsoluteValueSubstitution)
1226 1227
1227 //=================================================================== 1228 //===================================================================
1228 // NumeratorSubstitution 1229 // NumeratorSubstitution
1229 //=================================================================== 1230 //===================================================================
1230 1231
1231 void 1232 void
1232 NumeratorSubstitution::doSubstitution(double number, UnicodeString& toInsertInto , int32_t apos) const { 1233 NumeratorSubstitution::doSubstitution(double number, UnicodeString& toInsertInto , int32_t apos, UErrorCode& status) const {
1233 // perform a transformation on the number being formatted that 1234 // perform a transformation on the number being formatted that
1234 // is dependent on the type of substitution this is 1235 // is dependent on the type of substitution this is
1235 1236
1236 double numberToFormat = transformNumber(number); 1237 double numberToFormat = transformNumber(number);
1237 int64_t longNF = util64_fromDouble(numberToFormat); 1238 int64_t longNF = util64_fromDouble(numberToFormat);
1238 1239
1239 const NFRuleSet* aruleSet = getRuleSet(); 1240 const NFRuleSet* aruleSet = getRuleSet();
1240 if (withZeros && aruleSet != NULL) { 1241 if (withZeros && aruleSet != NULL) {
1241 // if there are leading zeros in the decimal expansion then emit them 1242 // if there are leading zeros in the decimal expansion then emit them
1242 int64_t nf =longNF; 1243 int64_t nf =longNF;
1243 int32_t len = toInsertInto.length(); 1244 int32_t len = toInsertInto.length();
1244 while ((nf *= 10) < denominator) { 1245 while ((nf *= 10) < denominator) {
1245 toInsertInto.insert(apos + getPos(), gSpace); 1246 toInsertInto.insert(apos + getPos(), gSpace);
1246 aruleSet->format((int64_t)0, toInsertInto, apos + getPos()); 1247 aruleSet->format((int64_t)0, toInsertInto, apos + getPos(), status);
1247 } 1248 }
1248 apos += toInsertInto.length() - len; 1249 apos += toInsertInto.length() - len;
1249 } 1250 }
1250 1251
1251 // if the result is an integer, from here on out we work in integer 1252 // if the result is an integer, from here on out we work in integer
1252 // space (saving time and memory and preserving accuracy) 1253 // space (saving time and memory and preserving accuracy)
1253 if (numberToFormat == longNF && aruleSet != NULL) { 1254 if (numberToFormat == longNF && aruleSet != NULL) {
1254 aruleSet->format(longNF, toInsertInto, apos + getPos()); 1255 aruleSet->format(longNF, toInsertInto, apos + getPos(), status);
1255 1256
1256 // if the result isn't an integer, then call either our rule set's 1257 // if the result isn't an integer, then call either our rule set's
1257 // format() method or our DecimalFormat's format() method to 1258 // format() method or our DecimalFormat's format() method to
1258 // format the result 1259 // format the result
1259 } else { 1260 } else {
1260 if (aruleSet != NULL) { 1261 if (aruleSet != NULL) {
1261 aruleSet->format(numberToFormat, toInsertInto, apos + getPos()); 1262 aruleSet->format(numberToFormat, toInsertInto, apos + getPos(), stat us);
1262 } else { 1263 } else {
1263 UErrorCode status = U_ZERO_ERROR;
1264 UnicodeString temp; 1264 UnicodeString temp;
1265 getNumberFormat()->format(numberToFormat, temp, status); 1265 getNumberFormat()->format(numberToFormat, temp, status);
1266 toInsertInto.insert(apos + getPos(), temp); 1266 toInsertInto.insert(apos + getPos(), temp);
1267 } 1267 }
1268 } 1268 }
1269 } 1269 }
1270 1270
1271 UBool 1271 UBool
1272 NumeratorSubstitution::doParse(const UnicodeString& text, 1272 NumeratorSubstitution::doParse(const UnicodeString& text,
1273 ParsePosition& parsePosition, 1273 ParsePosition& parsePosition,
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
1355 // NullSubstitution 1355 // NullSubstitution
1356 //=================================================================== 1356 //===================================================================
1357 1357
1358 UOBJECT_DEFINE_RTTI_IMPLEMENTATION(NullSubstitution) 1358 UOBJECT_DEFINE_RTTI_IMPLEMENTATION(NullSubstitution)
1359 1359
1360 U_NAMESPACE_END 1360 U_NAMESPACE_END
1361 1361
1362 /* U_HAVE_RBNF */ 1362 /* U_HAVE_RBNF */
1363 #endif 1363 #endif
1364 1364
OLDNEW
« no previous file with comments | « source/i18n/nfsubs.h ('k') | source/i18n/numfmt.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698