(root)/
gettext-0.22.4/
gettext-tools/
src/
cldr-plural-exp.h
       1  /* Unicode CLDR plural rule parser and converter
       2     Copyright (C) 2015, 2018 Free Software Foundation, Inc.
       3  
       4     This file was written by Daiki Ueno <ueno@gnu.org>, 2015.
       5  
       6     This program is free software: you can redistribute it and/or modify
       7     it under the terms of the GNU General Public License as published by
       8     the Free Software Foundation; either version 3 of the License, or
       9     (at your option) any later version.
      10  
      11     This program is distributed in the hope that it will be useful,
      12     but WITHOUT ANY WARRANTY; without even the implied warranty of
      13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      14     GNU General Public License for more details.
      15  
      16     You should have received a copy of the GNU General Public License
      17     along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
      18  
      19  #ifndef _CLDR_PLURAL_EXP_H
      20  #define _CLDR_PLURAL_EXP_H 1
      21  
      22  #include <stdio.h>
      23  
      24  #ifdef __cplusplus
      25  extern "C" {
      26  #endif
      27  
      28  enum cldr_plural_operand
      29    {
      30      CLDR_PLURAL_OPERAND_INTEGER,
      31      CLDR_PLURAL_OPERAND_DECIMAL
      32    };
      33  
      34  struct cldr_plural_operand_ty
      35  {
      36    enum cldr_plural_operand type;
      37    union
      38    {
      39      int ival;
      40      struct
      41      {
      42        double d;
      43        int nfractions;
      44      } dval;
      45    } value;
      46  };
      47  
      48  enum cldr_plural_relation
      49    {
      50      CLDR_PLURAL_RELATION_EQUAL,
      51      CLDR_PLURAL_RELATION_NOT_EQUAL
      52    };
      53  
      54  struct cldr_plural_range_ty
      55  {
      56    struct cldr_plural_operand_ty *start;
      57    struct cldr_plural_operand_ty *end;
      58  };
      59  
      60  struct cldr_plural_range_list_ty
      61  {
      62    struct cldr_plural_range_ty **items;
      63    size_t nitems;
      64    size_t nitems_max;
      65  };
      66  
      67  struct cldr_plural_expression_ty
      68  {
      69    /* 'n', 'i', 'f', 't', 'v', 'w' */
      70    int operand;
      71  
      72    /* 0 if not given */
      73    int mod;
      74  };
      75  
      76  struct cldr_plural_relation_ty
      77  {
      78    struct cldr_plural_expression_ty *expression;
      79    enum cldr_plural_relation type;
      80    struct cldr_plural_range_list_ty *ranges;
      81  };
      82  
      83  enum cldr_plural_condition
      84    {
      85      CLDR_PLURAL_CONDITION_AND,
      86      CLDR_PLURAL_CONDITION_OR,
      87      CLDR_PLURAL_CONDITION_RELATION,
      88      CLDR_PLURAL_CONDITION_TRUE,
      89      CLDR_PLURAL_CONDITION_FALSE
      90    };
      91  
      92  struct cldr_plural_condition_ty
      93  {
      94    enum cldr_plural_condition type;
      95    union
      96    {
      97      struct cldr_plural_relation_ty *relation;
      98      struct cldr_plural_condition_ty *conditions[2];
      99    } value;
     100  };
     101  
     102  struct cldr_plural_rule_ty
     103  {
     104    char *name;
     105    struct cldr_plural_condition_ty *condition;
     106  };
     107  
     108  struct cldr_plural_rule_list_ty
     109  {
     110    struct cldr_plural_rule_ty **items;
     111    size_t nitems;
     112    size_t nitems_max;
     113  };
     114  
     115  struct cldr_plural_parse_args
     116  {
     117    const char *cp;
     118    const char *cp_end;
     119    struct cldr_plural_rule_list_ty *result;
     120  };
     121  
     122  extern void
     123  cldr_plural_range_free (struct cldr_plural_range_ty *range);
     124  extern void
     125  cldr_plural_range_list_free (struct cldr_plural_range_list_ty *ranges);
     126  extern void
     127  cldr_plural_condition_free (struct cldr_plural_condition_ty *condition);
     128  extern void
     129  cldr_plural_relation_free (struct cldr_plural_relation_ty *relation);
     130  
     131  extern struct cldr_plural_rule_list_ty *
     132  cldr_plural_parse (const char *input);
     133  extern void
     134  cldr_plural_rule_list_free (struct cldr_plural_rule_list_ty *rules);
     135  extern void
     136  cldr_plural_rule_list_print (struct cldr_plural_rule_list_ty *rules, FILE *fp);
     137  
     138  #ifdef __cplusplus
     139  }
     140  #endif
     141  
     142  #endif  /* _CLDR_PLURAL_EXP_H */