tizen 2.3.1 release
[framework/api/base-utils.git] / src / utils_i18n_unormalization.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/unorm2.h>
18 #include <utils_i18n_unormalization.h>
19 #include <utils_i18n_private.h>
20
21 int i18n_unormalization_get_instance ( const char *package_name, const char *name, i18n_unormalization_mode_e mode,
22     i18n_unormalizer_h *normalizer )
23 {
24     i18n_error_code_e err = I18N_ERROR_NONE;
25     *normalizer = unorm2_getInstance(package_name, name, mode, (UErrorCode*)&err);
26     int result = _i18n_error_mapping(err);
27     
28     return result;    
29 }
30
31 int i18n_unormalization_normalize ( i18n_unormalizer_h normalizer, const i18n_uchar *src, int32_t len, i18n_uchar *dest, int32_t capacity, int32_t *len_deststr )
32 {
33     retv_if( normalizer == NULL, I18N_ERROR_INVALID_PARAMETER);
34
35     i18n_error_code_e err = I18N_ERROR_NONE;
36     *len_deststr = unorm2_normalize((UNormalizer2*)normalizer, src, len, dest, capacity, (UErrorCode*)&err);
37     int result = _i18n_error_mapping(err);
38
39     return result;
40 }