tizen 2.3.1 release
[framework/api/base-utils.git] / src / utils_i18n_ucollator.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/ucol.h>
18 #include <utils_i18n_ucollator.h>
19 #include <utils_i18n_private.h>
20
21 int i18n_ucollator_destroy ( i18n_ucollator_h collator )
22 {
23     retv_if(collator == NULL, I18N_ERROR_INVALID_PARAMETER);
24
25         ucol_close(collator);
26
27         return I18N_ERROR_NONE;
28 }
29
30 int i18n_ucollator_equal ( const i18n_ucollator_h collator, const i18n_uchar *src, int32_t src_len, const i18n_uchar *target, int32_t target_len, i18n_ubool *equal )
31 {
32     retv_if(collator == NULL, I18N_ERROR_INVALID_PARAMETER);
33
34         *equal = ucol_equal(collator, src, src_len, target, target_len);
35
36         return I18N_ERROR_NONE;
37 }
38
39 int i18n_ucollator_create ( const char *locale, i18n_ucollator_h *collator )
40 {
41         retv_if (collator == NULL, I18N_ERROR_INVALID_PARAMETER);
42
43         i18n_error_code_e err = I18N_ERROR_NONE;
44         *collator = ucol_open(locale, (UErrorCode*)&err);
45         int result = _i18n_error_mapping(err);
46
47         return result;
48 }
49
50 int i18n_ucollator_set_attribute( i18n_ucollator_h collator, i18n_ucollator_attribute_e attr, i18n_ucollator_attribute_value_e val )
51 {
52     retv_if(collator == NULL, I18N_ERROR_INVALID_PARAMETER);
53
54         i18n_error_code_e err = I18N_ERROR_NONE;
55         ucol_setAttribute(collator, attr, val, (UErrorCode*)&err);
56         int result = _i18n_error_mapping(err);
57
58         return result;
59 }
60
61 int i18n_ucollator_set_strength ( i18n_ucollator_h collator, i18n_ucollator_strength_e strength )
62 {
63     retv_if(collator == NULL, I18N_ERROR_INVALID_PARAMETER);
64
65         ucol_setStrength(collator, strength);
66
67         return I18N_ERROR_NONE;
68 }
69
70 int i18n_ucollator_str_collator ( const i18n_ucollator_h collator, const i18n_uchar *src, int32_t src_len, const i18n_uchar *target, int32_t target_len, i18n_ucollator_result_e *result )
71 {
72     retv_if(collator == NULL, I18N_ERROR_INVALID_PARAMETER);
73
74         *result = ucol_strcoll(collator, src, src_len, target, target_len);
75
76         return I18N_ERROR_NONE;
77 }