From: Peter Edberg Date: Tue, 14 Jan 2014 07:31:30 +0000 (+0000) Subject: ICU-10574 part 1, just API and setContext/getContext implementation X-Git-Tag: milestone-59-0-1~2269 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1865fa1670575e7a5f1f7c1c0392f87d54a7aacf;p=icu ICU-10574 part 1, just API and setContext/getContext implementation X-SVN-Rev: 34886 --- diff --git a/icu4c/source/i18n/numfmt.cpp b/icu4c/source/i18n/numfmt.cpp index da09207e87d..c68590d3d9b 100644 --- a/icu4c/source/i18n/numfmt.cpp +++ b/icu4c/source/i18n/numfmt.cpp @@ -1,6 +1,6 @@ /* ******************************************************************************* -* Copyright (C) 1997-2013, International Business Machines Corporation and +* Copyright (C) 1997-2014, International Business Machines Corporation and * others. All Rights Reserved. ******************************************************************************* * @@ -36,6 +36,7 @@ #include "unicode/numsys.h" #include "unicode/rbnf.h" #include "unicode/localpointer.h" +#include "unicode/udisplaycontext.h" #include "charstr.h" #include "winnmfmt.h" #include "uresimp.h" @@ -1150,6 +1151,33 @@ void NumberFormat::getEffectiveCurrency(UChar* result, UErrorCode& ec) const { } } +//---------------------------------------------------------------------- + + +void NumberFormat::setContext(UDisplayContext value, UErrorCode& status) +{ + if (U_FAILURE(status)) + return; + if ( (UDisplayContextType)((uint32_t)value >> 8) == UDISPCTX_TYPE_CAPITALIZATION ) { + fCapitalizationContext = value; + } else { + status = U_ILLEGAL_ARGUMENT_ERROR; + } +} + + +UDisplayContext NumberFormat::getContext(UDisplayContextType type, UErrorCode& status) const +{ + if (U_FAILURE(status)) + return (UDisplayContext)0; + if (type != UDISPCTX_TYPE_CAPITALIZATION) { + status = U_ILLEGAL_ARGUMENT_ERROR; + return (UDisplayContext)0; + } + return fCapitalizationContext; +} + + // ------------------------------------- // Creates the NumberFormat instance of the specified style (number, currency, // or percent) for the desired locale. diff --git a/icu4c/source/i18n/unicode/numfmt.h b/icu4c/source/i18n/unicode/numfmt.h index 1630657b601..73bf45f1956 100644 --- a/icu4c/source/i18n/unicode/numfmt.h +++ b/icu4c/source/i18n/unicode/numfmt.h @@ -1,6 +1,6 @@ /* ******************************************************************************** -* Copyright (C) 1997-2013, International Business Machines Corporation and others. +* Copyright (C) 1997-2014, International Business Machines Corporation and others. * All Rights Reserved. ******************************************************************************** * @@ -37,6 +37,7 @@ #include "unicode/locid.h" #include "unicode/stringpiece.h" #include "unicode/curramt.h" +#include "unicode/udisplaycontext.h" class NumberFormatTest; @@ -916,6 +917,31 @@ public: */ const UChar* getCurrency() const; + /* Cannot use #ifndef U_HIDE_DRAFT_API for the following draft method since it is virtual */ + /** + * Set a particular UDisplayContext value in the formatter, such as + * UDISPCTX_CAPITALIZATION_FOR_STANDALONE. + * @param value The UDisplayContext value to set. + * @param status Input/output status. If at entry this indicates a failure + * status, the function will do nothing; otherwise this will be + * updated with any new status from the function. + * @draft ICU 53 + */ + virtual void setContext(UDisplayContext value, UErrorCode& status); + + /* Cannot use #ifndef U_HIDE_DRAFT_API for the following draft method since it is virtual */ + /** + * Get the formatter's UDisplayContext value for the specified UDisplayContextType, + * such as UDISPCTX_TYPE_CAPITALIZATION. + * @param type The UDisplayContextType whose value to return + * @param status Input/output status. If at entry this indicates a failure + * status, the function will do nothing; otherwise this will be + * updated with any new status from the function. + * @return The UDisplayContextValue for the specified type. + * @draft ICU 53 + */ + virtual UDisplayContext getContext(UDisplayContextType type, UErrorCode& status) const; + public: /** @@ -999,7 +1025,7 @@ private: UNumberFormatStyle style, UErrorCode& errorCode); - UBool fGroupingUsed; + UBool fGroupingUsed; int32_t fMaxIntegerDigits; int32_t fMinIntegerDigits; int32_t fMaxFractionDigits; @@ -1016,6 +1042,8 @@ private: // ISO currency code UChar fCurrency[4]; + UDisplayContext fCapitalizationContext; + friend class ICUNumberFormatFactory; // access to makeInstance friend class ICUNumberFormatService; friend class ::NumberFormatTest; // access to isStyleSupported() diff --git a/icu4c/source/i18n/unicode/unum.h b/icu4c/source/i18n/unicode/unum.h index dce77332e96..86d4f46dee8 100644 --- a/icu4c/source/i18n/unicode/unum.h +++ b/icu4c/source/i18n/unicode/unum.h @@ -1,6 +1,6 @@ /* ******************************************************************************* -* Copyright (C) 1997-2013, International Business Machines Corporation and others. +* Copyright (C) 1997-2014, International Business Machines Corporation and others. * All Rights Reserved. * Modification History: * @@ -21,6 +21,7 @@ #include "unicode/umisc.h" #include "unicode/parseerr.h" #include "unicode/uformattable.h" +#include "unicode/udisplaycontext.h" /** * \file @@ -1242,6 +1243,32 @@ unum_getLocaleByType(const UNumberFormat *fmt, ULocDataLocaleType type, UErrorCode* status); +#ifndef U_HIDE_DRAFT_API +/** + * Set a particular UDisplayContext value in the formatter, such as + * UDISPCTX_CAPITALIZATION_FOR_STANDALONE. + * @param fmt The formatter for which to set a UDisplayContext value. + * @param value The UDisplayContext value to set. + * @param status A pointer to an UErrorCode to receive any errors + * @draft ICU 53 + */ +U_DRAFT void U_EXPORT2 +unum_setContext(UNumberFormat* fmt, UDisplayContext value, UErrorCode* status); + +/** + * Get the formatter's UDisplayContext value for the specified UDisplayContextType, + * such as UDISPCTX_TYPE_CAPITALIZATION. + * @param fmt The formatter to query. + * @param type The UDisplayContextType whose value to return + * @param status A pointer to an UErrorCode to receive any errors + * @return The UDisplayContextValue for the specified type. + * @draft ICU 53 + */ +U_DRAFT UDisplayContext U_EXPORT2 +unum_getContext(const UNumberFormat *fmt, UDisplayContextType type, UErrorCode* status); + +#endif /* U_HIDE_DRAFT_API */ + #endif /* #if !UCONFIG_NO_FORMATTING */ #endif diff --git a/icu4c/source/i18n/unum.cpp b/icu4c/source/i18n/unum.cpp index 9703f5d6a99..be19b823e56 100644 --- a/icu4c/source/i18n/unum.cpp +++ b/icu4c/source/i18n/unum.cpp @@ -1,6 +1,6 @@ /* ******************************************************************************* -* Copyright (C) 1996-2013, International Business Machines +* Copyright (C) 1996-2014, International Business Machines * Corporation and others. All Rights Reserved. ******************************************************************************* * Modification History: @@ -25,6 +25,7 @@ #include "unicode/dcfmtsym.h" #include "unicode/curramt.h" #include "unicode/localpointer.h" +#include "unicode/udisplaycontext.h" #include "uassert.h" #include "cpputils.h" #include "cstring.h" @@ -783,6 +784,25 @@ unum_getLocaleByType(const UNumberFormat *fmt, return ((const Format*)fmt)->getLocaleID(type, *status); } +U_CAPI void U_EXPORT2 +unum_setContext(UNumberFormat* fmt, UDisplayContext value, UErrorCode* status) +{ + if (U_FAILURE(*status)) { + return; + } + ((NumberFormat*)fmt)->setContext(value, *status); + return; +} + +U_CAPI UDisplayContext U_EXPORT2 +unum_getContext(const UNumberFormat *fmt, UDisplayContextType type, UErrorCode* status) +{ + if (U_FAILURE(*status)) { + return (UDisplayContext)0; + } + return ((NumberFormat*)fmt)->getContext(type, *status); +} + U_INTERNAL UFormattable * U_EXPORT2 unum_parseToUFormattable(const UNumberFormat* fmt, UFormattable *result,