2017-01-20 00:20:31 +00:00
|
|
|
// © 2016 and later: Unicode, Inc. and others.
|
2016-06-15 18:58:17 +00:00
|
|
|
// License & terms of use: http://www.unicode.org/copyright.html
|
2011-05-03 23:23:26 +00:00
|
|
|
/*
|
|
|
|
*****************************************************************************************
|
2016-05-31 21:45:07 +00:00
|
|
|
* Copyright (C) 2010-2013, International Business Machines
|
|
|
|
* Corporation and others. All Rights Reserved.
|
2011-05-03 23:23:26 +00:00
|
|
|
*****************************************************************************************
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef UPLURALRULES_H
|
|
|
|
#define UPLURALRULES_H
|
|
|
|
|
|
|
|
#include "unicode/utypes.h"
|
|
|
|
|
|
|
|
#if !UCONFIG_NO_FORMATTING
|
|
|
|
|
|
|
|
#include "unicode/localpointer.h"
|
2017-03-23 05:16:24 +00:00
|
|
|
#include "unicode/uenum.h"
|
2017-01-21 01:03:32 +00:00
|
|
|
#ifndef U_HIDE_INTERNAL_API
|
|
|
|
#include "unicode/unum.h"
|
|
|
|
#endif /* U_HIDE_INTERNAL_API */
|
2011-05-03 23:23:26 +00:00
|
|
|
|
|
|
|
/**
|
2011-08-01 02:20:46 +00:00
|
|
|
* \file
|
|
|
|
* \brief C API: Plural rules, select plural keywords for numeric values.
|
|
|
|
*
|
2011-05-03 23:23:26 +00:00
|
|
|
* A UPluralRules object defines rules for mapping non-negative numeric
|
|
|
|
* values onto a small set of keywords. Rules are constructed from a text
|
|
|
|
* description, consisting of a series of keywords and conditions.
|
|
|
|
* The uplrules_select function examines each condition in order and
|
|
|
|
* returns the keyword for the first condition that matches the number.
|
|
|
|
* If none match, the default rule(other) is returned.
|
|
|
|
*
|
|
|
|
* For more information, see the LDML spec, C.11 Language Plural Rules:
|
|
|
|
* http://www.unicode.org/reports/tr35/#Language_Plural_Rules
|
|
|
|
*
|
|
|
|
* Keywords: ICU locale data has 6 predefined values -
|
|
|
|
* 'zero', 'one', 'two', 'few', 'many' and 'other'. Callers need to check
|
|
|
|
* the value of keyword returned by the uplrules_select function.
|
|
|
|
*
|
|
|
|
* These are based on CLDR <i>Language Plural Rules</i>. For these
|
|
|
|
* predefined rules, see the CLDR page at
|
|
|
|
* http://unicode.org/repos/cldr-tmp/trunk/diff/supplemental/language_plural_rules.html
|
|
|
|
*/
|
|
|
|
|
2012-04-07 04:27:27 +00:00
|
|
|
/**
|
|
|
|
* Type of plurals and PluralRules.
|
2013-09-19 00:44:08 +00:00
|
|
|
* @stable ICU 50
|
2012-04-07 04:27:27 +00:00
|
|
|
*/
|
|
|
|
enum UPluralType {
|
|
|
|
/**
|
|
|
|
* Plural rules for cardinal numbers: 1 file vs. 2 files.
|
2013-09-19 00:44:08 +00:00
|
|
|
* @stable ICU 50
|
2012-04-07 04:27:27 +00:00
|
|
|
*/
|
|
|
|
UPLURAL_TYPE_CARDINAL,
|
|
|
|
/**
|
|
|
|
* Plural rules for ordinal numbers: 1st file, 2nd file, 3rd file, 4th file, etc.
|
2013-09-19 00:44:08 +00:00
|
|
|
* @stable ICU 50
|
2012-04-07 04:27:27 +00:00
|
|
|
*/
|
|
|
|
UPLURAL_TYPE_ORDINAL,
|
2016-09-08 22:45:51 +00:00
|
|
|
#ifndef U_HIDE_DEPRECATED_API
|
2012-04-07 04:27:27 +00:00
|
|
|
/**
|
2016-09-08 22:45:51 +00:00
|
|
|
* One more than the highest normal UPluralType value.
|
|
|
|
* @deprecated ICU 58 The numeric value may change over time, see ICU ticket #12420.
|
2012-04-07 04:27:27 +00:00
|
|
|
*/
|
|
|
|
UPLURAL_TYPE_COUNT
|
2017-03-29 04:44:37 +00:00
|
|
|
#endif /* U_HIDE_DEPRECATED_API */
|
2012-04-07 04:27:27 +00:00
|
|
|
};
|
|
|
|
/**
|
2013-09-19 00:44:08 +00:00
|
|
|
* @stable ICU 50
|
2012-04-07 04:27:27 +00:00
|
|
|
*/
|
|
|
|
typedef enum UPluralType UPluralType;
|
|
|
|
|
2011-05-03 23:23:26 +00:00
|
|
|
/**
|
|
|
|
* Opaque UPluralRules object for use in C programs.
|
2012-02-20 04:28:17 +00:00
|
|
|
* @stable ICU 4.8
|
2011-05-03 23:23:26 +00:00
|
|
|
*/
|
|
|
|
struct UPluralRules;
|
2012-02-20 04:28:17 +00:00
|
|
|
typedef struct UPluralRules UPluralRules; /**< C typedef for struct UPluralRules. @stable ICU 4.8 */
|
2011-05-03 23:23:26 +00:00
|
|
|
|
|
|
|
/**
|
2012-04-07 04:27:27 +00:00
|
|
|
* Opens a new UPluralRules object using the predefined cardinal-number plural rules for a
|
2011-05-03 23:23:26 +00:00
|
|
|
* given locale.
|
2012-04-07 04:27:27 +00:00
|
|
|
* Same as uplrules_openForType(locale, UPLURAL_TYPE_CARDINAL, status).
|
2011-05-03 23:23:26 +00:00
|
|
|
* @param locale The locale for which the rules are desired.
|
|
|
|
* @param status A pointer to a UErrorCode to receive any errors.
|
2012-04-07 04:27:27 +00:00
|
|
|
* @return A UPluralRules for the specified locale, or NULL if an error occurred.
|
2012-02-20 04:28:17 +00:00
|
|
|
* @stable ICU 4.8
|
2011-05-03 23:23:26 +00:00
|
|
|
*/
|
2016-12-19 22:40:54 +00:00
|
|
|
U_CAPI UPluralRules* U_EXPORT2
|
2012-04-07 04:27:27 +00:00
|
|
|
uplrules_open(const char *locale, UErrorCode *status);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Opens a new UPluralRules object using the predefined plural rules for a
|
|
|
|
* given locale and the plural type.
|
|
|
|
* @param locale The locale for which the rules are desired.
|
|
|
|
* @param type The plural type (e.g., cardinal or ordinal).
|
|
|
|
* @param status A pointer to a UErrorCode to receive any errors.
|
|
|
|
* @return A UPluralRules for the specified locale, or NULL if an error occurred.
|
2013-09-19 00:44:08 +00:00
|
|
|
* @stable ICU 50
|
2012-04-07 04:27:27 +00:00
|
|
|
*/
|
2016-12-19 22:40:54 +00:00
|
|
|
U_CAPI UPluralRules* U_EXPORT2
|
2012-04-07 04:27:27 +00:00
|
|
|
uplrules_openForType(const char *locale, UPluralType type, UErrorCode *status);
|
2011-05-03 23:23:26 +00:00
|
|
|
|
|
|
|
/**
|
2012-04-07 04:27:27 +00:00
|
|
|
* Closes a UPluralRules object. Once closed it may no longer be used.
|
2011-05-03 23:23:26 +00:00
|
|
|
* @param uplrules The UPluralRules object to close.
|
2012-02-20 04:28:17 +00:00
|
|
|
* @stable ICU 4.8
|
2011-05-03 23:23:26 +00:00
|
|
|
*/
|
2016-12-19 22:40:54 +00:00
|
|
|
U_CAPI void U_EXPORT2
|
2011-05-03 23:23:26 +00:00
|
|
|
uplrules_close(UPluralRules *uplrules);
|
|
|
|
|
|
|
|
|
|
|
|
#if U_SHOW_CPLUSPLUS_API
|
|
|
|
|
|
|
|
U_NAMESPACE_BEGIN
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \class LocalUPluralRulesPointer
|
|
|
|
* "Smart pointer" class, closes a UPluralRules via uplrules_close().
|
|
|
|
* For most methods see the LocalPointerBase base class.
|
|
|
|
*
|
|
|
|
* @see LocalPointerBase
|
|
|
|
* @see LocalPointer
|
2012-02-20 04:28:17 +00:00
|
|
|
* @stable ICU 4.8
|
2011-05-03 23:23:26 +00:00
|
|
|
*/
|
|
|
|
U_DEFINE_LOCAL_OPEN_POINTER(LocalUPluralRulesPointer, UPluralRules, uplrules_close);
|
|
|
|
|
|
|
|
U_NAMESPACE_END
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Given a number, returns the keyword of the first rule that
|
|
|
|
* applies to the number, according to the supplied UPluralRules object.
|
|
|
|
* @param uplrules The UPluralRules object specifying the rules.
|
|
|
|
* @param number The number for which the rule has to be determined.
|
|
|
|
* @param keyword The keyword of the rule that applies to number.
|
|
|
|
* @param capacity The capacity of keyword.
|
|
|
|
* @param status A pointer to a UErrorCode to receive any errors.
|
|
|
|
* @return The length of keyword.
|
2012-02-20 04:28:17 +00:00
|
|
|
* @stable ICU 4.8
|
2011-05-03 23:23:26 +00:00
|
|
|
*/
|
2016-12-19 22:40:54 +00:00
|
|
|
U_CAPI int32_t U_EXPORT2
|
2011-05-03 23:23:26 +00:00
|
|
|
uplrules_select(const UPluralRules *uplrules,
|
|
|
|
double number,
|
|
|
|
UChar *keyword, int32_t capacity,
|
|
|
|
UErrorCode *status);
|
|
|
|
|
2017-01-21 01:03:32 +00:00
|
|
|
#ifndef U_HIDE_INTERNAL_API
|
|
|
|
/**
|
|
|
|
* Given a number, returns the keyword of the first rule that applies to the
|
|
|
|
* number, according to the UPluralRules object and given the number format
|
|
|
|
* specified by the UNumberFormat object.
|
|
|
|
* Note: This internal preview interface may be removed in the future if
|
|
|
|
* an architecturally cleaner solution reaches stable status.
|
|
|
|
* @param uplrules The UPluralRules object specifying the rules.
|
|
|
|
* @param number The number for which the rule has to be determined.
|
|
|
|
* @param fmt The UNumberFormat specifying how the number will be formatted
|
|
|
|
* (this can affect the plural form, e.g. "1 dollar" vs "1.0 dollars").
|
|
|
|
* If this is NULL, the function behaves like uplrules_select.
|
|
|
|
* @param keyword The keyword of the rule that applies to number.
|
|
|
|
* @param capacity The capacity of the keyword buffer.
|
|
|
|
* @param status A pointer to a UErrorCode to receive any errors.
|
|
|
|
* @return The length of keyword.
|
|
|
|
* @internal ICU 59 technology preview, may be removed in the future
|
|
|
|
*/
|
|
|
|
U_INTERNAL int32_t U_EXPORT2
|
|
|
|
uplrules_selectWithFormat(const UPluralRules *uplrules,
|
|
|
|
double number,
|
|
|
|
const UNumberFormat *fmt,
|
|
|
|
UChar *keyword, int32_t capacity,
|
|
|
|
UErrorCode *status);
|
|
|
|
|
|
|
|
#endif /* U_HIDE_INTERNAL_API */
|
|
|
|
|
2017-03-23 05:16:24 +00:00
|
|
|
/**
|
|
|
|
* Creates a string enumeration of all plural rule keywords used in this
|
|
|
|
* UPluralRules object. The rule "other" is always present by default.
|
|
|
|
* @param uplrules The UPluralRules object specifying the rules for
|
|
|
|
* a given locale.
|
|
|
|
* @param status A pointer to a UErrorCode to receive any errors.
|
|
|
|
* @return a string enumeration over plural rule keywords, or NULL
|
|
|
|
* upon error. The caller is responsible for closing the result.
|
2018-03-01 05:54:24 +00:00
|
|
|
* @stable ICU 59
|
2017-03-23 05:16:24 +00:00
|
|
|
*/
|
2018-03-01 05:54:24 +00:00
|
|
|
U_STABLE UEnumeration* U_EXPORT2
|
2017-03-23 05:16:24 +00:00
|
|
|
uplrules_getKeywords(const UPluralRules *uplrules,
|
|
|
|
UErrorCode *status);
|
|
|
|
|
2011-05-03 23:23:26 +00:00
|
|
|
#endif /* #if !UCONFIG_NO_FORMATTING */
|
|
|
|
|
|
|
|
#endif
|