2011-05-03 23:23:26 +00:00
|
|
|
/*
|
|
|
|
*****************************************************************************************
|
2012-04-07 04:27:27 +00:00
|
|
|
* Copyright (C) 2010-2012, International Business Machines
|
2011-05-03 23:23:26 +00:00
|
|
|
* Corporation and others. All Rights Reserved.
|
|
|
|
*****************************************************************************************
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "unicode/utypes.h"
|
|
|
|
|
|
|
|
#if !UCONFIG_NO_FORMATTING
|
|
|
|
|
|
|
|
#include "unicode/upluralrules.h"
|
|
|
|
#include "unicode/plurrule.h"
|
|
|
|
#include "unicode/locid.h"
|
|
|
|
#include "unicode/unistr.h"
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endif /* #if !UCONFIG_NO_FORMATTING */
|