]> git.saurik.com Git - apple/icu.git/blame - icuSources/i18n/upluralrules.cpp
ICU-57131.0.1.tar.gz
[apple/icu.git] / icuSources / i18n / upluralrules.cpp
CommitLineData
4388f060
A
1/*
2*****************************************************************************************
51004dcb 3* Copyright (C) 2010-2012, International Business Machines
4388f060
A
4* Corporation and others. All Rights Reserved.
5*****************************************************************************************
6*/
7
8#include "unicode/utypes.h"
9
10#if !UCONFIG_NO_FORMATTING
11
12#include "unicode/upluralrules.h"
13#include "unicode/plurrule.h"
14#include "unicode/locid.h"
15#include "unicode/unistr.h"
16
17U_NAMESPACE_USE
18
19
20U_CAPI UPluralRules* U_EXPORT2
51004dcb 21uplrules_open(const char *locale, UErrorCode *status)
4388f060 22{
51004dcb
A
23 return uplrules_openForType(locale, UPLURAL_TYPE_CARDINAL, status);
24}
25
26U_CAPI UPluralRules* U_EXPORT2
27uplrules_openForType(const char *locale, UPluralType type, UErrorCode *status)
28{
29 return (UPluralRules*)PluralRules::forLocale(Locale(locale), type, *status);
4388f060
A
30}
31
32U_CAPI void U_EXPORT2
33uplrules_close(UPluralRules *uplrules)
34{
35 delete (PluralRules*)uplrules;
36}
37
38U_CAPI int32_t U_EXPORT2
39uplrules_select(const UPluralRules *uplrules,
40 double number,
41 UChar *keyword, int32_t capacity,
42 UErrorCode *status)
43{
44 if (U_FAILURE(*status)) {
45 return 0;
46 }
47 if (keyword == NULL ? capacity != 0 : capacity < 0) {
48 *status = U_ILLEGAL_ARGUMENT_ERROR;
49 return 0;
50 }
51 UnicodeString result = ((PluralRules*)uplrules)->select(number);
52 return result.extract(keyword, capacity, *status);
53}
54
55
56#endif /* #if !UCONFIG_NO_FORMATTING */