michael@0: /* michael@0: ***************************************************************************************** michael@0: * Copyright (C) 2010-2012, International Business Machines michael@0: * Corporation and others. All Rights Reserved. michael@0: ***************************************************************************************** michael@0: */ michael@0: michael@0: #include "unicode/utypes.h" michael@0: michael@0: #if !UCONFIG_NO_FORMATTING michael@0: michael@0: #include "unicode/upluralrules.h" michael@0: #include "unicode/plurrule.h" michael@0: #include "unicode/locid.h" michael@0: #include "unicode/unistr.h" michael@0: michael@0: U_NAMESPACE_USE michael@0: michael@0: michael@0: U_CAPI UPluralRules* U_EXPORT2 michael@0: uplrules_open(const char *locale, UErrorCode *status) michael@0: { michael@0: return uplrules_openForType(locale, UPLURAL_TYPE_CARDINAL, status); michael@0: } michael@0: michael@0: U_CAPI UPluralRules* U_EXPORT2 michael@0: uplrules_openForType(const char *locale, UPluralType type, UErrorCode *status) michael@0: { michael@0: return (UPluralRules*)PluralRules::forLocale(Locale(locale), type, *status); michael@0: } michael@0: michael@0: U_CAPI void U_EXPORT2 michael@0: uplrules_close(UPluralRules *uplrules) michael@0: { michael@0: delete (PluralRules*)uplrules; michael@0: } michael@0: michael@0: U_CAPI int32_t U_EXPORT2 michael@0: uplrules_select(const UPluralRules *uplrules, michael@0: double number, michael@0: UChar *keyword, int32_t capacity, michael@0: UErrorCode *status) michael@0: { michael@0: if (U_FAILURE(*status)) { michael@0: return 0; michael@0: } michael@0: if (keyword == NULL ? capacity != 0 : capacity < 0) { michael@0: *status = U_ILLEGAL_ARGUMENT_ERROR; michael@0: return 0; michael@0: } michael@0: UnicodeString result = ((PluralRules*)uplrules)->select(number); michael@0: return result.extract(keyword, capacity, *status); michael@0: } michael@0: michael@0: michael@0: #endif /* #if !UCONFIG_NO_FORMATTING */