Home | History | Annotate | Download | only in i18n
      1 /*
      2 *****************************************************************************************
      3 * Copyright (C) 2010-2012, International Business Machines
      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 
     17 U_NAMESPACE_USE
     18 
     19 
     20 U_CAPI UPluralRules* U_EXPORT2
     21 uplrules_open(const char *locale, UErrorCode *status)
     22 {
     23     return uplrules_openForType(locale, UPLURAL_TYPE_CARDINAL, status);
     24 }
     25 
     26 U_CAPI UPluralRules* U_EXPORT2
     27 uplrules_openForType(const char *locale, UPluralType type, UErrorCode *status)
     28 {
     29     return (UPluralRules*)PluralRules::forLocale(Locale(locale), type, *status);
     30 }
     31 
     32 U_CAPI void U_EXPORT2
     33 uplrules_close(UPluralRules *uplrules)
     34 {
     35     delete (PluralRules*)uplrules;
     36 }
     37 
     38 U_CAPI int32_t U_EXPORT2
     39 uplrules_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 */
     57