1 // Copyright (C) 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
4 *****************************************************************************************
5 * Copyright (C) 2010-2012, International Business Machines
6 * Corporation and others. All Rights Reserved.
7 *****************************************************************************************
10 #include "unicode/utypes.h"
12 #if !UCONFIG_NO_FORMATTING
14 #include "unicode/upluralrules.h"
15 #include "unicode/plurrule.h"
16 #include "unicode/locid.h"
17 #include "unicode/unistr.h"
22 U_CAPI UPluralRules* U_EXPORT2
23 uplrules_open(const char *locale, UErrorCode *status)
25 return uplrules_openForType(locale, UPLURAL_TYPE_CARDINAL, status);
28 U_CAPI UPluralRules* U_EXPORT2
29 uplrules_openForType(const char *locale, UPluralType type, UErrorCode *status)
31 return (UPluralRules*)PluralRules::forLocale(Locale(locale), type, *status);
35 uplrules_close(UPluralRules *uplrules)
37 delete (PluralRules*)uplrules;
40 U_CAPI int32_t U_EXPORT2
41 uplrules_select(const UPluralRules *uplrules,
43 UChar *keyword, int32_t capacity,
46 if (U_FAILURE(*status)) {
49 if (keyword == NULL ? capacity != 0 : capacity < 0) {
50 *status = U_ILLEGAL_ARGUMENT_ERROR;
53 UnicodeString result = ((PluralRules*)uplrules)->select(number);
54 return result.extract(keyword, capacity, *status);
58 #endif /* #if !UCONFIG_NO_FORMATTING */