blob: b8646585093af2ed8b93056a5aec8b0c92ed8c12 (
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_rm_type(struct i18n_set* set, int type) {
56 struct i18n_set* cursor = set;
57 struct i18n_set* prev = NULL;
58
59 while(cursor) {
60 if(cursor->type == type) {
61 if(cursor == set)
62 set = set->next;
63 else if(!cursor->next)
64 prev->next = NULL;
65 else
66 prev->next = cursor->next;
67
68 free(cursor);
69 }
70 prev = cursor;
71 cursor = cursor->next;
72 }
73 return set;
74 }
75
76
77 void i18n_set_dump(struct i18n_set* set) {
78 struct i18n_set* cursor = set;
79 while(cursor) {
80 i18n_dump_arr(cursor->chars);
81 cursor = cursor->next;
82 }
83 }
84
85
86 void i18n_set_free(struct i18n_set* set) {
87 struct i18n_set* next = NULL;
88
89 while(set) {
90 next = set->next;
91 free(set);
92 set = next;
93 }
94 }
|