Home | History | Annotate | Download | only in unicode
      1 /*
      2 *****************************************************************************************
      3 * Copyright (C) 2013, International Business Machines
      4 * Corporation and others. All Rights Reserved.
      5 *****************************************************************************************
      6 */
      7 
      8 #ifndef UNUMSYS_H
      9 #define UNUMSYS_H
     10 
     11 #include "unicode/utypes.h"
     12 
     13 #if !UCONFIG_NO_FORMATTING
     14 
     15 #include "unicode/uenum.h"
     16 #include "unicode/localpointer.h"
     17 
     18 /**
     19  * \file
     20  * \brief C API: UNumberingSystem, information about numbering systems
     21  *
     22  * Defines numbering systems. A numbering system describes the scheme by which
     23  * numbers are to be presented to the end user. In its simplest form, a numbering
     24  * system describes the set of digit characters that are to be used to display
     25  * numbers, such as Western digits, Thai digits, Arabic-Indic digits, etc., in a
     26  * positional numbering system with a specified radix (typically 10).
     27  * More complicated numbering systems are algorithmic in nature, and require use
     28  * of an RBNF formatter (rule based number formatter), in order to calculate
     29  * the characters to be displayed for a given number. Examples of algorithmic
     30  * numbering systems include Roman numerals, Chinese numerals, and Hebrew numerals.
     31  * Formatting rules for many commonly used numbering systems are included in
     32  * the ICU package, based on the numbering system rules defined in CLDR.
     33  * Alternate numbering systems can be specified to a locale by using the
     34  * numbers locale keyword.
     35  */
     36 
     37 #ifndef U_HIDE_DRAFT_API
     38 
     39 /**
     40  * Opaque UNumberingSystem object for use in C programs.
     41  * @draft ICU 52
     42  */
     43 struct UNumberingSystem;
     44 typedef struct UNumberingSystem UNumberingSystem;  /**< C typedef for struct UNumberingSystem. @draft ICU 52 */
     45 
     46 /**
     47  * Opens a UNumberingSystem object using the default numbering system for the specified
     48  * locale.
     49  * @param locale    The locale for which the default numbering system should be opened.
     50  * @param status    A pointer to a UErrorCode to receive any errors. For example, this
     51  *                  may be U_UNSUPPORTED_ERROR for a locale such as "en@numbers=xyz" that
     52  *                  specifies a numbering system unknown to ICU.
     53  * @return          A UNumberingSystem for the specified locale, or NULL if an error
     54  *                  occurred.
     55  * @draft ICU 52
     56  */
     57 U_DRAFT UNumberingSystem * U_EXPORT2
     58 unumsys_open(const char *locale, UErrorCode *status);
     59 
     60 /**
     61  * Opens a UNumberingSystem object using the name of one of the predefined numbering
     62  * systems specified by CLDR and known to ICU, such as "latn", "arabext", or "hanidec";
     63  * the full list is returned by unumsys_openAvailableNames. Note that some of the names
     64  * listed at http://unicode.org/repos/cldr/tags/latest/common/bcp47/number.xml - e.g.
     65  * default, native, traditional, finance - do not identify specific numbering systems,
     66  * but rather key values that may only be used as part of a locale, which in turn
     67  * defines how they are mapped to a specific numbering system such as "latn" or "hant".
     68  *
     69  * @param name      The name of the numbering system for which a UNumberingSystem object
     70  *                  should be opened.
     71  * @param status    A pointer to a UErrorCode to receive any errors. For example, this
     72  *                  may be U_UNSUPPORTED_ERROR for a numbering system such as "xyz" that
     73  *                  is unknown to ICU.
     74  * @return          A UNumberingSystem for the specified name, or NULL if an error
     75  *                  occurred.
     76  * @draft ICU 52
     77  */
     78 U_DRAFT UNumberingSystem * U_EXPORT2
     79 unumsys_openByName(const char *name, UErrorCode *status);
     80 
     81 /**
     82  * Close a UNumberingSystem object. Once closed it may no longer be used.
     83  * @param unumsys   The UNumberingSystem object to close.
     84  * @draft ICU 52
     85  */
     86 U_DRAFT void U_EXPORT2
     87 unumsys_close(UNumberingSystem *unumsys);
     88 
     89 #if U_SHOW_CPLUSPLUS_API
     90 U_NAMESPACE_BEGIN
     91 
     92 /**
     93  * \class LocalUNumberingSystemPointer
     94  * "Smart pointer" class, closes a UNumberingSystem via unumsys_close().
     95  * For most methods see the LocalPointerBase base class.
     96  * @see LocalPointerBase
     97  * @see LocalPointer
     98  * @draft ICU 52
     99  */
    100 U_DEFINE_LOCAL_OPEN_POINTER(LocalUNumberingSystemPointer, UNumberingSystem, unumsys_close);
    101 
    102 U_NAMESPACE_END
    103 #endif
    104 
    105 /**
    106  * Returns an enumeration over the names of all of the predefined numbering systems known
    107  * to ICU.
    108  * @param status    A pointer to a UErrorCode to receive any errors.
    109  * @return          A pointer to a UEnumeration that must be closed with uenum_close(),
    110  *                  or NULL if an error occurred.
    111  * @draft ICU 52
    112  */
    113 U_DRAFT UEnumeration * U_EXPORT2
    114 unumsys_openAvailableNames(UErrorCode *status);
    115 
    116 /**
    117  * Returns the name of the specified UNumberingSystem object (if it is one of the
    118  * predefined names known to ICU).
    119  * @param unumsys   The UNumberingSystem whose name is desired.
    120  * @return          A pointer to the name of the specified UNumberingSystem object, or
    121  *                  NULL if the name is not one of the ICU predefined names. The pointer
    122  *                  is only valid for the lifetime of the UNumberingSystem object.
    123  * @draft ICU 52
    124  */
    125 U_DRAFT const char * U_EXPORT2
    126 unumsys_getName(const UNumberingSystem *unumsys);
    127 
    128 /**
    129  * Returns whether the given UNumberingSystem object is for an algorithmic (not purely
    130  * positional) system.
    131  * @param unumsys   The UNumberingSystem whose algorithmic status is desired.
    132  * @return          TRUE if the specified UNumberingSystem object is for an algorithmic
    133  *                  system.
    134  * @draft ICU 52
    135  */
    136 U_DRAFT UBool U_EXPORT2
    137 unumsys_isAlgorithmic(const UNumberingSystem *unumsys);
    138 
    139 /**
    140  * Returns the radix of the specified UNumberingSystem object. Simple positional
    141  * numbering systems typically have radix 10, but might have a radix of e.g. 16 for
    142  * hexadecimal. The radix is less well-defined for non-positional algorithmic systems.
    143  * @param unumsys   The UNumberingSystem whose radix is desired.
    144  * @return          The radix of the specified UNumberingSystem object.
    145  * @draft ICU 52
    146  */
    147 U_DRAFT int32_t U_EXPORT2
    148 unumsys_getRadix(const UNumberingSystem *unumsys);
    149 
    150 /**
    151  * Get the description string of the specified UNumberingSystem object. For simple
    152  * positional systems this is the ordered string of digits (with length matching
    153  * the radix), e.g. "\u3007\u4E00\u4E8C\u4E09\u56DB\u4E94\u516D\u4E03\u516B\u4E5D"
    154  * for "hanidec"; it would be "0123456789ABCDEF" for hexadecimal. For
    155  * algorithmic systems this is the name of the RBNF ruleset used for formatting,
    156  * e.g. "zh/SpelloutRules/%spellout-cardinal" for "hans" or "%greek-upper" for
    157  * "grek".
    158  * @param unumsys   The UNumberingSystem whose description string is desired.
    159  * @param result    A pointer to a buffer to receive the description string.
    160  * @param resultLength  The maximum size of result.
    161  * @param status    A pointer to a UErrorCode to receive any errors.
    162  * @return          The total buffer size needed; if greater than resultLength, the
    163  *                  output was truncated.
    164  * @draft ICU 52
    165  */
    166 U_DRAFT int32_t U_EXPORT2
    167 unumsys_getDescription(const UNumberingSystem *unumsys, UChar *result,
    168                        int32_t resultLength, UErrorCode *status);
    169 
    170 #endif  /* U_HIDE_DRAFT_API */
    171 
    172 #endif /* #if !UCONFIG_NO_FORMATTING */
    173 
    174 #endif
    175