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

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

Issue 1621843002: ICU 56 update step 1 (Closed) Base URL: https://chromium.googlesource.com/chromium/deps/icu.git@561
Patch Set: Created 4 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/pluralaffix.cpp ('k') | source/i18n/plurrule.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) 2009-2014, International Business Machines Corporation and 3 * Copyright (C) 2009-2015, International Business Machines Corporation and
4 * others. All Rights Reserved. 4 * others. All Rights Reserved.
5 ******************************************************************************* 5 *******************************************************************************
6 * 6 *
7 * File PLURFMT.CPP 7 * File PLURFMT.CPP
8 ******************************************************************************* 8 *******************************************************************************
9 */ 9 */
10 10
11 #include "unicode/decimfmt.h" 11 #include "unicode/decimfmt.h"
12 #include "unicode/messagepattern.h" 12 #include "unicode/messagepattern.h"
13 #include "unicode/plurfmt.h" 13 #include "unicode/plurfmt.h"
14 #include "unicode/plurrule.h" 14 #include "unicode/plurrule.h"
15 #include "unicode/utypes.h" 15 #include "unicode/utypes.h"
16 #include "cmemory.h" 16 #include "cmemory.h"
17 #include "messageimpl.h" 17 #include "messageimpl.h"
18 #include "nfrule.h" 18 #include "nfrule.h"
19 #include "plurrule_impl.h" 19 #include "plurrule_impl.h"
20 #include "uassert.h" 20 #include "uassert.h"
21 #include "uhash.h" 21 #include "uhash.h"
22 #include "precision.h"
23 #include "visibledigits.h"
22 24
23 #if !UCONFIG_NO_FORMATTING 25 #if !UCONFIG_NO_FORMATTING
24 26
25 U_NAMESPACE_BEGIN 27 U_NAMESPACE_BEGIN
26 28
27 static const UChar OTHER_STRING[] = { 29 static const UChar OTHER_STRING[] = {
28 0x6F, 0x74, 0x68, 0x65, 0x72, 0 // "other" 30 0x6F, 0x74, 0x68, 0x65, 0x72, 0 // "other"
29 }; 31 };
30 32
31 UOBJECT_DEFINE_RTTI_IMPLEMENTATION(PluralFormat) 33 UOBJECT_DEFINE_RTTI_IMPLEMENTATION(PluralFormat)
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 return appendTo; 254 return appendTo;
253 } 255 }
254 if (msgPattern.countParts() == 0) { 256 if (msgPattern.countParts() == 0) {
255 return numberFormat->format(numberObject, appendTo, pos, status); 257 return numberFormat->format(numberObject, appendTo, pos, status);
256 } 258 }
257 // Get the appropriate sub-message. 259 // Get the appropriate sub-message.
258 // Select it based on the formatted number-offset. 260 // Select it based on the formatted number-offset.
259 double numberMinusOffset = number - offset; 261 double numberMinusOffset = number - offset;
260 UnicodeString numberString; 262 UnicodeString numberString;
261 FieldPosition ignorePos; 263 FieldPosition ignorePos;
262 FixedDecimal dec(numberMinusOffset); 264 FixedPrecision fp;
265 VisibleDigitsWithExponent dec;
266 fp.initVisibleDigitsWithExponent(numberMinusOffset, dec, status);
267 if (U_FAILURE(status)) {
268 return appendTo;
269 }
263 if (offset == 0) { 270 if (offset == 0) {
264 numberFormat->format(numberObject, numberString, ignorePos, status); // could be BigDecimal etc.
265 DecimalFormat *decFmt = dynamic_cast<DecimalFormat *>(numberFormat); 271 DecimalFormat *decFmt = dynamic_cast<DecimalFormat *>(numberFormat);
266 if(decFmt != NULL) { 272 if(decFmt != NULL) {
267 dec = decFmt->getFixedDecimal(numberObject, status); 273 decFmt->initVisibleDigitsWithExponent(
274 numberObject, dec, status);
275 if (U_FAILURE(status)) {
276 return appendTo;
277 }
278 decFmt->format(dec, numberString, ignorePos, status);
279 } else {
280 numberFormat->format(
281 numberObject, numberString, ignorePos, status); // could be BigDecimal etc.
268 } 282 }
269 } else { 283 } else {
270 numberFormat->format(numberMinusOffset, numberString, ignorePos, status) ;
271 DecimalFormat *decFmt = dynamic_cast<DecimalFormat *>(numberFormat); 284 DecimalFormat *decFmt = dynamic_cast<DecimalFormat *>(numberFormat);
272 if(decFmt != NULL) { 285 if(decFmt != NULL) {
273 dec = decFmt->getFixedDecimal(numberMinusOffset, status); 286 decFmt->initVisibleDigitsWithExponent(
287 numberMinusOffset, dec, status);
288 if (U_FAILURE(status)) {
289 return appendTo;
290 }
291 decFmt->format(dec, numberString, ignorePos, status);
292 } else {
293 numberFormat->format(
294 numberMinusOffset, numberString, ignorePos, status);
274 } 295 }
275 } 296 }
276 int32_t partIndex = findSubMessage(msgPattern, 0, pluralRulesWrapper, &dec, number, status); 297 int32_t partIndex = findSubMessage(msgPattern, 0, pluralRulesWrapper, &dec, number, status);
277 if (U_FAILURE(status)) { return appendTo; } 298 if (U_FAILURE(status)) { return appendTo; }
278 // Replace syntactic # signs in the top level of this sub-message 299 // Replace syntactic # signs in the top level of this sub-message
279 // (not in nested arguments) with the formatted number-offset. 300 // (not in nested arguments) with the formatted number-offset.
280 const UnicodeString& pattern = msgPattern.getPatternString(); 301 const UnicodeString& pattern = msgPattern.getPatternString();
281 int32_t prevIndex = msgPattern.getPart(partIndex).getLimit(); 302 int32_t prevIndex = msgPattern.getPart(partIndex).getLimit();
282 for (;;) { 303 for (;;) {
283 const MessagePattern::Part& part = msgPattern.getPart(++partIndex); 304 const MessagePattern::Part& part = msgPattern.getPart(++partIndex);
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after
526 continue; 547 continue;
527 } 548 }
528 549
529 UnicodeString currArg = pattern.tempSubString(partStart->getLimit(), par tLimit->getIndex() - partStart->getLimit()); 550 UnicodeString currArg = pattern.tempSubString(partStart->getLimit(), par tLimit->getIndex() - partStart->getLimit());
530 if (rbnfLenientScanner != NULL) { 551 if (rbnfLenientScanner != NULL) {
531 // If lenient parsing is turned ON, we've got some time consuming pa rsing ahead of us. 552 // If lenient parsing is turned ON, we've got some time consuming pa rsing ahead of us.
532 int32_t length = -1; 553 int32_t length = -1;
533 currMatchIndex = rbnfLenientScanner->findTextLenient(source, currArg , startingAt, &length); 554 currMatchIndex = rbnfLenientScanner->findTextLenient(source, currArg , startingAt, &length);
534 } 555 }
535 else { 556 else {
536 currMatchIndex = source.indexOf(currArg); 557 currMatchIndex = source.indexOf(currArg, startingAt);
537 } 558 }
538 if (currMatchIndex >= 0 && currMatchIndex >= matchedIndex && currArg.len gth() > matchedWord.length()) { 559 if (currMatchIndex >= 0 && currMatchIndex >= matchedIndex && currArg.len gth() > matchedWord.length()) {
539 matchedIndex = currMatchIndex; 560 matchedIndex = currMatchIndex;
540 matchedWord = currArg; 561 matchedWord = currArg;
541 keyword = pattern.tempSubString(partStart->getLimit(), partLimit->ge tIndex() - partStart->getLimit()); 562 keyword = pattern.tempSubString(partStart->getLimit(), partLimit->ge tIndex() - partStart->getLimit());
542 } 563 }
543 } 564 }
544 if (matchedIndex >= 0) { 565 if (matchedIndex >= 0) {
545 pos.setBeginIndex(matchedIndex); 566 pos.setBeginIndex(matchedIndex);
546 pos.setEndIndex(matchedIndex + matchedWord.length()); 567 pos.setEndIndex(matchedIndex + matchedWord.length());
547 result.setString(keyword); 568 result.setString(keyword);
548 return; 569 return;
549 } 570 }
550 571
551 // Not found! 572 // Not found!
552 pos.setBeginIndex(-1); 573 pos.setBeginIndex(-1);
553 pos.setEndIndex(-1); 574 pos.setEndIndex(-1);
554 } 575 }
555 576
556 PluralFormat::PluralSelector::~PluralSelector() {} 577 PluralFormat::PluralSelector::~PluralSelector() {}
557 578
558 PluralFormat::PluralSelectorAdapter::~PluralSelectorAdapter() { 579 PluralFormat::PluralSelectorAdapter::~PluralSelectorAdapter() {
559 delete pluralRules; 580 delete pluralRules;
560 } 581 }
561 582
562 UnicodeString PluralFormat::PluralSelectorAdapter::select(void *context, double number, 583 UnicodeString PluralFormat::PluralSelectorAdapter::select(void *context, double number,
563 UErrorCode& /*ec*/) co nst { 584 UErrorCode& /*ec*/) co nst {
564 (void)number; // unused except in the assertion 585 (void)number; // unused except in the assertion
565 FixedDecimal *dec=static_cast<FixedDecimal *>(context); 586 VisibleDigitsWithExponent *dec=static_cast<VisibleDigitsWithExponent *>(cont ext);
566 U_ASSERT(dec->source==number);
567 return pluralRules->select(*dec); 587 return pluralRules->select(*dec);
568 } 588 }
569 589
570 void PluralFormat::PluralSelectorAdapter::reset() { 590 void PluralFormat::PluralSelectorAdapter::reset() {
571 delete pluralRules; 591 delete pluralRules;
572 pluralRules = NULL; 592 pluralRules = NULL;
573 } 593 }
574 594
575 595
576 U_NAMESPACE_END 596 U_NAMESPACE_END
577 597
578 598
579 #endif /* #if !UCONFIG_NO_FORMATTING */ 599 #endif /* #if !UCONFIG_NO_FORMATTING */
580 600
581 //eof 601 //eof
OLDNEW
« no previous file with comments | « source/i18n/pluralaffix.cpp ('k') | source/i18n/plurrule.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698