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-2012, International Business Machines
|
|
|
|
* Corporation and others. All Rights Reserved.
|
2011-05-03 23:23:26 +00:00
|
|
|
*****************************************************************************************
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "unicode/utypes.h"
|
|
|
|
|
|
|
|
#if !UCONFIG_NO_FORMATTING
|
|
|
|
|
|
|
|
#include "unicode/upluralrules.h"
|
|
|
|
#include "unicode/plurrule.h"
|
|
|
|
#include "unicode/locid.h"
|
|
|
|
#include "unicode/unistr.h"
|
2017-01-21 01:03:32 +00:00
|
|
|
#include "unicode/unum.h"
|
|
|
|
#include "unicode/numfmt.h"
|
2011-05-03 23:23:26 +00:00
|
|
|
|
|
|
|
U_NAMESPACE_USE
|
|
|
|
|
|
|
|
|
|
|
|
U_CAPI UPluralRules* U_EXPORT2
|
2012-04-07 04:27:27 +00:00
|
|
|
uplrules_open(const char *locale, UErrorCode *status)
|
2011-05-03 23:23:26 +00:00
|
|
|
{
|
2012-04-07 04:27:27 +00:00
|
|
|
return uplrules_openForType(locale, UPLURAL_TYPE_CARDINAL, status);
|
|
|
|
}
|
|
|
|
|
|
|
|
U_CAPI UPluralRules* U_EXPORT2
|
|
|
|
uplrules_openForType(const char *locale, UPluralType type, UErrorCode *status)
|
|
|
|
{
|
|
|
|
return (UPluralRules*)PluralRules::forLocale(Locale(locale), type, *status);
|
2011-05-03 23:23:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
U_CAPI void U_EXPORT2
|
|
|
|
uplrules_close(UPluralRules *uplrules)
|
|
|
|
{
|
2011-05-05 23:36:01 +00:00
|
|
|
delete (PluralRules*)uplrules;
|
2011-05-03 23:23:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
U_CAPI int32_t U_EXPORT2
|
|
|
|
uplrules_select(const UPluralRules *uplrules,
|
2011-05-05 23:36:01 +00:00
|
|
|
double number,
|
|
|
|
UChar *keyword, int32_t capacity,
|
|
|
|
UErrorCode *status)
|
2011-05-03 23:23:26 +00:00
|
|
|
{
|
2011-05-05 23:36:01 +00:00
|
|
|
if (U_FAILURE(*status)) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (keyword == NULL ? capacity != 0 : capacity < 0) {
|
|
|
|
*status = U_ILLEGAL_ARGUMENT_ERROR;
|
2011-05-03 23:23:26 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
UnicodeString result = ((PluralRules*)uplrules)->select(number);
|
2011-05-05 23:36:01 +00:00
|
|
|
return result.extract(keyword, capacity, *status);
|
2011-05-03 23:23:26 +00:00
|
|
|
}
|
|
|
|
|
2017-01-21 01:03:32 +00:00
|
|
|
U_CAPI int32_t U_EXPORT2
|
|
|
|
uplrules_selectWithFormat(const UPluralRules *uplrules,
|
|
|
|
double number,
|
|
|
|
const UNumberFormat *fmt,
|
|
|
|
UChar *keyword, int32_t capacity,
|
|
|
|
UErrorCode *status)
|
|
|
|
{
|
|
|
|
if (U_FAILURE(*status)) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
const PluralRules* plrules = reinterpret_cast<const PluralRules*>(uplrules);
|
|
|
|
const NumberFormat* nf = reinterpret_cast<const NumberFormat*>(fmt);
|
|
|
|
if (plrules == NULL || nf == NULL || ((keyword == NULL)? capacity != 0 : capacity < 0)) {
|
|
|
|
*status = U_ILLEGAL_ARGUMENT_ERROR;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
Formattable obj(number);
|
2017-02-09 23:40:59 +00:00
|
|
|
UnicodeString result = plrules->select(obj, *nf, *status);
|
2017-01-21 01:03:32 +00:00
|
|
|
return result.extract(keyword, capacity, *status);
|
|
|
|
}
|
2011-05-03 23:23:26 +00:00
|
|
|
|
2017-03-23 05:16:24 +00:00
|
|
|
U_CAPI UEnumeration* U_EXPORT2
|
|
|
|
uplrules_getKeywords(const UPluralRules *uplrules,
|
|
|
|
UErrorCode *status)
|
|
|
|
{
|
|
|
|
if (U_FAILURE(*status)) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
const PluralRules* plrules = reinterpret_cast<const PluralRules*>(uplrules);
|
|
|
|
if (plrules == NULL) {
|
|
|
|
*status = U_ILLEGAL_ARGUMENT_ERROR;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
StringEnumeration *senum = plrules->getKeywords(*status);
|
|
|
|
if (U_FAILURE(*status)) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
if (senum == NULL) {
|
|
|
|
*status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return uenum_openFromStringEnumeration(senum, status);
|
|
|
|
}
|
|
|
|
|
2011-05-03 23:23:26 +00:00
|
|
|
#endif /* #if !UCONFIG_NO_FORMATTING */
|