tizen 2.3.1 release
[framework/api/base-utils.git] / src / utils_i18n_uset.c
1 /*
2  * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  *    Licensed under the Apache License, Version 2.0 (the "License");
5  *    you may not use this file except in compliance with the License.
6  *    You may obtain a copy of the License at
7  *
8  *        http://www.apache.org/licenses/LICENSE-2.0
9  *
10  *    Unless required by applicable law or agreed to in writing, software
11  *    distributed under the License is distributed on an "AS IS" BASIS,
12  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *    See the License for the specific language governing permissions and
14  *    limitations under the License.
15  */
16
17 #include <unicode/usearch.h>
18 #include <unicode/uchar.h>
19 #include <utils_i18n_uset.h>
20 #include <utils_i18n_private.h>
21
22 int i18n_uset_create_empty ( i18n_uset_h* set )
23 {
24     if(set == NULL)
25     {
26         return I18N_ERROR_INVALID_PARAMETER;
27     }
28     *set = (i18n_uset_h)uset_openEmpty();
29     return I18N_ERROR_NONE;
30 }
31
32 int i18n_uset_create ( i18n_uchar32 start, i18n_uchar32 end, i18n_uset_h *set)
33 {
34     if(set == NULL)
35     {
36         return I18N_ERROR_INVALID_PARAMETER;
37     }
38     *set = (i18n_uset_h)uset_open(start, end);
39     return I18N_ERROR_NONE;
40 }
41
42 int i18n_uset_create_pattern ( const i18n_uchar *pattern, int32_t pattern_length, i18n_uset_h *set )
43 {
44     UErrorCode icu_error = U_ZERO_ERROR;
45     i18n_error_code_e i18n_error;
46
47     if (pattern == NULL || pattern_length < -1 || set == NULL) {
48         return I18N_ERROR_INVALID_PARAMETER;
49     }
50
51     *set = (i18n_uset_h)uset_openPattern(pattern, pattern_length, &icu_error);
52     ERR("Error code: %d", icu_error);
53     ERR_MAPPING(icu_error, i18n_error);
54     return i18n_error;
55 }
56
57 int i18n_uset_create_pattern_options ( const i18n_uchar *pattern, int32_t pattern_length, uint32_t options, i18n_uset_h *set )
58 {
59     UErrorCode icu_error = U_ZERO_ERROR;
60     i18n_error_code_e i18n_error;
61
62     if (pattern == NULL || pattern_length < -1 || set == NULL) {
63         return I18N_ERROR_INVALID_PARAMETER;
64     }
65     if ((options != I18N_USET_IGNORE_SPACE) && (options != I18N_USET_CASE_INSENSITIVE)) {
66         return I18N_ERROR_INVALID_PARAMETER;
67     }
68
69     *set = (i18n_uset_h)uset_openPatternOptions(pattern, pattern_length, options, &icu_error);
70     ERR("Error code: %d", icu_error);
71     ERR_MAPPING(icu_error, i18n_error);
72     return i18n_error;
73 }
74
75 int i18n_uset_destroy ( i18n_uset_h set )
76 {
77     if (set == NULL) {
78         return I18N_ERROR_INVALID_PARAMETER;
79     }
80     uset_close((USet*)set);
81     return I18N_ERROR_NONE;
82 }
83
84 int i18n_uset_clone ( const i18n_uset_h set, i18n_uset_h *set_clone )
85 {
86     if (set == NULL || set_clone == NULL) {
87         return I18N_ERROR_INVALID_PARAMETER;
88     }
89     *set_clone = (i18n_uset_h)uset_clone((const USet*)set);
90     return I18N_ERROR_NONE;
91 }
92
93 i18n_ubool i18n_uset_is_frozen ( const i18n_uset_h set )
94 {
95     set_last_result(I18N_ERROR_NONE);
96     if (set == NULL) {
97         set_last_result(I18N_ERROR_INVALID_PARAMETER);
98         return false;
99     }
100     return uset_isFrozen((const USet*)set);
101 }
102
103 int i18n_uset_freeze ( i18n_uset_h set )
104 {
105     if (set == NULL) {
106         return I18N_ERROR_INVALID_PARAMETER;
107     }
108     uset_freeze((USet*)set);
109     return I18N_ERROR_NONE;
110 }
111
112 int i18n_uset_clone_as_thawed ( const i18n_uset_h set, i18n_uset_h *set_copy )
113 {
114     if (set == NULL || set_copy == NULL) {
115         return I18N_ERROR_INVALID_PARAMETER;
116     }
117     *set_copy = (i18n_uset_h)uset_cloneAsThawed((const USet*)set);
118     return I18N_ERROR_NONE;
119 }
120
121 int i18n_uset_set ( i18n_uset_h set, i18n_uchar32 start, i18n_uchar32 end )
122 {
123     if (set == NULL) {
124         return I18N_ERROR_INVALID_PARAMETER;
125     }
126     uset_set((USet*)set, start, end);
127     return I18N_ERROR_NONE;
128 }
129
130 int32_t i18n_uset_apply_pattern ( i18n_uset_h set, const i18n_uchar *pattern, int32_t pattern_length, uint32_t options )
131 {
132     if (set == NULL ) {
133        set_last_result(I18N_ERROR_INVALID_PARAMETER);
134        return 0;
135     }
136     if (pattern == NULL || pattern_length < -1) {
137         set_last_result(I18N_ERROR_INVALID_PARAMETER);
138         return 0;
139     }
140     if (options != I18N_USET_IGNORE_SPACE && options != I18N_USET_CASE_INSENSITIVE) {
141         set_last_result(I18N_ERROR_INVALID_PARAMETER);
142         return 0;
143     }
144
145     UErrorCode icu_error = U_ZERO_ERROR;
146     i18n_error_code_e i18n_error;
147
148     int32_t result_uset_applyPattern = uset_applyPattern ((USet*)set, pattern, pattern_length, options, &icu_error);
149     ERR("Error code: %d", icu_error);
150     ERR_MAPPING(icu_error, i18n_error);
151
152     set_last_result(i18n_error);
153     return result_uset_applyPattern;
154 }
155
156 int i18n_uset_apply_int_property_value ( i18n_uset_h set, i18n_uchar_uproperty_e prop, int32_t value )
157 {
158     if (set == NULL) {
159        return I18N_ERROR_INVALID_PARAMETER;
160     }
161     if ((prop < I18N_UCHAR_INT_START || prop > I18N_UCHAR_INT_LIMIT-1) &&
162             (prop < I18N_UCHAR_MASK_START || prop > I18N_UCHAR_MASK_LIMIT-1)) {
163        return I18N_ERROR_INVALID_PARAMETER;
164     }
165     if (prop != I18N_UCHAR_GENERAL_CATEGORY_MASK &&
166         (value <= I18N_UCHAR_INVALID_CODE ||
167         value >= I18N_UCHAR_OTHER_PROPERTY_LIMIT)) {
168        return I18N_ERROR_INVALID_PARAMETER;
169     }
170
171     UErrorCode icu_error = U_ZERO_ERROR;
172     i18n_error_code_e i18n_error;
173
174     uset_applyIntPropertyValue((USet *)set, prop, value, &icu_error);
175     ERR("Error code: %d", icu_error);
176     ERR_MAPPING(icu_error, i18n_error);
177
178     return i18n_error;
179 }
180
181 int i18n_uset_apply_property_alias ( i18n_uset_h set, const i18n_uchar *prop, int32_t prop_length, const i18n_uchar *value, int32_t value_length )
182 {
183     if (set == NULL) {
184        return I18N_ERROR_INVALID_PARAMETER;
185     }
186     if (prop == NULL || prop_length < -1) {
187         return I18N_ERROR_INVALID_PARAMETER;
188     }
189     if (value == NULL || value_length < -1) {
190         return I18N_ERROR_INVALID_PARAMETER;
191     }
192
193     UErrorCode icu_error = U_ZERO_ERROR;
194     i18n_error_code_e i18n_error;
195
196     uset_applyPropertyAlias ((USet*)set, prop, prop_length, value, value_length, &icu_error);
197     ERR("Error code: %d", icu_error);
198     ERR_MAPPING(icu_error, i18n_error);
199
200     return i18n_error;
201
202 }
203
204 i18n_ubool i18n_uset_resembles_pattern ( const i18n_uchar *pattern, int32_t pattern_length, int32_t pos )
205 {
206     if (pattern == NULL || pattern_length < -1 || pos < 0) {
207        set_last_result(I18N_ERROR_INVALID_PARAMETER);
208        return false;
209     }
210     set_last_result(I18N_ERROR_NONE);
211     return uset_resemblesPattern(pattern, pattern_length, pos);
212 }
213
214 int32_t i18n_uset_to_pattern ( const i18n_uset_h set, i18n_uchar *result, int32_t result_capacity, i18n_ubool escape_unprintable )
215 {
216     if (set == NULL || result_capacity < 0) {
217        set_last_result(I18N_ERROR_INVALID_PARAMETER);
218        return 0;
219     }
220
221     UErrorCode icu_error = U_ZERO_ERROR;
222     i18n_error_code_e i18n_error;
223
224     int32_t result_uset_toPattern = uset_toPattern((const USet*)set, result, result_capacity, escape_unprintable, &icu_error);
225     ERR("Error code: %d", icu_error);
226     ERR_MAPPING(icu_error, i18n_error);
227
228     set_last_result(i18n_error);
229     return result_uset_toPattern;
230 }
231
232 int i18n_uset_add ( i18n_uset_h set, i18n_uchar32 character )
233 {
234     if (set == NULL) {
235         return I18N_ERROR_INVALID_PARAMETER;
236     }
237     uset_add ((USet*)set, character);
238     return I18N_ERROR_NONE;
239 }
240
241 int i18n_uset_add_all ( i18n_uset_h set, const i18n_uset_h additional_set )
242 {
243     if (set == NULL || additional_set == NULL) {
244         return I18N_ERROR_INVALID_PARAMETER;
245     }
246     uset_addAll((USet *)set, (const USet*)additional_set);
247     return I18N_ERROR_NONE;
248 }
249
250 int i18n_uset_add_range ( i18n_uset_h set, i18n_uchar32 start, i18n_uchar32 end )
251 {
252     if (set == NULL) {
253         return I18N_ERROR_INVALID_PARAMETER;
254     }
255     uset_addRange((USet*)set, start, end);
256     return I18N_ERROR_NONE;
257 }
258
259 int i18n_uset_add_string ( i18n_uset_h set, const i18n_uchar *str, int32_t str_len )
260 {
261     if (set == NULL) {
262         return I18N_ERROR_INVALID_PARAMETER;
263     }
264     if (str == NULL || str_len < -1) {
265        return I18N_ERROR_INVALID_PARAMETER;
266     }
267     uset_addString((USet*)set, str, str_len);
268     return I18N_ERROR_NONE;
269 }
270
271 int i18n_uset_add_all_code_points ( i18n_uset_h set, const i18n_uchar *str, int32_t str_len )
272 {
273     if(set == NULL) {
274         return I18N_ERROR_INVALID_PARAMETER;
275     }
276     if (str == NULL || str_len < -1) {
277        return I18N_ERROR_INVALID_PARAMETER;
278     }
279     uset_addAllCodePoints((USet*)set, str, str_len);
280     return I18N_ERROR_NONE;
281 }
282
283 int i18n_uset_remove ( i18n_uset_h set, i18n_uchar32 character )
284 {
285     if (set == NULL) {
286         return I18N_ERROR_INVALID_PARAMETER;
287     }
288     uset_remove ((USet*)set, character);
289     return I18N_ERROR_NONE;
290 }
291
292 int i18n_uset_remove_range ( i18n_uset_h set, i18n_uchar32 start, i18n_uchar32 end )
293 {
294     if (set == NULL) {
295         return I18N_ERROR_INVALID_PARAMETER;
296     }
297     uset_removeRange ((USet*)set, start, end);
298     return I18N_ERROR_NONE;
299 }
300
301 int i18n_uset_remove_string ( i18n_uset_h set, const i18n_uchar *str, int32_t str_len )
302 {
303     if (set == NULL) {
304         return I18N_ERROR_INVALID_PARAMETER;
305     }
306     if (str == NULL || str_len < -1) {
307        return I18N_ERROR_INVALID_PARAMETER;
308     }
309     uset_removeString((USet*)set, str, str_len);
310     return I18N_ERROR_NONE;
311 }
312
313 int i18n_uset_remove_all ( i18n_uset_h set, const i18n_uset_h remove_set )
314 {
315     if (set == NULL || remove_set == NULL) {
316         return I18N_ERROR_INVALID_PARAMETER;
317     }
318     uset_removeAll((USet*)set, (const USet*)remove_set);
319     return I18N_ERROR_NONE;
320 }
321
322 int i18n_uset_retain ( i18n_uset_h set, i18n_uchar32 start, i18n_uchar32 end )
323 {
324     if (set == NULL) {
325         return I18N_ERROR_INVALID_PARAMETER;
326     }
327      uset_retain((USet*)set, start, end);
328      return I18N_ERROR_NONE;
329 }
330
331 int i18n_uset_retain_all ( i18n_uset_h set, const i18n_uset_h retain )
332 {
333     if (set == NULL || retain == NULL) {
334         return I18N_ERROR_INVALID_PARAMETER;
335     }
336     uset_retainAll ((USet*)set, (const USet*)retain);
337     return I18N_ERROR_NONE;
338 }
339
340 int i18n_uset_compact ( i18n_uset_h set )
341 {
342     if (set == NULL) {
343         return I18N_ERROR_INVALID_PARAMETER;
344     }
345     uset_compact((USet*)set);
346     return I18N_ERROR_NONE;
347 }
348
349 int i18n_uset_complement ( i18n_uset_h set )
350 {
351     if (set == NULL) {
352         return I18N_ERROR_INVALID_PARAMETER;
353     }
354     uset_complement((USet*)set);
355     return I18N_ERROR_NONE;
356 }
357
358 int i18n_uset_complement_all ( i18n_uset_h set, const i18n_uset_h complement )
359 {
360     if (set == NULL || set == complement || complement == NULL) {
361         return I18N_ERROR_INVALID_PARAMETER;
362     }
363     uset_complementAll((USet*)set, (const USet*)complement);
364     return I18N_ERROR_NONE;
365 }
366
367 int i18n_uset_clear ( i18n_uset_h set )
368 {
369     if (set == NULL) {
370         return I18N_ERROR_INVALID_PARAMETER;
371     }
372     uset_clear((USet*)set);
373     return I18N_ERROR_NONE;
374 }
375
376 int i18n_uset_destroy_over ( i18n_uset_h set, int32_t attributes )
377 {
378     if (set == NULL) {
379         return I18N_ERROR_INVALID_PARAMETER;
380     }
381     uset_closeOver((USet*)set, attributes);
382     return I18N_ERROR_NONE;
383 }
384
385 int i18n_uset_remove_all_strings ( i18n_uset_h set )
386 {
387     if (set == NULL) {
388         return I18N_ERROR_INVALID_PARAMETER;
389     }
390     uset_removeAllStrings((USet*)set);
391     return I18N_ERROR_NONE;
392 }
393
394 i18n_ubool i18n_uset_is_empty ( const i18n_uset_h set )
395 {
396     if (set == NULL) {
397         set_last_result(I18N_ERROR_INVALID_PARAMETER);
398         return false;
399     }
400     set_last_result(I18N_ERROR_NONE);
401     return uset_isEmpty((const USet*)set);
402 }
403
404 i18n_ubool i18n_uset_contains ( const i18n_uset_h set, i18n_uchar32 character )
405 {
406     if (set == NULL) {
407         set_last_result(I18N_ERROR_INVALID_PARAMETER);
408         return false;
409     }
410     set_last_result(I18N_ERROR_NONE);
411     return uset_contains((const USet*)set, character);
412 }
413
414 i18n_ubool i18n_uset_contains_range ( const i18n_uset_h set, i18n_uchar32 start, i18n_uchar32 end )
415 {
416     if (set == NULL) {
417         set_last_result(I18N_ERROR_INVALID_PARAMETER);
418         return false;
419     }
420     set_last_result(I18N_ERROR_NONE);
421     return uset_containsRange((const USet*)set, start, end);
422 }
423
424 i18n_ubool i18n_uset_contains_string ( const i18n_uset_h set, const i18n_uchar *str, int32_t str_len )
425 {
426     if (set == NULL) {
427         set_last_result(I18N_ERROR_INVALID_PARAMETER);
428         return false;
429     }
430     if (str == NULL || str_len < -1) {
431        set_last_result(I18N_ERROR_INVALID_PARAMETER);
432        return false;
433     }
434     set_last_result(I18N_ERROR_NONE);
435     return uset_containsString((const USet*)set, str, str_len);
436 }
437
438 int32_t i18n_uset_index_of ( const i18n_uset_h set, i18n_uchar32 character )
439 {
440     if (set == NULL) {
441         set_last_result(I18N_ERROR_INVALID_PARAMETER);
442         return 0;
443     }
444     set_last_result(I18N_ERROR_NONE);
445     return uset_indexOf((const USet*)set, character);
446 }
447
448 i18n_uchar32 i18n_uset_char_at ( const i18n_uset_h set, int32_t char_index )
449 {
450     if (set == NULL || (char_index < 0 || char_index > uset_size((const USet*)set)-1)) {
451         set_last_result(I18N_ERROR_INVALID_PARAMETER);
452         return 0x0;
453     }
454     set_last_result(I18N_ERROR_NONE);
455     return uset_charAt((const USet*)set, char_index);
456 }
457
458 int32_t i18n_uset_size ( const i18n_uset_h set )
459 {
460     if (set == NULL) {
461         set_last_result(I18N_ERROR_INVALID_PARAMETER);
462         return 0;
463     }
464     set_last_result(I18N_ERROR_NONE);
465     return uset_size((const USet*)set);
466 }
467
468 int32_t i18n_uset_get_item_count ( const i18n_uset_h set )
469 {
470     if (set == NULL) {
471         set_last_result(I18N_ERROR_INVALID_PARAMETER);
472         return 0;
473     }
474     set_last_result(I18N_ERROR_NONE);
475     return uset_getItemCount((const USet*)set);
476 }
477
478 int32_t i18n_uset_get_item ( const i18n_uset_h set, int32_t item_index, i18n_uchar32 *start, i18n_uchar32 *end,
479         i18n_uchar *str, int32_t str_capacity )
480 {
481     if (set == NULL || (item_index < 0 || item_index > uset_getItemCount((const USet*)set)-1) || start == NULL || end == NULL) {
482        set_last_result(I18N_ERROR_INVALID_PARAMETER);
483        return 0;
484     }
485     if ((str == NULL && str_capacity != 0) || (str != NULL && str_capacity < 0)) {
486        set_last_result(I18N_ERROR_INVALID_PARAMETER);
487        return 0;
488     }
489
490     UErrorCode icu_error = U_ZERO_ERROR;
491     i18n_error_code_e i18n_error;
492
493     int32_t result_uset_getItem = uset_getItem((const USet*)set, item_index, start, end, str, str_capacity, &icu_error);
494     ERR("Error code: %d", icu_error);
495     ERR_MAPPING(icu_error, i18n_error);
496
497     set_last_result(i18n_error);
498     return result_uset_getItem;
499 }
500
501 i18n_ubool i18n_uset_contains_all ( const i18n_uset_h set1, const i18n_uset_h set2 )
502 {
503     if (set1 == NULL || set2 == NULL) {
504         set_last_result(I18N_ERROR_INVALID_PARAMETER);
505         return false;
506     }
507     set_last_result(I18N_ERROR_NONE);
508     return uset_containsAll((const USet*)set1, (const USet*)set2);
509 }
510
511 i18n_ubool i18n_uset_contains_all_code_points ( const i18n_uset_h set, const i18n_uchar *str, int32_t str_len )
512 {
513     if (set == NULL) {
514         set_last_result(I18N_ERROR_INVALID_PARAMETER);
515         return false;
516     }
517     if (str == NULL || str_len < -1) {
518        set_last_result(I18N_ERROR_INVALID_PARAMETER);
519        return false;
520     }
521     set_last_result(I18N_ERROR_NONE);
522     return uset_containsAllCodePoints((const USet*)set, str, str_len);
523 }
524
525 i18n_ubool i18n_uset_contains_none ( const i18n_uset_h set1, const i18n_uset_h set2 )
526 {
527     if (set1 == NULL || set2 == NULL) {
528         set_last_result(I18N_ERROR_INVALID_PARAMETER);
529         return false;
530     }
531     set_last_result(I18N_ERROR_NONE);
532     return uset_containsNone((const USet*)set1, (const USet*)set2);
533 }
534
535 i18n_ubool i18n_uset_contains_some ( const i18n_uset_h set1, const i18n_uset_h set2 )
536 {
537     if (set1 == NULL || set2 == NULL) {
538         set_last_result(I18N_ERROR_INVALID_PARAMETER);
539         return false;
540     }
541     set_last_result(I18N_ERROR_NONE);
542     return uset_containsSome((const USet*)set1, (const USet*)set2);
543 }
544
545 int32_t i18n_uset_span ( const i18n_uset_h set, const i18n_uchar *str, int32_t length, i18n_uset_span_condition_e span_condition )
546 {
547     if (set == NULL) {
548         set_last_result(I18N_ERROR_INVALID_PARAMETER);
549         return 0;
550     }
551     if (str == NULL || length < -1) {
552        set_last_result(I18N_ERROR_INVALID_PARAMETER);
553        return 0;
554     }
555     set_last_result(I18N_ERROR_NONE);
556     return uset_span((const USet*)set, str, length, (USetSpanCondition) span_condition);
557 }
558
559 int32_t i18n_uset_span_back ( const i18n_uset_h set, const i18n_uchar *str, int32_t length, i18n_uset_span_condition_e span_condition )
560 {
561     if (set == NULL) {
562         set_last_result(I18N_ERROR_INVALID_PARAMETER);
563         return 0;
564     }
565     if (str == NULL || length < -1) {
566        set_last_result(I18N_ERROR_INVALID_PARAMETER);
567        return 0;
568     }
569     if (span_condition < I18N_USET_SPAN_NOT_CONTAINED ||
570         span_condition > I18N_USET_SPAN_CONDITION_COUNT) {
571         set_last_result(I18N_ERROR_INVALID_PARAMETER);
572         return 0;
573     }
574     set_last_result(I18N_ERROR_NONE);
575     return uset_spanBack((const USet*)set, str, length, (USetSpanCondition) span_condition);
576 }
577
578 int32_t i18n_uset_span_utf8 ( const i18n_uset_h set, const char *str, int32_t length, i18n_uset_span_condition_e span_condition )
579 {
580     if (set == NULL) {
581         set_last_result(I18N_ERROR_INVALID_PARAMETER);
582         return 0;
583     }
584     if (str == NULL || length < -1) {
585        set_last_result(I18N_ERROR_INVALID_PARAMETER);
586        return 0;
587     }
588     if (span_condition < I18N_USET_SPAN_NOT_CONTAINED ||
589         span_condition > I18N_USET_SPAN_CONDITION_COUNT) {
590         set_last_result(I18N_ERROR_INVALID_PARAMETER);
591         return 0;
592     }
593     set_last_result(I18N_ERROR_NONE);
594     return uset_spanUTF8((const USet*)set, str, length, (USetSpanCondition) span_condition);
595 }
596
597 int32_t i18n_uset_span_back_utf8 ( const i18n_uset_h set, const char *str, int32_t length, i18n_uset_span_condition_e span_condition )
598 {
599     if(set == NULL) {
600         set_last_result(I18N_ERROR_INVALID_PARAMETER);
601         return 0;
602     }
603     if (str == NULL || length < -1) {
604        set_last_result(I18N_ERROR_INVALID_PARAMETER);
605        return 0;
606     }
607     if (span_condition < I18N_USET_SPAN_NOT_CONTAINED ||
608         span_condition > I18N_USET_SPAN_CONDITION_COUNT) {
609         set_last_result(I18N_ERROR_INVALID_PARAMETER);
610         return 0;
611     }
612     set_last_result(I18N_ERROR_NONE);
613     return uset_spanBackUTF8((const USet*)set, str, length, (USetSpanCondition) span_condition);
614 }
615
616 i18n_ubool i18n_uset_equals ( const i18n_uset_h set1, const i18n_uset_h set2 )
617 {
618     if (set1 == NULL || set2 == NULL) {
619         set_last_result(I18N_ERROR_INVALID_PARAMETER);
620         return false;
621     }
622     set_last_result(I18N_ERROR_NONE);
623     return uset_equals((const USet*)set1, (const USet*)set2);
624 }
625
626 int32_t i18n_uset_serialize ( const i18n_uset_h set, uint16_t *dest, int32_t dest_capacity )
627 {
628     i18n_error_code_e i18n_error;
629
630     if (set == NULL) {
631        set_last_result(I18N_ERROR_INVALID_PARAMETER);
632        return 0;
633     }
634     if (dest == NULL || dest_capacity < 0) {
635        set_last_result(I18N_ERROR_INVALID_PARAMETER);
636        return 0;
637     }
638
639     UErrorCode icu_error = U_ZERO_ERROR;
640     int32_t result_uset_serialize =  uset_serialize((const USet*)set, dest, dest_capacity, &icu_error);
641     ERR("Error code: %d", icu_error);
642     ERR_MAPPING(icu_error, i18n_error);
643
644     set_last_result(i18n_error);
645     return result_uset_serialize;
646 }
647
648 i18n_ubool i18n_uset_get_serialized_set ( const uint16_t *src, int32_t src_length, i18n_userialized_set_s *fill_set )
649 {
650     if (src == NULL || src_length < 0) {
651        set_last_result(I18N_ERROR_INVALID_PARAMETER);
652        return 0;
653     }
654     set_last_result(I18N_ERROR_NONE);
655     return uset_getSerializedSet((USerializedSet*)fill_set, src, src_length);
656 }
657
658 int i18n_uset_set_serialized_to_one ( i18n_uchar32 character, i18n_userialized_set_s *fill_set )
659 {
660     if (fill_set == NULL) {
661        return I18N_ERROR_INVALID_PARAMETER;
662     }
663     uset_setSerializedToOne((USerializedSet*)fill_set, character);
664     return I18N_ERROR_NONE;
665 }
666
667 i18n_ubool i18n_uset_serialized_contains ( const i18n_userialized_set_s *set, i18n_uchar32 character )
668 {
669     if (set == NULL) {
670        set_last_result(I18N_ERROR_INVALID_PARAMETER);
671        return 0;
672     }
673     set_last_result(I18N_ERROR_NONE);
674     return uset_serializedContains((const USerializedSet*)set, character);
675 }
676
677 int32_t i18n_uset_get_serialized_range_count ( const i18n_userialized_set_s *set )
678 {
679     if (set == NULL) {
680        set_last_result(I18N_ERROR_INVALID_PARAMETER);
681        return 0;
682     }
683     set_last_result(I18N_ERROR_NONE);
684     return uset_getSerializedRangeCount((const USerializedSet*)set);
685 }
686
687 i18n_ubool i18n_uset_get_serialized_range ( const i18n_userialized_set_s *set, int32_t range_index, i18n_uchar32 *p_start, i18n_uchar32 *p_end )
688 {
689     if (set == NULL) {
690        set_last_result(I18N_ERROR_INVALID_PARAMETER);
691        return false;
692     }
693     if (range_index < 0 || range_index > uset_getSerializedRangeCount((const USerializedSet*)set)-1) {
694        set_last_result(I18N_ERROR_INVALID_PARAMETER);
695        return false;
696     }
697     set_last_result(I18N_ERROR_NONE);
698     return  uset_getSerializedRange((const USerializedSet*)set, range_index, p_start, p_end);
699 }