upluralrules.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. /*
  2. *****************************************************************************************
  3. * Copyright (C) 2010-2013, International Business Machines
  4. * Corporation and others. All Rights Reserved.
  5. *****************************************************************************************
  6. */
  7. #ifndef UPLURALRULES_H
  8. #define UPLURALRULES_H
  9. #include "unicode/utypes.h"
  10. #if !UCONFIG_NO_FORMATTING
  11. #include "unicode/localpointer.h"
  12. /**
  13. * \file
  14. * \brief C API: Plural rules, select plural keywords for numeric values.
  15. *
  16. * A UPluralRules object defines rules for mapping non-negative numeric
  17. * values onto a small set of keywords. Rules are constructed from a text
  18. * description, consisting of a series of keywords and conditions.
  19. * The uplrules_select function examines each condition in order and
  20. * returns the keyword for the first condition that matches the number.
  21. * If none match, the default rule(other) is returned.
  22. *
  23. * For more information, see the LDML spec, C.11 Language Plural Rules:
  24. * http://www.unicode.org/reports/tr35/#Language_Plural_Rules
  25. *
  26. * Keywords: ICU locale data has 6 predefined values -
  27. * 'zero', 'one', 'two', 'few', 'many' and 'other'. Callers need to check
  28. * the value of keyword returned by the uplrules_select function.
  29. *
  30. * These are based on CLDR <i>Language Plural Rules</i>. For these
  31. * predefined rules, see the CLDR page at
  32. * http://unicode.org/repos/cldr-tmp/trunk/diff/supplemental/language_plural_rules.html
  33. */
  34. /**
  35. * Type of plurals and PluralRules.
  36. * @stable ICU 50
  37. */
  38. enum UPluralType {
  39. /**
  40. * Plural rules for cardinal numbers: 1 file vs. 2 files.
  41. * @stable ICU 50
  42. */
  43. UPLURAL_TYPE_CARDINAL,
  44. /**
  45. * Plural rules for ordinal numbers: 1st file, 2nd file, 3rd file, 4th file, etc.
  46. * @stable ICU 50
  47. */
  48. UPLURAL_TYPE_ORDINAL,
  49. /**
  50. * Number of Plural rules types.
  51. * @stable ICU 50
  52. */
  53. UPLURAL_TYPE_COUNT
  54. };
  55. /**
  56. * @stable ICU 50
  57. */
  58. typedef enum UPluralType UPluralType;
  59. /**
  60. * Opaque UPluralRules object for use in C programs.
  61. * @stable ICU 4.8
  62. */
  63. struct UPluralRules;
  64. typedef struct UPluralRules UPluralRules; /**< C typedef for struct UPluralRules. @stable ICU 4.8 */
  65. /**
  66. * Opens a new UPluralRules object using the predefined cardinal-number plural rules for a
  67. * given locale.
  68. * Same as uplrules_openForType(locale, UPLURAL_TYPE_CARDINAL, status).
  69. * @param locale The locale for which the rules are desired.
  70. * @param status A pointer to a UErrorCode to receive any errors.
  71. * @return A UPluralRules for the specified locale, or NULL if an error occurred.
  72. * @stable ICU 4.8
  73. */
  74. U_STABLE UPluralRules* U_EXPORT2
  75. uplrules_open(const char *locale, UErrorCode *status);
  76. /**
  77. * Opens a new UPluralRules object using the predefined plural rules for a
  78. * given locale and the plural type.
  79. * @param locale The locale for which the rules are desired.
  80. * @param type The plural type (e.g., cardinal or ordinal).
  81. * @param status A pointer to a UErrorCode to receive any errors.
  82. * @return A UPluralRules for the specified locale, or NULL if an error occurred.
  83. * @stable ICU 50
  84. */
  85. U_DRAFT UPluralRules* U_EXPORT2
  86. uplrules_openForType(const char *locale, UPluralType type, UErrorCode *status);
  87. /**
  88. * Closes a UPluralRules object. Once closed it may no longer be used.
  89. * @param uplrules The UPluralRules object to close.
  90. * @stable ICU 4.8
  91. */
  92. U_STABLE void U_EXPORT2
  93. uplrules_close(UPluralRules *uplrules);
  94. #if U_SHOW_CPLUSPLUS_API
  95. U_NAMESPACE_BEGIN
  96. /**
  97. * \class LocalUPluralRulesPointer
  98. * "Smart pointer" class, closes a UPluralRules via uplrules_close().
  99. * For most methods see the LocalPointerBase base class.
  100. *
  101. * @see LocalPointerBase
  102. * @see LocalPointer
  103. * @stable ICU 4.8
  104. */
  105. U_DEFINE_LOCAL_OPEN_POINTER(LocalUPluralRulesPointer, UPluralRules, uplrules_close);
  106. U_NAMESPACE_END
  107. #endif
  108. /**
  109. * Given a number, returns the keyword of the first rule that
  110. * applies to the number, according to the supplied UPluralRules object.
  111. * @param uplrules The UPluralRules object specifying the rules.
  112. * @param number The number for which the rule has to be determined.
  113. * @param keyword The keyword of the rule that applies to number.
  114. * @param capacity The capacity of keyword.
  115. * @param status A pointer to a UErrorCode to receive any errors.
  116. * @return The length of keyword.
  117. * @stable ICU 4.8
  118. */
  119. U_STABLE int32_t U_EXPORT2
  120. uplrules_select(const UPluralRules *uplrules,
  121. double number,
  122. UChar *keyword, int32_t capacity,
  123. UErrorCode *status);
  124. #endif /* #if !UCONFIG_NO_FORMATTING */
  125. #endif