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
|
2015-12-14 21:57:41 +00:00
|
|
|
/*
|
|
|
|
*******************************************************************************
|
2016-05-31 21:45:07 +00:00
|
|
|
* Copyright (C) 2015, International Business Machines Corporation
|
|
|
|
* and others. All Rights Reserved.
|
2015-12-14 21:57:41 +00:00
|
|
|
*******************************************************************************
|
|
|
|
* standardplural.h
|
|
|
|
*
|
|
|
|
* created on: 2015dec14
|
|
|
|
* created by: Markus W. Scherer
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __STANDARDPLURAL_H__
|
|
|
|
#define __STANDARDPLURAL_H__
|
|
|
|
|
|
|
|
#include "unicode/utypes.h"
|
|
|
|
|
|
|
|
#if !UCONFIG_NO_FORMATTING
|
|
|
|
|
|
|
|
U_NAMESPACE_BEGIN
|
|
|
|
|
2015-12-16 04:21:28 +00:00
|
|
|
class UnicodeString;
|
|
|
|
|
2015-12-14 21:57:41 +00:00
|
|
|
/**
|
|
|
|
* Standard CLDR plural form/category constants.
|
|
|
|
* See http://www.unicode.org/reports/tr35/tr35-numbers.html#Language_Plural_Rules
|
|
|
|
*/
|
|
|
|
class U_I18N_API StandardPlural {
|
|
|
|
public:
|
|
|
|
enum Form {
|
|
|
|
ZERO,
|
|
|
|
ONE,
|
|
|
|
TWO,
|
|
|
|
FEW,
|
|
|
|
MANY,
|
|
|
|
OTHER,
|
|
|
|
COUNT
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return the lowercase CLDR keyword string for the plural form
|
|
|
|
*/
|
|
|
|
static const char *getKeyword(Form p);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param keyword for example "few" or "other"
|
|
|
|
* @return the plural form corresponding to the keyword, or OTHER
|
|
|
|
*/
|
|
|
|
static Form orOtherFromString(const char *keyword) {
|
|
|
|
return static_cast<Form>(indexOrOtherIndexFromString(keyword));
|
|
|
|
}
|
|
|
|
|
2015-12-16 04:21:28 +00:00
|
|
|
/**
|
|
|
|
* @param keyword for example "few" or "other"
|
|
|
|
* @return the plural form corresponding to the keyword, or OTHER
|
|
|
|
*/
|
|
|
|
static Form orOtherFromString(const UnicodeString &keyword) {
|
|
|
|
return static_cast<Form>(indexOrOtherIndexFromString(keyword));
|
|
|
|
}
|
|
|
|
|
2015-12-14 21:57:41 +00:00
|
|
|
/**
|
|
|
|
* Sets U_ILLEGAL_ARGUMENT_ERROR if the keyword is not a plural form.
|
|
|
|
*
|
|
|
|
* @param keyword for example "few" or "other"
|
|
|
|
* @return the plural form corresponding to the keyword
|
|
|
|
*/
|
|
|
|
static Form fromString(const char *keyword, UErrorCode &errorCode) {
|
|
|
|
return static_cast<Form>(indexFromString(keyword, errorCode));
|
|
|
|
}
|
|
|
|
|
2015-12-16 04:21:28 +00:00
|
|
|
/**
|
|
|
|
* Sets U_ILLEGAL_ARGUMENT_ERROR if the keyword is not a plural form.
|
|
|
|
*
|
|
|
|
* @param keyword for example "few" or "other"
|
|
|
|
* @return the plural form corresponding to the keyword
|
|
|
|
*/
|
|
|
|
static Form fromString(const UnicodeString &keyword, UErrorCode &errorCode) {
|
|
|
|
return static_cast<Form>(indexFromString(keyword, errorCode));
|
|
|
|
}
|
|
|
|
|
2015-12-14 21:57:41 +00:00
|
|
|
/**
|
|
|
|
* @param keyword for example "few" or "other"
|
|
|
|
* @return the index of the plural form corresponding to the keyword, or a negative value
|
|
|
|
*/
|
|
|
|
static int32_t indexOrNegativeFromString(const char *keyword);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param keyword for example "few" or "other"
|
2015-12-16 04:21:28 +00:00
|
|
|
* @return the index of the plural form corresponding to the keyword, or a negative value
|
|
|
|
*/
|
|
|
|
static int32_t indexOrNegativeFromString(const UnicodeString &keyword);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param keyword for example "few" or "other"
|
|
|
|
* @return the index of the plural form corresponding to the keyword, or OTHER
|
2015-12-14 21:57:41 +00:00
|
|
|
*/
|
|
|
|
static int32_t indexOrOtherIndexFromString(const char *keyword) {
|
|
|
|
int32_t i = indexOrNegativeFromString(keyword);
|
|
|
|
return i >= 0 ? i : OTHER;
|
|
|
|
}
|
|
|
|
|
2015-12-16 04:21:28 +00:00
|
|
|
/**
|
|
|
|
* @param keyword for example "few" or "other"
|
|
|
|
* @return the index of the plural form corresponding to the keyword, or OTHER
|
|
|
|
*/
|
|
|
|
static int32_t indexOrOtherIndexFromString(const UnicodeString &keyword) {
|
|
|
|
int32_t i = indexOrNegativeFromString(keyword);
|
|
|
|
return i >= 0 ? i : OTHER;
|
|
|
|
}
|
|
|
|
|
2015-12-14 21:57:41 +00:00
|
|
|
/**
|
|
|
|
* Sets U_ILLEGAL_ARGUMENT_ERROR if the keyword is not a plural form.
|
|
|
|
*
|
|
|
|
* @param keyword for example "few" or "other"
|
|
|
|
* @return the index of the plural form corresponding to the keyword
|
|
|
|
*/
|
|
|
|
static int32_t indexFromString(const char *keyword, UErrorCode &errorCode);
|
2015-12-16 04:21:28 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets U_ILLEGAL_ARGUMENT_ERROR if the keyword is not a plural form.
|
|
|
|
*
|
|
|
|
* @param keyword for example "few" or "other"
|
|
|
|
* @return the index of the plural form corresponding to the keyword
|
|
|
|
*/
|
|
|
|
static int32_t indexFromString(const UnicodeString &keyword, UErrorCode &errorCode);
|
2015-12-14 21:57:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
U_NAMESPACE_END
|
|
|
|
|
|
|
|
#endif // !UCONFIG_NO_FORMATTING
|
|
|
|
#endif // __STANDARDPLURAL_H__
|