Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/unicode/numsys.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 // © 2016 and later: Unicode, Inc. and others.
0002 // License & terms of use: http://www.unicode.org/copyright.html
0003 /*
0004 *******************************************************************************
0005 * Copyright (C) 2010-2014, International Business Machines Corporation and
0006 * others. All Rights Reserved.
0007 *******************************************************************************
0008 *
0009 *
0010 * File NUMSYS.H
0011 *
0012 * Modification History:*
0013 *   Date        Name        Description
0014 *
0015 ********************************************************************************
0016 */
0017 
0018 #ifndef NUMSYS
0019 #define NUMSYS
0020 
0021 #include "unicode/utypes.h"
0022 
0023 #if U_SHOW_CPLUSPLUS_API
0024 
0025 /**
0026  * \file
0027  * \brief C++ API: NumberingSystem object
0028  */
0029 
0030 #if !UCONFIG_NO_FORMATTING
0031 
0032 #include "unicode/format.h"
0033 #include "unicode/uobject.h"
0034 
0035 U_NAMESPACE_BEGIN
0036 
0037 // can't be #ifndef U_HIDE_INTERNAL_API; needed for char[] field size
0038 /**
0039  * Size of a numbering system name.
0040  * @internal
0041  */
0042 constexpr const size_t kInternalNumSysNameCapacity = 8;
0043 
0044 /**
0045  * Defines numbering systems. A numbering system describes the scheme by which 
0046  * numbers are to be presented to the end user.  In its simplest form, a numbering
0047  * system describes the set of digit characters that are to be used to display
0048  * numbers, such as Western digits, Thai digits, Arabic-Indic digits, etc., in a
0049  * positional numbering system with a specified radix (typically 10).
0050  * More complicated numbering systems are algorithmic in nature, and require use
0051  * of an RBNF formatter ( rule based number formatter ), in order to calculate
0052  * the characters to be displayed for a given number.  Examples of algorithmic
0053  * numbering systems include Roman numerals, Chinese numerals, and Hebrew numerals.
0054  * Formatting rules for many commonly used numbering systems are included in
0055  * the ICU package, based on the numbering system rules defined in CLDR.
0056  * Alternate numbering systems can be specified to a locale by using the
0057  * numbers locale keyword.
0058  */
0059 
0060 class U_I18N_API NumberingSystem : public UObject {
0061 public:
0062 
0063     /**
0064      * Default Constructor.
0065      *
0066      * @stable ICU 4.2
0067      */
0068     NumberingSystem();
0069 
0070     /**
0071      * Copy constructor.
0072      * @stable ICU 4.2
0073      */
0074     NumberingSystem(const NumberingSystem& other);
0075 
0076     /**
0077      * Copy assignment.
0078      * @stable ICU 4.2
0079      */
0080     NumberingSystem& operator=(const NumberingSystem& other) = default;
0081 
0082     /**
0083      * Destructor.
0084      * @stable ICU 4.2
0085      */
0086     virtual ~NumberingSystem();
0087 
0088     /**
0089      * Create the default numbering system associated with the specified locale.
0090      * @param inLocale The given locale.
0091      * @param status ICU status
0092      * @stable ICU 4.2
0093      */
0094     static NumberingSystem* U_EXPORT2 createInstance(const Locale & inLocale, UErrorCode& status);
0095 
0096     /**
0097      * Create the default numbering system associated with the default locale.
0098      * @stable ICU 4.2
0099      */
0100     static NumberingSystem* U_EXPORT2 createInstance(UErrorCode& status);
0101 
0102     /**
0103      * Create a numbering system using the specified radix, type, and description. 
0104      * @param radix         The radix (base) for this numbering system.
0105      * @param isAlgorithmic true if the numbering system is algorithmic rather than numeric.
0106      * @param description   The string representing the set of digits used in a numeric system, or the name of the RBNF
0107      *                      ruleset to be used in an algorithmic system.
0108      * @param status ICU status
0109      * @stable ICU 4.2
0110      */
0111     static NumberingSystem* U_EXPORT2 createInstance(int32_t radix, UBool isAlgorithmic, const UnicodeString& description, UErrorCode& status );
0112 
0113     /**
0114      * Return a StringEnumeration over all the names of numbering systems known to ICU.
0115      * The numbering system names will be in alphabetical (invariant) order.
0116      *
0117      * The returned StringEnumeration is owned by the caller, who must delete it when
0118      * finished with it.
0119      *
0120      * @stable ICU 4.2
0121      */
0122      static StringEnumeration * U_EXPORT2 getAvailableNames(UErrorCode& status);
0123 
0124     /**
0125      * Create a numbering system from one of the predefined numbering systems specified
0126      * by CLDR and known to ICU, such as "latn", "arabext", or "hanidec"; the full list
0127      * is returned by unumsys_openAvailableNames. Note that some of the names listed at
0128      * http://unicode.org/repos/cldr/tags/latest/common/bcp47/number.xml - e.g.
0129      * default, native, traditional, finance - do not identify specific numbering systems,
0130      * but rather key values that may only be used as part of a locale, which in turn
0131      * defines how they are mapped to a specific numbering system such as "latn" or "hant".
0132      *
0133      * @param name   The name of the numbering system.
0134      * @param status ICU status; set to U_UNSUPPORTED_ERROR if numbering system not found.
0135      * @return The NumberingSystem instance, or nullptr if not found.
0136      * @stable ICU 4.2
0137      */
0138     static NumberingSystem* U_EXPORT2 createInstanceByName(const char* name, UErrorCode& status);
0139 
0140 
0141     /**
0142      * Returns the radix of this numbering system. Simple positional numbering systems
0143      * typically have radix 10, but might have a radix of e.g. 16 for hexadecimal. The
0144      * radix is less well-defined for non-positional algorithmic systems.
0145      * @stable ICU 4.2
0146      */
0147     int32_t getRadix() const;
0148 
0149     /**
0150      * Returns the name of this numbering system if it was created using one of the predefined names
0151      * known to ICU.  Otherwise, returns nullptr.
0152      * The predefined names are identical to the numbering system names as defined by
0153      * the BCP47 definition in Unicode CLDR.
0154      * See also, http://www.unicode.org/repos/cldr/tags/latest/common/bcp47/number.xml
0155      * @stable ICU 4.6
0156      */
0157     const char * getName() const;
0158 
0159     /**
0160      * Returns the description string of this numbering system. For simple
0161      * positional systems this is the ordered string of digits (with length matching
0162      * the radix), e.g. "\u3007\u4E00\u4E8C\u4E09\u56DB\u4E94\u516D\u4E03\u516B\u4E5D"
0163      * for "hanidec"; it would be "0123456789ABCDEF" for hexadecimal. For
0164      * algorithmic systems this is the name of the RBNF ruleset used for formatting,
0165      * e.g. "zh/SpelloutRules/%spellout-cardinal" for "hans" or "%greek-upper" for
0166      * "grek".
0167      * @stable ICU 4.2
0168      */
0169     virtual UnicodeString getDescription() const;
0170 
0171 
0172 
0173     /**
0174      * Returns true if the given numbering system is algorithmic
0175      *
0176      * @return         true if the numbering system is algorithmic.
0177      *                 Otherwise, return false.
0178      * @stable ICU 4.2
0179      */
0180     UBool isAlgorithmic() const;
0181 
0182     /**
0183      * ICU "poor man's RTTI", returns a UClassID for this class.
0184      *
0185      * @stable ICU 4.2
0186      *
0187     */
0188     static UClassID U_EXPORT2 getStaticClassID(void);
0189 
0190     /**
0191      * ICU "poor man's RTTI", returns a UClassID for the actual class.
0192      *
0193      * @stable ICU 4.2
0194      */
0195     virtual UClassID getDynamicClassID() const override;
0196 
0197 
0198 private:
0199     UnicodeString   desc;
0200     int32_t         radix;
0201     UBool           algorithmic;
0202     char            name[kInternalNumSysNameCapacity+1];
0203 
0204     void setRadix(int32_t radix);
0205 
0206     void setAlgorithmic(UBool algorithmic);
0207 
0208     void setDesc(const UnicodeString &desc);
0209 
0210     void setName(const char* name);
0211 };
0212 
0213 U_NAMESPACE_END
0214 
0215 #endif /* #if !UCONFIG_NO_FORMATTING */
0216 
0217 #endif /* U_SHOW_CPLUSPLUS_API */
0218 
0219 #endif // _NUMSYS
0220 //eof