| OLD | NEW |
| 1 /******************************************************************** | 1 /******************************************************************** |
| 2 * COPYRIGHT: | 2 * COPYRIGHT: |
| 3 * Copyright (c) 1997-2010, International Business Machines Corporation and | 3 * Copyright (c) 1997-2010, 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 * |
| (...skipping 711 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 722 } | 722 } |
| 723 Format* fmt = subformats[i].format; | 723 Format* fmt = subformats[i].format; |
| 724 DecimalFormat* decfmt; | 724 DecimalFormat* decfmt; |
| 725 SimpleDateFormat* sdtfmt; | 725 SimpleDateFormat* sdtfmt; |
| 726 ChoiceFormat* chcfmt; | 726 ChoiceFormat* chcfmt; |
| 727 PluralFormat* plfmt; | 727 PluralFormat* plfmt; |
| 728 SelectFormat* selfmt; | 728 SelectFormat* selfmt; |
| 729 if (fmt == NULL) { | 729 if (fmt == NULL) { |
| 730 // do nothing, string format | 730 // do nothing, string format |
| 731 } | 731 } |
| 732 else if ((decfmt = dynamic_cast<DecimalFormat*>(fmt)) != NULL) { | 732 else if ((decfmt = CR_DYNAMIC_CAST<DecimalFormat*>(fmt)) != NULL) { |
| 733 UErrorCode ec = U_ZERO_ERROR; | 733 UErrorCode ec = U_ZERO_ERROR; |
| 734 NumberFormat& formatAlias = *decfmt; | 734 NumberFormat& formatAlias = *decfmt; |
| 735 NumberFormat *defaultTemplate = NumberFormat::createInstance(fLocale
, ec); | 735 NumberFormat *defaultTemplate = NumberFormat::createInstance(fLocale
, ec); |
| 736 NumberFormat *currencyTemplate = NumberFormat::createCurrencyInstanc
e(fLocale, ec); | 736 NumberFormat *currencyTemplate = NumberFormat::createCurrencyInstanc
e(fLocale, ec); |
| 737 NumberFormat *percentTemplate = NumberFormat::createPercentInstance(
fLocale, ec); | 737 NumberFormat *percentTemplate = NumberFormat::createPercentInstance(
fLocale, ec); |
| 738 NumberFormat *integerTemplate = createIntegerFormat(fLocale, ec); | 738 NumberFormat *integerTemplate = createIntegerFormat(fLocale, ec); |
| 739 | 739 |
| 740 appendTo += COMMA; | 740 appendTo += COMMA; |
| 741 appendTo += ID_NUMBER; | 741 appendTo += ID_NUMBER; |
| 742 if (formatAlias != *defaultTemplate) { | 742 if (formatAlias != *defaultTemplate) { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 754 UnicodeString buffer; | 754 UnicodeString buffer; |
| 755 appendTo += decfmt->toPattern(buffer); | 755 appendTo += decfmt->toPattern(buffer); |
| 756 } | 756 } |
| 757 } | 757 } |
| 758 | 758 |
| 759 delete defaultTemplate; | 759 delete defaultTemplate; |
| 760 delete currencyTemplate; | 760 delete currencyTemplate; |
| 761 delete percentTemplate; | 761 delete percentTemplate; |
| 762 delete integerTemplate; | 762 delete integerTemplate; |
| 763 } | 763 } |
| 764 else if ((sdtfmt = dynamic_cast<SimpleDateFormat*>(fmt)) != NULL) { | 764 else if ((sdtfmt = CR_DYNAMIC_CAST<SimpleDateFormat*>(fmt)) != NULL) { |
| 765 DateFormat& formatAlias = *sdtfmt; | 765 DateFormat& formatAlias = *sdtfmt; |
| 766 DateFormat *defaultDateTemplate = DateFormat::createDateInstance(Dat
eFormat::kDefault, fLocale); | 766 DateFormat *defaultDateTemplate = DateFormat::createDateInstance(Dat
eFormat::kDefault, fLocale); |
| 767 DateFormat *shortDateTemplate = DateFormat::createDateInstance(DateF
ormat::kShort, fLocale); | 767 DateFormat *shortDateTemplate = DateFormat::createDateInstance(DateF
ormat::kShort, fLocale); |
| 768 DateFormat *longDateTemplate = DateFormat::createDateInstance(DateFo
rmat::kLong, fLocale); | 768 DateFormat *longDateTemplate = DateFormat::createDateInstance(DateFo
rmat::kLong, fLocale); |
| 769 DateFormat *fullDateTemplate = DateFormat::createDateInstance(DateFo
rmat::kFull, fLocale); | 769 DateFormat *fullDateTemplate = DateFormat::createDateInstance(DateFo
rmat::kFull, fLocale); |
| 770 DateFormat *defaultTimeTemplate = DateFormat::createTimeInstance(Dat
eFormat::kDefault, fLocale); | 770 DateFormat *defaultTimeTemplate = DateFormat::createTimeInstance(Dat
eFormat::kDefault, fLocale); |
| 771 DateFormat *shortTimeTemplate = DateFormat::createTimeInstance(DateF
ormat::kShort, fLocale); | 771 DateFormat *shortTimeTemplate = DateFormat::createTimeInstance(DateF
ormat::kShort, fLocale); |
| 772 DateFormat *longTimeTemplate = DateFormat::createTimeInstance(DateFo
rmat::kLong, fLocale); | 772 DateFormat *longTimeTemplate = DateFormat::createTimeInstance(DateFo
rmat::kLong, fLocale); |
| 773 DateFormat *fullTimeTemplate = DateFormat::createTimeInstance(DateFo
rmat::kFull, fLocale); | 773 DateFormat *fullTimeTemplate = DateFormat::createTimeInstance(DateFo
rmat::kFull, fLocale); |
| 774 | 774 |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 830 delete defaultDateTemplate; | 830 delete defaultDateTemplate; |
| 831 delete shortDateTemplate; | 831 delete shortDateTemplate; |
| 832 delete longDateTemplate; | 832 delete longDateTemplate; |
| 833 delete fullDateTemplate; | 833 delete fullDateTemplate; |
| 834 delete defaultTimeTemplate; | 834 delete defaultTimeTemplate; |
| 835 delete shortTimeTemplate; | 835 delete shortTimeTemplate; |
| 836 delete longTimeTemplate; | 836 delete longTimeTemplate; |
| 837 delete fullTimeTemplate; | 837 delete fullTimeTemplate; |
| 838 // {sfb} there should be a more efficient way to do this! | 838 // {sfb} there should be a more efficient way to do this! |
| 839 } | 839 } |
| 840 else if ((chcfmt = dynamic_cast<ChoiceFormat*>(fmt)) != NULL) { | 840 else if ((chcfmt = CR_DYNAMIC_CAST<ChoiceFormat*>(fmt)) != NULL) { |
| 841 UnicodeString buffer; | 841 UnicodeString buffer; |
| 842 appendTo += COMMA; | 842 appendTo += COMMA; |
| 843 appendTo += ID_CHOICE; | 843 appendTo += ID_CHOICE; |
| 844 appendTo += COMMA; | 844 appendTo += COMMA; |
| 845 appendTo += ((ChoiceFormat*)fmt)->toPattern(buffer); | 845 appendTo += ((ChoiceFormat*)fmt)->toPattern(buffer); |
| 846 } | 846 } |
| 847 else if ((plfmt = dynamic_cast<PluralFormat*>(fmt)) != NULL) { | 847 else if ((plfmt = CR_DYNAMIC_CAST<PluralFormat*>(fmt)) != NULL) { |
| 848 UnicodeString buffer; | 848 UnicodeString buffer; |
| 849 appendTo += plfmt->toPattern(buffer); | 849 appendTo += plfmt->toPattern(buffer); |
| 850 } | 850 } |
| 851 else if ((selfmt = dynamic_cast<SelectFormat*>(fmt)) != NULL) { | 851 else if ((selfmt = CR_DYNAMIC_CAST<SelectFormat*>(fmt)) != NULL) { |
| 852 UnicodeString buffer; | 852 UnicodeString buffer; |
| 853 appendTo += ((SelectFormat*)fmt)->toPattern(buffer); | 853 appendTo += ((SelectFormat*)fmt)->toPattern(buffer); |
| 854 } | 854 } |
| 855 else { | 855 else { |
| 856 //appendTo += ", unknown"; | 856 //appendTo += ", unknown"; |
| 857 } | 857 } |
| 858 appendTo += RIGHT_CURLY_BRACE; | 858 appendTo += RIGHT_CURLY_BRACE; |
| 859 } | 859 } |
| 860 copyAndFixQuotes(fPattern, lastOffset, fPattern.length(), appendTo); | 860 copyAndFixQuotes(fPattern, lastOffset, fPattern.length(), appendTo); |
| 861 return appendTo; | 861 return appendTo; |
| (...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1239 // Recursively calling the format process only if the current | 1239 // Recursively calling the format process only if the current |
| 1240 // format argument refers to either of the following: | 1240 // format argument refers to either of the following: |
| 1241 // a ChoiceFormat object, a PluralFormat object, a SelectFormat object. | 1241 // a ChoiceFormat object, a PluralFormat object, a SelectFormat object. |
| 1242 Format* fmt = subformats[i].format; | 1242 Format* fmt = subformats[i].format; |
| 1243 if (fmt != NULL) { | 1243 if (fmt != NULL) { |
| 1244 UnicodeString argNum; | 1244 UnicodeString argNum; |
| 1245 fmt->format(*obj, argNum, success); | 1245 fmt->format(*obj, argNum, success); |
| 1246 | 1246 |
| 1247 // Needs to reprocess the ChoiceFormat and PluralFormat and SelectFo
rmat option by using the | 1247 // Needs to reprocess the ChoiceFormat and PluralFormat and SelectFo
rmat option by using the |
| 1248 // MessageFormat pattern application. | 1248 // MessageFormat pattern application. |
| 1249 if ((dynamic_cast<ChoiceFormat*>(fmt) != NULL || | 1249 if ((CR_DYNAMIC_CAST<ChoiceFormat*>(fmt) != NULL || |
| 1250 dynamic_cast<PluralFormat*>(fmt) != NULL || | 1250 CR_DYNAMIC_CAST<PluralFormat*>(fmt) != NULL || |
| 1251 dynamic_cast<SelectFormat*>(fmt) != NULL) && | 1251 CR_DYNAMIC_CAST<SelectFormat*>(fmt) != NULL) && |
| 1252 argNum.indexOf(LEFT_CURLY_BRACE) >= 0 | 1252 argNum.indexOf(LEFT_CURLY_BRACE) >= 0 |
| 1253 ) { | 1253 ) { |
| 1254 MessageFormat temp(argNum, fLocale, success); | 1254 MessageFormat temp(argNum, fLocale, success); |
| 1255 // TODO: Implement recursion protection | 1255 // TODO: Implement recursion protection |
| 1256 if ( isArgNumeric ) { | 1256 if ( isArgNumeric ) { |
| 1257 temp.format(arguments, NULL, cnt, appendTo, status, recursio
nProtection, success); | 1257 temp.format(arguments, NULL, cnt, appendTo, status, recursio
nProtection, success); |
| 1258 } | 1258 } |
| 1259 else { | 1259 else { |
| 1260 temp.format(arguments, argumentNames, cnt, appendTo, status,
recursionProtection, success); | 1260 temp.format(arguments, argumentNames, cnt, appendTo, status,
recursionProtection, success); |
| 1261 } | 1261 } |
| (...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1557 case 2: // percent | 1557 case 2: // percent |
| 1558 fmt = NumberFormat::createPercentInstance(fLocale, ec); | 1558 fmt = NumberFormat::createPercentInstance(fLocale, ec); |
| 1559 break; | 1559 break; |
| 1560 case 3: // integer | 1560 case 3: // integer |
| 1561 argType = Formattable::kLong; | 1561 argType = Formattable::kLong; |
| 1562 fmt = createIntegerFormat(fLocale, ec); | 1562 fmt = createIntegerFormat(fLocale, ec); |
| 1563 break; | 1563 break; |
| 1564 default: // pattern | 1564 default: // pattern |
| 1565 fmt = NumberFormat::createInstance(fLocale, ec); | 1565 fmt = NumberFormat::createInstance(fLocale, ec); |
| 1566 if (fmt) { | 1566 if (fmt) { |
| 1567 DecimalFormat* decfmt = dynamic_cast<DecimalFormat*>(fmt); | 1567 DecimalFormat* decfmt = CR_DYNAMIC_CAST<DecimalFormat*>(fmt); |
| 1568 if (decfmt != NULL) { | 1568 if (decfmt != NULL) { |
| 1569 decfmt->applyPattern(segments[3],parseError,ec); | 1569 decfmt->applyPattern(segments[3],parseError,ec); |
| 1570 } | 1570 } |
| 1571 } | 1571 } |
| 1572 break; | 1572 break; |
| 1573 } | 1573 } |
| 1574 break; | 1574 break; |
| 1575 | 1575 |
| 1576 case 2: // date | 1576 case 2: // date |
| 1577 case 3: // time | 1577 case 3: // time |
| 1578 argType = Formattable::kDate; | 1578 argType = Formattable::kDate; |
| 1579 styleID = findKeyword(segments[3], DATE_STYLE_IDS); | 1579 styleID = findKeyword(segments[3], DATE_STYLE_IDS); |
| 1580 style = (styleID >= 0) ? DATE_STYLES[styleID] : DateFormat::kDefault; | 1580 style = (styleID >= 0) ? DATE_STYLES[styleID] : DateFormat::kDefault; |
| 1581 | 1581 |
| 1582 if (typeID == 2) { | 1582 if (typeID == 2) { |
| 1583 fmt = DateFormat::createDateInstance(style, fLocale); | 1583 fmt = DateFormat::createDateInstance(style, fLocale); |
| 1584 } else { | 1584 } else { |
| 1585 fmt = DateFormat::createTimeInstance(style, fLocale); | 1585 fmt = DateFormat::createTimeInstance(style, fLocale); |
| 1586 } | 1586 } |
| 1587 | 1587 |
| 1588 if (styleID < 0 && fmt != NULL) { | 1588 if (styleID < 0 && fmt != NULL) { |
| 1589 SimpleDateFormat* sdtfmt = dynamic_cast<SimpleDateFormat*>(fmt); | 1589 SimpleDateFormat* sdtfmt = CR_DYNAMIC_CAST<SimpleDateFormat*>(fmt); |
| 1590 if (sdtfmt != NULL) { | 1590 if (sdtfmt != NULL) { |
| 1591 sdtfmt->applyPattern(segments[3]); | 1591 sdtfmt->applyPattern(segments[3]); |
| 1592 } | 1592 } |
| 1593 } | 1593 } |
| 1594 break; | 1594 break; |
| 1595 | 1595 |
| 1596 case 4: // choice | 1596 case 4: // choice |
| 1597 argType = Formattable::kDouble; | 1597 argType = Formattable::kDouble; |
| 1598 | 1598 |
| 1599 fmt = new ChoiceFormat(segments[3], parseError, ec); | 1599 fmt = new ChoiceFormat(segments[3], parseError, ec); |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1741 } | 1741 } |
| 1742 } | 1742 } |
| 1743 | 1743 |
| 1744 /** | 1744 /** |
| 1745 * Convenience method that ought to be in NumberFormat | 1745 * Convenience method that ought to be in NumberFormat |
| 1746 */ | 1746 */ |
| 1747 NumberFormat* | 1747 NumberFormat* |
| 1748 MessageFormat::createIntegerFormat(const Locale& locale, UErrorCode& status) con
st { | 1748 MessageFormat::createIntegerFormat(const Locale& locale, UErrorCode& status) con
st { |
| 1749 NumberFormat *temp = NumberFormat::createInstance(locale, status); | 1749 NumberFormat *temp = NumberFormat::createInstance(locale, status); |
| 1750 DecimalFormat *temp2; | 1750 DecimalFormat *temp2; |
| 1751 if (temp != NULL && (temp2 = dynamic_cast<DecimalFormat*>(temp)) != NULL) { | 1751 if (temp != NULL && (temp2 = CR_DYNAMIC_CAST<DecimalFormat*>(temp)) != NULL)
{ |
| 1752 temp2->setMaximumFractionDigits(0); | 1752 temp2->setMaximumFractionDigits(0); |
| 1753 temp2->setDecimalSeparatorAlwaysShown(FALSE); | 1753 temp2->setDecimalSeparatorAlwaysShown(FALSE); |
| 1754 temp2->setParseIntegerOnly(TRUE); | 1754 temp2->setParseIntegerOnly(TRUE); |
| 1755 } | 1755 } |
| 1756 | 1756 |
| 1757 return temp; | 1757 return temp; |
| 1758 } | 1758 } |
| 1759 | 1759 |
| 1760 /** | 1760 /** |
| 1761 * Return the default number format. Used to format a numeric | 1761 * Return the default number format. Used to format a numeric |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1849 delete s; | 1849 delete s; |
| 1850 } | 1850 } |
| 1851 } | 1851 } |
| 1852 delete fFormatNames; | 1852 delete fFormatNames; |
| 1853 } | 1853 } |
| 1854 U_NAMESPACE_END | 1854 U_NAMESPACE_END |
| 1855 | 1855 |
| 1856 #endif /* #if !UCONFIG_NO_FORMATTING */ | 1856 #endif /* #if !UCONFIG_NO_FORMATTING */ |
| 1857 | 1857 |
| 1858 //eof | 1858 //eof |
| OLD | NEW |