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

Side by Side Diff: source/i18n/msgfmt.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/measunit.cpp ('k') | source/i18n/nfrs.h » ('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 * COPYRIGHT: 2 * COPYRIGHT:
3 * Copyright (c) 1997-2014, International Business Machines Corporation and 3 * Copyright (c) 1997-2015, International Business Machines Corporation and
4 * others. All Rights Reserved. 4 * others. All Rights Reserved.
5 ******************************************************************** 5 ********************************************************************
6 * 6 *
7 * File MSGFMT.CPP 7 * File MSGFMT.CPP
8 * 8 *
9 * Modification History: 9 * Modification History:
10 * 10 *
11 * Date Name Description 11 * Date Name Description
12 * 02/19/97 aliu Converted from java. 12 * 02/19/97 aliu Converted from java.
13 * 03/20/97 helena Finished first cut of implementation. 13 * 03/20/97 helena Finished first cut of implementation.
(...skipping 25 matching lines...) Expand all
39 #include "patternprops.h" 39 #include "patternprops.h"
40 #include "messageimpl.h" 40 #include "messageimpl.h"
41 #include "msgfmt_impl.h" 41 #include "msgfmt_impl.h"
42 #include "plurrule_impl.h" 42 #include "plurrule_impl.h"
43 #include "uassert.h" 43 #include "uassert.h"
44 #include "uelement.h" 44 #include "uelement.h"
45 #include "uhash.h" 45 #include "uhash.h"
46 #include "ustrfmt.h" 46 #include "ustrfmt.h"
47 #include "util.h" 47 #include "util.h"
48 #include "uvector.h" 48 #include "uvector.h"
49 #include "visibledigits.h"
49 50
50 // ***************************************************************************** 51 // *****************************************************************************
51 // class MessageFormat 52 // class MessageFormat
52 // ***************************************************************************** 53 // *****************************************************************************
53 54
54 #define SINGLE_QUOTE ((UChar)0x0027) 55 #define SINGLE_QUOTE ((UChar)0x0027)
55 #define COMMA ((UChar)0x002C) 56 #define COMMA ((UChar)0x002C)
56 #define LEFT_CURLY_BRACE ((UChar)0x007B) 57 #define LEFT_CURLY_BRACE ((UChar)0x007B)
57 #define RIGHT_CURLY_BRACE ((UChar)0x007D) 58 #define RIGHT_CURLY_BRACE ((UChar)0x007D)
58 59
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after
406 if (customFormatArgStarts == NULL) { 407 if (customFormatArgStarts == NULL) {
407 return TRUE; 408 return TRUE;
408 } 409 }
409 410
410 UErrorCode ec = U_ZERO_ERROR; 411 UErrorCode ec = U_ZERO_ERROR;
411 const int32_t count = uhash_count(customFormatArgStarts); 412 const int32_t count = uhash_count(customFormatArgStarts);
412 const int32_t rhs_count = uhash_count(that.customFormatArgStarts); 413 const int32_t rhs_count = uhash_count(that.customFormatArgStarts);
413 if (count != rhs_count) { 414 if (count != rhs_count) {
414 return FALSE; 415 return FALSE;
415 } 416 }
416 int32_t idx = 0, rhs_idx = 0, pos = -1, rhs_pos = -1; 417 int32_t idx = 0, rhs_idx = 0, pos = UHASH_FIRST, rhs_pos = UHASH_FIRST;
417 for (; idx < count && rhs_idx < rhs_count && U_SUCCESS(ec); ++idx, ++rhs_idx ) { 418 for (; idx < count && rhs_idx < rhs_count && U_SUCCESS(ec); ++idx, ++rhs_idx ) {
418 const UHashElement* cur = uhash_nextElement(customFormatArgStarts, &pos) ; 419 const UHashElement* cur = uhash_nextElement(customFormatArgStarts, &pos) ;
419 const UHashElement* rhs_cur = uhash_nextElement(that.customFormatArgStar ts, &rhs_pos); 420 const UHashElement* rhs_cur = uhash_nextElement(that.customFormatArgStar ts, &rhs_pos);
420 if (cur->key.integer != rhs_cur->key.integer) { 421 if (cur->key.integer != rhs_cur->key.integer) {
421 return FALSE; 422 return FALSE;
422 } 423 }
423 const Format* format = (const Format*)uhash_iget(cachedFormatters, cur-> key.integer); 424 const Format* format = (const Format*)uhash_iget(cachedFormatters, cur-> key.integer);
424 const Format* rhs_format = (const Format*)uhash_iget(that.cachedFormatte rs, rhs_cur->key.integer); 425 const Format* rhs_format = (const Format*)uhash_iget(that.cachedFormatte rs, rhs_cur->key.integer);
425 if (*format != *rhs_format) { 426 if (*format != *rhs_format) {
426 return FALSE; 427 return FALSE;
(...skipping 898 matching lines...) Expand 10 before | Expand all | Expand 10 after
1325 cachedFormatters=uhash_open(uhash_hashLong, uhash_compareLong, 1326 cachedFormatters=uhash_open(uhash_hashLong, uhash_compareLong,
1326 equalFormatsForHash, &ec); 1327 equalFormatsForHash, &ec);
1327 if (U_FAILURE(ec)) { 1328 if (U_FAILURE(ec)) {
1328 return; 1329 return;
1329 } 1330 }
1330 uhash_setValueDeleter(cachedFormatters, uprv_deleteUObject); 1331 uhash_setValueDeleter(cachedFormatters, uprv_deleteUObject);
1331 } 1332 }
1332 1333
1333 const int32_t count = uhash_count(that.cachedFormatters); 1334 const int32_t count = uhash_count(that.cachedFormatters);
1334 int32_t pos, idx; 1335 int32_t pos, idx;
1335 for (idx = 0, pos = -1; idx < count && U_SUCCESS(ec); ++idx) { 1336 for (idx = 0, pos = UHASH_FIRST; idx < count && U_SUCCESS(ec); ++idx) {
1336 const UHashElement* cur = uhash_nextElement(that.cachedFormatters, & pos); 1337 const UHashElement* cur = uhash_nextElement(that.cachedFormatters, & pos);
1337 Format* newFormat = ((Format*)(cur->value.pointer))->clone(); 1338 Format* newFormat = ((Format*)(cur->value.pointer))->clone();
1338 if (newFormat) { 1339 if (newFormat) {
1339 uhash_iput(cachedFormatters, cur->key.integer, newFormat, &ec); 1340 uhash_iput(cachedFormatters, cur->key.integer, newFormat, &ec);
1340 } else { 1341 } else {
1341 ec = U_MEMORY_ALLOCATION_ERROR; 1342 ec = U_MEMORY_ALLOCATION_ERROR;
1342 return; 1343 return;
1343 } 1344 }
1344 } 1345 }
1345 } 1346 }
1346 if (that.customFormatArgStarts) { 1347 if (that.customFormatArgStarts) {
1347 if (customFormatArgStarts == NULL) { 1348 if (customFormatArgStarts == NULL) {
1348 customFormatArgStarts=uhash_open(uhash_hashLong, uhash_compareLong, 1349 customFormatArgStarts=uhash_open(uhash_hashLong, uhash_compareLong,
1349 NULL, &ec); 1350 NULL, &ec);
1350 } 1351 }
1351 const int32_t count = uhash_count(that.customFormatArgStarts); 1352 const int32_t count = uhash_count(that.customFormatArgStarts);
1352 int32_t pos, idx; 1353 int32_t pos, idx;
1353 for (idx = 0, pos = -1; idx < count && U_SUCCESS(ec); ++idx) { 1354 for (idx = 0, pos = UHASH_FIRST; idx < count && U_SUCCESS(ec); ++idx) {
1354 const UHashElement* cur = uhash_nextElement(that.customFormatArgStar ts, &pos); 1355 const UHashElement* cur = uhash_nextElement(that.customFormatArgStar ts, &pos);
1355 uhash_iputi(customFormatArgStarts, cur->key.integer, cur->value.inte ger, &ec); 1356 uhash_iputi(customFormatArgStarts, cur->key.integer, cur->value.inte ger, &ec);
1356 } 1357 }
1357 } 1358 }
1358 } 1359 }
1359 1360
1360 1361
1361 Formattable* 1362 Formattable*
1362 MessageFormat::parse(int32_t msgStart, 1363 MessageFormat::parse(int32_t msgStart,
1363 const UnicodeString& source, 1364 const UnicodeString& source,
(...skipping 584 matching lines...) Expand 10 before | Expand all | Expand 10 after
1948 (const Format*)uhash_iget(msgFormat.cachedFormatters, context.number ArgIndex); 1949 (const Format*)uhash_iget(msgFormat.cachedFormatters, context.number ArgIndex);
1949 } 1950 }
1950 if(context.formatter == NULL) { 1951 if(context.formatter == NULL) {
1951 context.formatter = msgFormat.getDefaultNumberFormat(ec); 1952 context.formatter = msgFormat.getDefaultNumberFormat(ec);
1952 context.forReplaceNumber = TRUE; 1953 context.forReplaceNumber = TRUE;
1953 } 1954 }
1954 U_ASSERT(context.number.getDouble(ec) == number); // argument number minus the offset 1955 U_ASSERT(context.number.getDouble(ec) == number); // argument number minus the offset
1955 context.formatter->format(context.number, context.numberString, ec); 1956 context.formatter->format(context.number, context.numberString, ec);
1956 const DecimalFormat *decFmt = dynamic_cast<const DecimalFormat *>(context.fo rmatter); 1957 const DecimalFormat *decFmt = dynamic_cast<const DecimalFormat *>(context.fo rmatter);
1957 if(decFmt != NULL) { 1958 if(decFmt != NULL) {
1958 FixedDecimal dec = decFmt->getFixedDecimal(context.number, ec); 1959 VisibleDigitsWithExponent digits;
1959 return rules->select(dec); 1960 decFmt->initVisibleDigitsWithExponent(context.number, digits, ec);
1961 if (U_FAILURE(ec)) {
1962 return UnicodeString(FALSE, OTHER_STRING, 5);
1963 }
1964 return rules->select(digits);
1960 } else { 1965 } else {
1961 return rules->select(number); 1966 return rules->select(number);
1962 } 1967 }
1963 } 1968 }
1964 1969
1965 void MessageFormat::PluralSelectorProvider::reset() { 1970 void MessageFormat::PluralSelectorProvider::reset() {
1966 delete rules; 1971 delete rules;
1967 rules = NULL; 1972 rules = NULL;
1968 } 1973 }
1969 1974
1970 1975
1971 U_NAMESPACE_END 1976 U_NAMESPACE_END
1972 1977
1973 #endif /* #if !UCONFIG_NO_FORMATTING */ 1978 #endif /* #if !UCONFIG_NO_FORMATTING */
1974 1979
1975 //eof 1980 //eof
OLDNEW
« no previous file with comments | « source/i18n/measunit.cpp ('k') | source/i18n/nfrs.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698