summaryrefslogtreecommitdiff
path: root/src/i18n_set.c
blob: a539752255804d6c06734981c5eff737ed009e73 (plain)
    1 #include "i18n_set.h"
    2 
    3 struct i18n_set* i18n_set_new(int type) {
    4   struct i18n_set* out = malloc(sizeof(struct i18n_set));
    5 
    6   out->count = 0;
    7   out->type  = type;
    8   out->next  = NULL;
    9   out->chars[0] = '\0';
   10 
   11   switch(type) {
   12     case I18N_TYPE_ASCII_LOWER:
   13       out->count = i18n_cat_ascii_lower(out->chars);
   14       break;
   15     case I18N_TYPE_ASCII_UPPER:
   16       out->count = i18n_cat_ascii_upper(out->chars);
   17       break;
   18     case I18N_TYPE_ASCII_NUMERALS:
   19       out->count = i18n_cat_ascii_numerals(out->chars);
   20       break;
   21     case I18N_TYPE_ASCII_SYMBOLS:
   22       out->count = i18n_cat_ascii_symbols(out->chars);
   23       break;
   24     case I18N_TYPE_ONE:
   25       out->count = i18n_cat_one(out->chars);
   26       break;
   27     case I18N_TYPE_TWO:
   28       out->count = i18n_cat_two(out->chars);
   29       break;
   30     case I18N_TYPE_THREE:
   31       out->count = i18n_cat_three(out->chars);
   32       break;
   33     case I18N_TYPE_FOUR:
   34       out->count = i18n_cat_four(out->chars);
   35       break;
   36   }
   37 
   38   return out;
   39 }
   40 
   41 
   42 struct i18n_set* i18n_set_add(struct i18n_set* set, int type) {
   43   struct i18n_set* cursor = set;
   44   if(!set)
   45     return i18n_set_new(type);
   46 
   47   while(cursor->next)
   48     cursor = cursor->next;
   49 
   50   cursor->next = i18n_set_new(type);
   51   return cursor->next;
   52 }
   53 
   54 
   55 struct i18n_set* i18n_set_exists(struct i18n_set* set, int type) {
   56   while(set) {
   57     if(set->type == type)
   58       break;
   59     set = set->next;
   60   }
   61   return set;
   62 }
   63 
   64 
   65 struct i18n_set* i18n_set_rm_type(struct i18n_set* set, int type) {
   66   struct i18n_set* cursor = set;
   67   struct i18n_set* prev = NULL;
   68 
   69   while(cursor) {
   70     if(cursor->type == type) {
   71       if(cursor == set)
   72         set = set->next;
   73       else if(!cursor->next)
   74         prev->next = NULL;
   75       else
   76         prev->next = cursor->next;
   77 
   78       free(cursor);
   79     }
   80     prev = cursor;
   81     cursor = cursor->next;
   82   }
   83   return set;
   84 }
   85 
   86 
   87 void i18n_set_dump(struct i18n_set* set) {
   88   struct i18n_set* cursor = set;
   89   unsigned int total = 0;
   90   while(cursor) {
   91     total += cursor->count;
   92     i18n_dump_arr(cursor->chars);
   93     cursor = cursor->next;
   94   }
   95   printf("Total: %u\n\n", total);
   96 }
   97 
   98 
   99 void i18n_set_free(struct i18n_set* set) {
  100   struct i18n_set* next = NULL;
  101 
  102   while(set) {
  103     next = set->next;
  104     free(set);
  105     set = next;
  106   }
  107 }

Generated by cgit