From: Hyunjee Kim Date: Tue, 2 Jul 2019 01:17:31 +0000 (+0900) Subject: code refactoring for reducing cyclomatic complexity X-Git-Tag: submit/tizen/20190703.000555^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=85612f3afbd26e691289c9abde6b1c2deadd4890;p=platform%2Fcore%2Fapi%2Fbase-utils.git code refactoring for reducing cyclomatic complexity Change-Id: I9c850c9ade1c684391da91217a2ba6531e62b85a Signed-off-by: Hyunjee Kim --- diff --git a/packaging/capi-base-utils.spec b/packaging/capi-base-utils.spec index 22646ce..154fec0 100755 --- a/packaging/capi-base-utils.spec +++ b/packaging/capi-base-utils.spec @@ -1,6 +1,6 @@ Name: capi-base-utils Summary: Base Utils -Version: 3.1.4 +Version: 3.1.5 Release: 1 Group: Base License: Apache-2.0 and ICU diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index dc2c980..92b3655 100755 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -12,7 +12,7 @@ INCLUDE_DIRECTORIES( ) SET(BASEUTILS_SRCS - utils_i18n_private.c + utils_i18n_private.cpp utils_i18n_uchar.c utils_i18n_ucollator.c utils_i18n_unormalization.c diff --git a/src/include/utils_i18n_private.h b/src/include/utils_i18n_private.h index 320c29f..9b9cd40 100644 --- a/src/include/utils_i18n_private.h +++ b/src/include/utils_i18n_private.h @@ -80,18 +80,14 @@ extern "C" { } \ } while (0); -#define ERR_MAPPING_REVERSE(BASE_UTILS_ERROR, ICU_ERROR) ICU_ERROR = \ - (UErrorCode)_i18n_error_mapping_reverse((int)BASE_UTILS_ERROR) - -#define ERR_MAPPING(ICU_ERROR, BASE_UTILS_ERROR) BASE_UTILS_ERROR = \ - (i18n_error_code_e)_i18n_error_mapping((int)ICU_ERROR) #define COPY_STR(dst, src, dst_len) do { \ strncpy((dst), (src), (dst_len)); \ (dst)[(dst_len) - 1] = '\0'; \ } while (0) +#define ERR_MAPPING(ICU_ERROR, BASE_UTILS_ERROR) BASE_UTILS_ERROR = \ + (i18n_error_code_e)_i18n_error_mapping((int)ICU_ERROR) int _i18n_error_mapping(int err); -int _i18n_error_mapping_reverse(int err); #ifdef __cplusplus } diff --git a/src/utils_i18n_private.c b/src/utils_i18n_private.c deleted file mode 100644 index 37f5a26..0000000 --- a/src/utils_i18n_private.c +++ /dev/null @@ -1,601 +0,0 @@ -/* - * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include - -int _i18n_error_mapping(int err) -{ - if (err == U_STRING_NOT_TERMINATED_WARNING) - return I18N_WARNING_STRING_NOT_TERMINATED; - else if (err == U_SORT_KEY_TOO_SHORT_WARNING) - return I18N_WARNING_SORT_KEY_TOO_SHORT; - else if (err <= U_ZERO_ERROR) - return I18N_ERROR_NONE; - - switch (err) { - case U_ILLEGAL_ARGUMENT_ERROR: - return I18N_ERROR_INVALID_PARAMETER; - - case U_MISSING_RESOURCE_ERROR: - return I18N_ERROR_MISSING_RESOURCE; - - case U_INVALID_FORMAT_ERROR: - return I18N_ERROR_INVALID_FORMAT; - - case U_FILE_ACCESS_ERROR: - return I18N_ERROR_FILE_ACCESS; - - case U_INTERNAL_PROGRAM_ERROR: - return I18N_ERROR_INTERNAL_PROGRAM; - - case U_MESSAGE_PARSE_ERROR: - return I18N_ERROR_MESSAGE_PARSE; - - case U_MEMORY_ALLOCATION_ERROR: - return I18N_ERROR_OUT_OF_MEMORY; - - case U_INDEX_OUTOFBOUNDS_ERROR: - return I18N_ERROR_INDEX_OUTOFBOUNDS; - - case U_PARSE_ERROR: - return I18N_ERROR_PARSE; - - case U_INVALID_CHAR_FOUND: - return I18N_ERROR_INVALID_CHAR_FOUND; - - case U_TRUNCATED_CHAR_FOUND: - return I18N_ERROR_TRUNCATED_CHAR_FOUND; - - case U_ILLEGAL_CHAR_FOUND: - return I18N_ERROR_ILLEGAL_CHAR_FOUND; - - case U_INVALID_TABLE_FORMAT: - return I18N_ERROR_INVALID_TABLE_FORMAT; - - case U_INVALID_TABLE_FILE: - return I18N_ERROR_INVALID_TABLE_FILE; - - case U_BUFFER_OVERFLOW_ERROR: - return I18N_ERROR_BUFFER_OVERFLOW; - - case U_UNSUPPORTED_ERROR: - return I18N_ERROR_NOT_SUPPORTED; - - case U_RESOURCE_TYPE_MISMATCH: - return I18N_ERROR_RESOURCE_TYPE_MISMATCH; - - case U_ILLEGAL_ESCAPE_SEQUENCE: - return I18N_ERROR_ILLECAL_ESCAPE_SEQUENCE; - - case U_UNSUPPORTED_ESCAPE_SEQUENCE: - return I18N_ERROR_UNSUPPORTED_ESCAPE_SEQUENCE; - - case U_NO_SPACE_AVAILABLE: - return I18N_ERROR_NO_SPACE_AVAILABLE; - - case U_CE_NOT_FOUND_ERROR: - return I18N_ERROR_CE_NOT_FOUND; - - case U_PRIMARY_TOO_LONG_ERROR: - return I18N_ERROR_PRIMARY_TOO_LONG; - - case U_STATE_TOO_OLD_ERROR: - return I18N_ERROR_STATE_TOO_OLD; - - case U_TOO_MANY_ALIASES_ERROR: - return I18N_ERROR_TOO_MANY_ALIASES; - - case U_ENUM_OUT_OF_SYNC_ERROR: - return I18N_ERROR_ENUM_OUT_OF_SYNC; - - case U_INVARIANT_CONVERSION_ERROR: - return I18N_ERROR_INVARIANT_CONVERSION; - - case U_INVALID_STATE_ERROR: - return I18N_ERROR_INVALID_STATE; - - case U_COLLATOR_VERSION_MISMATCH: - return I18N_ERROR_COLLATOR_VERSION_MISMATCH; - - case U_USELESS_COLLATOR_ERROR: - return I18N_ERROR_USELESS_COLLATOR; - - case U_NO_WRITE_PERMISSION: - return I18N_ERROR_NO_WRITE_PERMISSION; - - case U_MALFORMED_SET: - return I18N_ERROR_MALFORMED_SET; - - case U_IDNA_STD3_ASCII_RULES_ERROR: - return I18N_ERROR_STD3_ASCII_RULES; - - case U_IDNA_UNASSIGNED_ERROR: - return I18N_ERROR_UNASSIGNED; - - case U_BAD_VARIABLE_DEFINITION: - return I18N_ERROR_BAD_VARIABLE_DEFINITION; - - case U_MALFORMED_RULE: - return I18N_ERROR_MALFORMED_RULE; - - case U_MALFORMED_UNICODE_ESCAPE: - return I18N_ERROR_MALFORMED_UNICODE_ESCAPE; - - case U_MALFORMED_VARIABLE_DEFINITION: - return I18N_ERROR_MALFORMED_VARIABLE_DEFINITION; - - case U_MALFORMED_VARIABLE_REFERENCE: - return I18N_ERROR_MALFORMED_VARIABLE_REFERENCE; - - case U_MISPLACED_ANCHOR_START: - return I18N_ERROR_MISPLACED_ANCHOR_START; - - case U_MISPLACED_CURSOR_OFFSET: - return I18N_ERROR_MISPLACED_CURSOR_OFFSET; - - case U_MISPLACED_QUANTIFIER: - return I18N_ERROR_MISPLACED_QUANTIFIER; - - case U_MISSING_OPERATOR: - return I18N_ERROR_MISSING_OPERATOR; - - case U_MULTIPLE_ANTE_CONTEXTS: - return I18N_ERROR_MULTIPLE_ANTE_CONTEXTS; - - case U_MULTIPLE_CURSORS: - return I18N_ERROR_MULTIPLE_CURSORS; - - case U_MULTIPLE_POST_CONTEXTS: - return I18N_ERROR_MULTIPLE_POST_CONTEXTS; - - case U_TRAILING_BACKSLASH: - return I18N_ERROR_TRAILING_BACKSLASH; - - case U_UNDEFINED_SEGMENT_REFERENCE: - return I18N_ERROR_UNDEFINED_SEGMENT_REFERENCE; - - case U_UNDEFINED_VARIABLE: - return I18N_ERROR_UNDEFINED_VARIABLE; - - case U_UNQUOTED_SPECIAL: - return I18N_ERROR_UNQUOTED_SPECIAL; - - case U_UNTERMINATED_QUOTE: - return I18N_ERROR_UNTERMINATED_QUOTE; - - case U_RULE_MASK_ERROR: - return I18N_ERROR_RULE_MASK; - - case U_MISPLACED_COMPOUND_FILTER: - return I18N_ERROR_MISPLACED_COMPOUND_FILTER; - - case U_MULTIPLE_COMPOUND_FILTERS: - return I18N_ERROR_MULTIPLE_COMPOUND_FILTERS; - - case U_INVALID_RBT_SYNTAX: - return I18N_ERROR_INVALID_RBT_SYNTAX; - - case U_MALFORMED_PRAGMA: - return I18N_ERROR_MALFORMED_PRAGMA; - - case U_UNCLOSED_SEGMENT: - return I18N_ERROR_UNCLOSED_SEGMENT; - - case U_VARIABLE_RANGE_EXHAUSTED: - return I18N_ERROR_VARIABLE_RANGE_EXHAUSTED; - - case U_VARIABLE_RANGE_OVERLAP: - return I18N_ERROR_VARIABLE_RANGE_OVERLAP; - - case U_ILLEGAL_CHARACTER: - return I18N_ERROR_ILLEGAL_CHARACTER; - - case U_INTERNAL_TRANSLITERATOR_ERROR: - return I18N_ERROR_INTERNAL_TRANSLITERATOR; - - case U_INVALID_ID: - return I18N_ERROR_INVALID_ID; - - case U_INVALID_FUNCTION: - return I18N_ERROR_INVALID_FUNCTION; - - case U_UNEXPECTED_TOKEN: - return I18N_ERROR_UNEXPECTED_TOKEN; - - case U_MULTIPLE_DECIMAL_SEPARATORS: - return I18N_ERROR_MULTIPLE_DECIMAL_SEPARATORS; - - case U_MULTIPLE_EXPONENTIAL_SYMBOLS: - return I18N_ERROR_MULTIPLE_EXPONENTIAL_SYMBOLS; - - case U_MALFORMED_EXPONENTIAL_PATTERN: - return I18N_ERROR_MALFORMED_EXPONENTIAL_PATTERN; - - case U_MULTIPLE_PERCENT_SYMBOLS: - return I18N_ERROR_MULTIPLE_PERCENT_SYMBOLS; - - case U_MULTIPLE_PERMILL_SYMBOLS: - return I18N_ERROR_MULTIPLE_PERMILL_SYMBOLS; - - case U_MULTIPLE_PAD_SPECIFIERS: - return I18N_ERROR_MULTIPLE_PAD_SPECIFIERS; - - case U_PATTERN_SYNTAX_ERROR: - return I18N_ERROR_PATTERN_SYNTAX; - - case U_ILLEGAL_PAD_POSITION: - return I18N_ERROR_ILLEGAL_PAD_POSITION; - - case U_UNMATCHED_BRACES: - return I18N_ERROR_UNMATCHED_BRACES; - - case U_ARGUMENT_TYPE_MISMATCH: - return I18N_ERROR_ARGUMENT_TYPE_MISMATCH; - - case U_DUPLICATE_KEYWORD: - return I18N_ERROR_DUPLICATE_KEYWORD; - - case U_UNDEFINED_KEYWORD: - return I18N_ERROR_UNDEFINED_KEYWORD; - - case U_DEFAULT_KEYWORD_MISSING: - return I18N_ERROR_DEFAULT_KEYWORD_MISSING; - - case U_DECIMAL_NUMBER_SYNTAX_ERROR: - return I18N_ERROR_DECIMAL_NUMBER_SYNTAX; - - case U_FORMAT_INEXACT_ERROR: - return I18N_ERROR_INEXACT_FORMAT; - - case U_BRK_INTERNAL_ERROR: - return I18N_ERROR_UBRK_INTERNAL; - - case U_BRK_HEX_DIGITS_EXPECTED: - return I18N_ERROR_UBRK_HEX_DIGITS_EXPECTED; - - case U_BRK_SEMICOLON_EXPECTED: - return I18N_ERROR_UBRK_SEMICOLON_EXPECTED; - - case U_BRK_RULE_SYNTAX: - return I18N_ERROR_UBRK_RULE_SYNTAX; - - case U_BRK_UNCLOSED_SET: - return I18N_ERROR_UBRK_UNCLOSED_SET; - - case U_BRK_ASSIGN_ERROR: - return I18N_ERROR_UBRK_ASSIGN_ERROR; - - case U_BRK_VARIABLE_REDFINITION: - return I18N_ERROR_UBRK_VARIABLE_REDEFINITION; - - case U_BRK_MISMATCHED_PAREN: - return I18N_ERROR_UBRK_MISMATCHED_PAREN; - - case U_BRK_NEW_LINE_IN_QUOTED_STRING: - return I18N_ERROR_UBRK_NEW_LINE_IN_QUOTED_STRING; - - case U_BRK_UNDEFINED_VARIABLE: - return I18N_ERROR_UBRK_UNDEFINED_VARIABLE; - - case U_BRK_INIT_ERROR: - return I18N_ERROR_UBRK_INIT; - - case U_BRK_RULE_EMPTY_SET: - return I18N_ERROR_UBRK_RULE_EMPTY_SET; - - case U_BRK_UNRECOGNIZED_OPTION: - return I18N_ERROR_UBRK_UNRECOGNIZED_OPTION; - - case U_BRK_MALFORMED_RULE_TAG: - return I18N_ERROR_UBRK_MALFORMED_RULE_TAG; - - default: - return I18N_ERROR_UNKNOWN; - } -} - -int _i18n_error_mapping_reverse(int err) -{ - switch (err) { - case I18N_ERROR_NONE: - return U_ZERO_ERROR; - - case I18N_ERROR_INVALID_PARAMETER: - return U_ILLEGAL_ARGUMENT_ERROR; - - case I18N_ERROR_MISSING_RESOURCE: - return U_MISSING_RESOURCE_ERROR; - - case I18N_ERROR_INVALID_FORMAT: - return U_INVALID_FORMAT_ERROR; - - case I18N_ERROR_FILE_ACCESS: - return U_FILE_ACCESS_ERROR; - - case I18N_ERROR_INTERNAL_PROGRAM: - return U_INTERNAL_PROGRAM_ERROR; - - case I18N_ERROR_MESSAGE_PARSE: - return U_MESSAGE_PARSE_ERROR; - - case I18N_ERROR_OUT_OF_MEMORY: - return U_MEMORY_ALLOCATION_ERROR; - - case I18N_ERROR_INDEX_OUTOFBOUNDS: - return U_INDEX_OUTOFBOUNDS_ERROR; - - case I18N_ERROR_PARSE: - return U_PARSE_ERROR; - - case I18N_ERROR_INVALID_CHAR_FOUND: - return U_INVALID_CHAR_FOUND; - - case I18N_ERROR_TRUNCATED_CHAR_FOUND: - return U_TRUNCATED_CHAR_FOUND; - - case I18N_ERROR_ILLEGAL_CHAR_FOUND: - return U_ILLEGAL_CHAR_FOUND; - - case I18N_ERROR_INVALID_TABLE_FORMAT: - return U_INVALID_TABLE_FORMAT; - - case I18N_ERROR_INVALID_TABLE_FILE: - return U_INVALID_TABLE_FILE; - - case I18N_ERROR_BUFFER_OVERFLOW: - return U_BUFFER_OVERFLOW_ERROR; - - case I18N_ERROR_NOT_SUPPORTED: - return U_UNSUPPORTED_ERROR; - - case I18N_ERROR_RESOURCE_TYPE_MISMATCH: - return U_RESOURCE_TYPE_MISMATCH; - - case I18N_ERROR_ILLECAL_ESCAPE_SEQUENCE: - return U_ILLEGAL_ESCAPE_SEQUENCE; - - case I18N_ERROR_UNSUPPORTED_ESCAPE_SEQUENCE: - return U_UNSUPPORTED_ESCAPE_SEQUENCE; - - case I18N_ERROR_NO_SPACE_AVAILABLE: - return U_NO_SPACE_AVAILABLE; - - case I18N_ERROR_CE_NOT_FOUND: - return U_CE_NOT_FOUND_ERROR; - - case I18N_ERROR_PRIMARY_TOO_LONG: - return U_PRIMARY_TOO_LONG_ERROR; - - case I18N_ERROR_STATE_TOO_OLD: - return U_STATE_TOO_OLD_ERROR; - - case I18N_ERROR_TOO_MANY_ALIASES: - return U_TOO_MANY_ALIASES_ERROR; - - case I18N_ERROR_ENUM_OUT_OF_SYNC: - return U_ENUM_OUT_OF_SYNC_ERROR; - - case I18N_ERROR_INVARIANT_CONVERSION: - return U_INVARIANT_CONVERSION_ERROR; - - case I18N_ERROR_INVALID_STATE: - return U_INVALID_STATE_ERROR; - - case I18N_ERROR_COLLATOR_VERSION_MISMATCH: - return U_COLLATOR_VERSION_MISMATCH; - - case I18N_ERROR_USELESS_COLLATOR: - return U_USELESS_COLLATOR_ERROR; - - case I18N_ERROR_NO_WRITE_PERMISSION: - return U_NO_WRITE_PERMISSION; - - case I18N_ERROR_MALFORMED_SET: - return U_MALFORMED_SET; - - case I18N_ERROR_STD3_ASCII_RULES: - return U_IDNA_STD3_ASCII_RULES_ERROR; - - case I18N_WARNING_STRING_NOT_TERMINATED: - return U_STRING_NOT_TERMINATED_WARNING; - - case I18N_ERROR_UNASSIGNED: - return U_IDNA_UNASSIGNED_ERROR; - - case I18N_WARNING_SORT_KEY_TOO_SHORT: - return U_SORT_KEY_TOO_SHORT_WARNING; - - case I18N_ERROR_BAD_VARIABLE_DEFINITION: - return U_BAD_VARIABLE_DEFINITION; - - case I18N_ERROR_MALFORMED_RULE: - return U_MALFORMED_RULE; - - case I18N_ERROR_MALFORMED_UNICODE_ESCAPE: - return U_MALFORMED_UNICODE_ESCAPE; - - case I18N_ERROR_MALFORMED_VARIABLE_DEFINITION: - return U_MALFORMED_VARIABLE_DEFINITION; - - case I18N_ERROR_MALFORMED_VARIABLE_REFERENCE: - return U_MALFORMED_VARIABLE_REFERENCE; - - case I18N_ERROR_MISPLACED_ANCHOR_START: - return U_MISPLACED_ANCHOR_START; - - case I18N_ERROR_MISPLACED_CURSOR_OFFSET: - return U_MISPLACED_CURSOR_OFFSET; - - case I18N_ERROR_MISPLACED_QUANTIFIER: - return U_MISPLACED_QUANTIFIER; - - case I18N_ERROR_MISSING_OPERATOR: - return U_MISSING_OPERATOR; - - case I18N_ERROR_MULTIPLE_ANTE_CONTEXTS: - return U_MULTIPLE_ANTE_CONTEXTS; - - case I18N_ERROR_MULTIPLE_CURSORS: - return U_MULTIPLE_CURSORS; - - case I18N_ERROR_MULTIPLE_POST_CONTEXTS: - return U_MULTIPLE_POST_CONTEXTS; - - case I18N_ERROR_TRAILING_BACKSLASH: - return U_TRAILING_BACKSLASH; - - case I18N_ERROR_UNDEFINED_SEGMENT_REFERENCE: - return U_UNDEFINED_SEGMENT_REFERENCE; - - case I18N_ERROR_UNDEFINED_VARIABLE: - return U_UNDEFINED_VARIABLE; - - case I18N_ERROR_UNQUOTED_SPECIAL: - return U_UNQUOTED_SPECIAL; - - case I18N_ERROR_UNTERMINATED_QUOTE: - return U_UNTERMINATED_QUOTE; - - case I18N_ERROR_RULE_MASK: - return U_RULE_MASK_ERROR; - - case I18N_ERROR_MISPLACED_COMPOUND_FILTER: - return U_MISPLACED_COMPOUND_FILTER; - - case I18N_ERROR_MULTIPLE_COMPOUND_FILTERS: - return U_MULTIPLE_COMPOUND_FILTERS; - - case I18N_ERROR_INVALID_RBT_SYNTAX: - return U_INVALID_RBT_SYNTAX; - - case I18N_ERROR_MALFORMED_PRAGMA: - return U_MALFORMED_PRAGMA; - - case I18N_ERROR_UNCLOSED_SEGMENT: - return U_UNCLOSED_SEGMENT; - - case I18N_ERROR_VARIABLE_RANGE_EXHAUSTED: - return U_VARIABLE_RANGE_EXHAUSTED; - - case I18N_ERROR_VARIABLE_RANGE_OVERLAP: - return U_VARIABLE_RANGE_OVERLAP; - - case I18N_ERROR_ILLEGAL_CHARACTER: - return U_ILLEGAL_CHARACTER; - - case I18N_ERROR_INTERNAL_TRANSLITERATOR: - return U_INTERNAL_TRANSLITERATOR_ERROR; - - case I18N_ERROR_INVALID_ID: - return U_INVALID_ID; - - case I18N_ERROR_INVALID_FUNCTION: - return U_INVALID_FUNCTION; - - case I18N_ERROR_UNEXPECTED_TOKEN: - return U_UNEXPECTED_TOKEN; - - case I18N_ERROR_MULTIPLE_DECIMAL_SEPARATORS: - return U_MULTIPLE_DECIMAL_SEPARATORS; - - case I18N_ERROR_MULTIPLE_EXPONENTIAL_SYMBOLS: - return U_MULTIPLE_EXPONENTIAL_SYMBOLS; - - case I18N_ERROR_MALFORMED_EXPONENTIAL_PATTERN: - return U_MALFORMED_EXPONENTIAL_PATTERN; - - case I18N_ERROR_MULTIPLE_PERCENT_SYMBOLS: - return U_MULTIPLE_PERCENT_SYMBOLS; - - case I18N_ERROR_MULTIPLE_PERMILL_SYMBOLS: - return U_MULTIPLE_PERMILL_SYMBOLS; - - case I18N_ERROR_MULTIPLE_PAD_SPECIFIERS: - return U_MULTIPLE_PAD_SPECIFIERS; - - case I18N_ERROR_PATTERN_SYNTAX: - return U_PATTERN_SYNTAX_ERROR; - - case I18N_ERROR_ILLEGAL_PAD_POSITION: - return U_ILLEGAL_PAD_POSITION; - - case I18N_ERROR_UNMATCHED_BRACES: - return U_UNMATCHED_BRACES; - - case I18N_ERROR_ARGUMENT_TYPE_MISMATCH: - return U_ARGUMENT_TYPE_MISMATCH; - - case I18N_ERROR_DUPLICATE_KEYWORD: - return U_DUPLICATE_KEYWORD; - - case I18N_ERROR_UNDEFINED_KEYWORD: - return U_UNDEFINED_KEYWORD; - - case I18N_ERROR_DEFAULT_KEYWORD_MISSING: - return U_DEFAULT_KEYWORD_MISSING; - - case I18N_ERROR_DECIMAL_NUMBER_SYNTAX: - return U_DECIMAL_NUMBER_SYNTAX_ERROR; - - case I18N_ERROR_INEXACT_FORMAT: - return U_FORMAT_INEXACT_ERROR; - - case I18N_ERROR_UBRK_INTERNAL: - return U_BRK_INTERNAL_ERROR; - - case I18N_ERROR_UBRK_HEX_DIGITS_EXPECTED: - return U_BRK_HEX_DIGITS_EXPECTED; - - case I18N_ERROR_UBRK_SEMICOLON_EXPECTED: - return U_BRK_SEMICOLON_EXPECTED; - - case I18N_ERROR_UBRK_RULE_SYNTAX: - return U_BRK_RULE_SYNTAX; - - case I18N_ERROR_UBRK_UNCLOSED_SET: - return U_BRK_UNCLOSED_SET; - - case I18N_ERROR_UBRK_ASSIGN_ERROR: - return U_BRK_ASSIGN_ERROR; - - case I18N_ERROR_UBRK_VARIABLE_REDEFINITION: - return U_BRK_VARIABLE_REDFINITION; - - case I18N_ERROR_UBRK_MISMATCHED_PAREN: - return U_BRK_MISMATCHED_PAREN; - - case I18N_ERROR_UBRK_NEW_LINE_IN_QUOTED_STRING: - return U_BRK_NEW_LINE_IN_QUOTED_STRING; - - case I18N_ERROR_UBRK_UNDEFINED_VARIABLE: - return U_BRK_UNDEFINED_VARIABLE; - - case I18N_ERROR_UBRK_INIT: - return U_BRK_INIT_ERROR; - - case I18N_ERROR_UBRK_RULE_EMPTY_SET: - return U_BRK_RULE_EMPTY_SET; - - case I18N_ERROR_UBRK_UNRECOGNIZED_OPTION: - return U_BRK_UNRECOGNIZED_OPTION; - - case I18N_ERROR_UBRK_MALFORMED_RULE_TAG: - return U_BRK_MALFORMED_RULE_TAG; - - default: - return U_STANDARD_ERROR_LIMIT; - } -} diff --git a/src/utils_i18n_private.cpp b/src/utils_i18n_private.cpp new file mode 100644 index 0000000..6091995 --- /dev/null +++ b/src/utils_i18n_private.cpp @@ -0,0 +1,125 @@ +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +using namespace std; + +int _i18n_error_mapping(int err) { + + static map err_map; + + if(err_map.empty()) { + err_map.insert(make_pair(U_STRING_NOT_TERMINATED_WARNING, I18N_WARNING_STRING_NOT_TERMINATED)); + err_map.insert(make_pair(U_SORT_KEY_TOO_SHORT_WARNING, I18N_WARNING_SORT_KEY_TOO_SHORT)); + err_map.insert(make_pair(U_ZERO_ERROR, I18N_ERROR_NONE)); + err_map.insert(make_pair(U_ILLEGAL_ARGUMENT_ERROR, I18N_ERROR_INVALID_PARAMETER)); + err_map.insert(make_pair(U_MISSING_RESOURCE_ERROR, I18N_ERROR_MISSING_RESOURCE)); + err_map.insert(make_pair(U_INVALID_FORMAT_ERROR, I18N_ERROR_INVALID_FORMAT)); + err_map.insert(make_pair(U_FILE_ACCESS_ERROR, I18N_ERROR_FILE_ACCESS)); + err_map.insert(make_pair(U_INTERNAL_PROGRAM_ERROR, I18N_ERROR_INTERNAL_PROGRAM)); + err_map.insert(make_pair(U_MESSAGE_PARSE_ERROR, I18N_ERROR_MESSAGE_PARSE)); + err_map.insert(make_pair(U_MEMORY_ALLOCATION_ERROR, I18N_ERROR_OUT_OF_MEMORY)); + err_map.insert(make_pair(U_INDEX_OUTOFBOUNDS_ERROR, I18N_ERROR_INDEX_OUTOFBOUNDS)); + err_map.insert(make_pair(U_PARSE_ERROR, I18N_ERROR_PARSE)); + err_map.insert(make_pair(U_INVALID_CHAR_FOUND, I18N_ERROR_INVALID_CHAR_FOUND)); + err_map.insert(make_pair(U_TRUNCATED_CHAR_FOUND, I18N_ERROR_TRUNCATED_CHAR_FOUND)); + err_map.insert(make_pair(U_ILLEGAL_CHAR_FOUND, I18N_ERROR_ILLEGAL_CHAR_FOUND)); + err_map.insert(make_pair(U_INVALID_TABLE_FORMAT, I18N_ERROR_INVALID_TABLE_FORMAT)); + err_map.insert(make_pair(U_INVALID_TABLE_FILE, I18N_ERROR_INVALID_TABLE_FILE)); + err_map.insert(make_pair(U_BUFFER_OVERFLOW_ERROR, I18N_ERROR_BUFFER_OVERFLOW)); + err_map.insert(make_pair(U_UNSUPPORTED_ERROR, I18N_ERROR_NOT_SUPPORTED)); + err_map.insert(make_pair(U_RESOURCE_TYPE_MISMATCH, I18N_ERROR_RESOURCE_TYPE_MISMATCH)); + err_map.insert(make_pair(U_ILLEGAL_ESCAPE_SEQUENCE, I18N_ERROR_ILLECAL_ESCAPE_SEQUENCE)); + err_map.insert(make_pair(U_UNSUPPORTED_ESCAPE_SEQUENCE, I18N_ERROR_UNSUPPORTED_ESCAPE_SEQUENCE)); + err_map.insert(make_pair(U_NO_SPACE_AVAILABLE, I18N_ERROR_NO_SPACE_AVAILABLE)); + err_map.insert(make_pair(U_CE_NOT_FOUND_ERROR, I18N_ERROR_CE_NOT_FOUND)); + err_map.insert(make_pair(U_PRIMARY_TOO_LONG_ERROR, I18N_ERROR_PRIMARY_TOO_LONG)); + err_map.insert(make_pair(U_STATE_TOO_OLD_ERROR, I18N_ERROR_STATE_TOO_OLD)); + err_map.insert(make_pair(U_TOO_MANY_ALIASES_ERROR, I18N_ERROR_TOO_MANY_ALIASES)); + err_map.insert(make_pair(U_ENUM_OUT_OF_SYNC_ERROR, I18N_ERROR_ENUM_OUT_OF_SYNC)); + err_map.insert(make_pair(U_INVARIANT_CONVERSION_ERROR, I18N_ERROR_INVARIANT_CONVERSION)); + err_map.insert(make_pair(U_INVALID_STATE_ERROR, I18N_ERROR_INVALID_STATE)); + err_map.insert(make_pair(U_COLLATOR_VERSION_MISMATCH, I18N_ERROR_COLLATOR_VERSION_MISMATCH)); + err_map.insert(make_pair(U_USELESS_COLLATOR_ERROR, I18N_ERROR_USELESS_COLLATOR)); + err_map.insert(make_pair(U_NO_WRITE_PERMISSION, I18N_ERROR_NO_WRITE_PERMISSION)); + err_map.insert(make_pair(U_MALFORMED_SET, I18N_ERROR_MALFORMED_SET)); + err_map.insert(make_pair(U_IDNA_STD3_ASCII_RULES_ERROR, I18N_ERROR_STD3_ASCII_RULES)); + err_map.insert(make_pair(U_IDNA_UNASSIGNED_ERROR, I18N_ERROR_UNASSIGNED)); + err_map.insert(make_pair(U_BAD_VARIABLE_DEFINITION, I18N_ERROR_BAD_VARIABLE_DEFINITION)); + err_map.insert(make_pair(U_MALFORMED_RULE, I18N_ERROR_MALFORMED_RULE)); + err_map.insert(make_pair(U_MALFORMED_UNICODE_ESCAPE, I18N_ERROR_MALFORMED_UNICODE_ESCAPE)); + err_map.insert(make_pair(U_MALFORMED_VARIABLE_DEFINITION, I18N_ERROR_MALFORMED_VARIABLE_DEFINITION)); + err_map.insert(make_pair(U_MALFORMED_VARIABLE_REFERENCE, I18N_ERROR_MALFORMED_VARIABLE_REFERENCE)); + err_map.insert(make_pair(U_MISPLACED_ANCHOR_START, I18N_ERROR_MISPLACED_ANCHOR_START)); + err_map.insert(make_pair(U_MISPLACED_CURSOR_OFFSET, I18N_ERROR_MISPLACED_CURSOR_OFFSET)); + err_map.insert(make_pair(U_MISPLACED_QUANTIFIER, I18N_ERROR_MISPLACED_QUANTIFIER)); + err_map.insert(make_pair(U_MISSING_OPERATOR, I18N_ERROR_MISSING_OPERATOR)); + err_map.insert(make_pair(U_MULTIPLE_ANTE_CONTEXTS, I18N_ERROR_MULTIPLE_ANTE_CONTEXTS)); + err_map.insert(make_pair(U_MULTIPLE_CURSORS, I18N_ERROR_MULTIPLE_CURSORS)); + err_map.insert(make_pair(U_MULTIPLE_POST_CONTEXTS, I18N_ERROR_MULTIPLE_POST_CONTEXTS)); + err_map.insert(make_pair(U_TRAILING_BACKSLASH, I18N_ERROR_TRAILING_BACKSLASH)); + err_map.insert(make_pair(U_UNDEFINED_SEGMENT_REFERENCE, I18N_ERROR_UNDEFINED_SEGMENT_REFERENCE)); + err_map.insert(make_pair(U_UNDEFINED_VARIABLE, I18N_ERROR_UNDEFINED_VARIABLE)); + err_map.insert(make_pair(U_UNQUOTED_SPECIAL, I18N_ERROR_UNQUOTED_SPECIAL)); + err_map.insert(make_pair(U_UNTERMINATED_QUOTE, I18N_ERROR_UNTERMINATED_QUOTE)); + err_map.insert(make_pair(U_RULE_MASK_ERROR, I18N_ERROR_RULE_MASK)); + err_map.insert(make_pair(U_MISPLACED_COMPOUND_FILTER, I18N_ERROR_MISPLACED_COMPOUND_FILTER)); + err_map.insert(make_pair(U_MULTIPLE_COMPOUND_FILTERS, I18N_ERROR_MULTIPLE_COMPOUND_FILTERS)); + err_map.insert(make_pair(U_INVALID_RBT_SYNTAX, I18N_ERROR_INVALID_RBT_SYNTAX)); + err_map.insert(make_pair(U_MALFORMED_PRAGMA, I18N_ERROR_MALFORMED_PRAGMA)); + err_map.insert(make_pair(U_UNCLOSED_SEGMENT, I18N_ERROR_UNCLOSED_SEGMENT)); + err_map.insert(make_pair(U_VARIABLE_RANGE_EXHAUSTED, I18N_ERROR_VARIABLE_RANGE_EXHAUSTED)); + err_map.insert(make_pair(U_VARIABLE_RANGE_OVERLAP, I18N_ERROR_VARIABLE_RANGE_OVERLAP)); + err_map.insert(make_pair(U_ILLEGAL_CHARACTER, I18N_ERROR_ILLEGAL_CHARACTER)); + err_map.insert(make_pair(U_INTERNAL_TRANSLITERATOR_ERROR, I18N_ERROR_INTERNAL_TRANSLITERATOR)); + err_map.insert(make_pair(U_INVALID_ID, I18N_ERROR_INVALID_ID)); + err_map.insert(make_pair(U_INVALID_FUNCTION, I18N_ERROR_INVALID_FUNCTION)); + err_map.insert(make_pair(U_UNEXPECTED_TOKEN, I18N_ERROR_UNEXPECTED_TOKEN)); + err_map.insert(make_pair(U_MULTIPLE_DECIMAL_SEPARATORS, I18N_ERROR_MULTIPLE_DECIMAL_SEPARATORS)); + err_map.insert(make_pair(U_MULTIPLE_EXPONENTIAL_SYMBOLS, I18N_ERROR_MULTIPLE_EXPONENTIAL_SYMBOLS)); + err_map.insert(make_pair(U_MALFORMED_EXPONENTIAL_PATTERN, I18N_ERROR_MALFORMED_EXPONENTIAL_PATTERN)); + err_map.insert(make_pair(U_MULTIPLE_PERCENT_SYMBOLS, I18N_ERROR_MULTIPLE_PERCENT_SYMBOLS)); + err_map.insert(make_pair(U_MULTIPLE_PERMILL_SYMBOLS, I18N_ERROR_MULTIPLE_PERMILL_SYMBOLS)); + err_map.insert(make_pair(U_MULTIPLE_PAD_SPECIFIERS, I18N_ERROR_MULTIPLE_PAD_SPECIFIERS)); + err_map.insert(make_pair(U_PATTERN_SYNTAX_ERROR, I18N_ERROR_PATTERN_SYNTAX)); + err_map.insert(make_pair(U_ILLEGAL_PAD_POSITION, I18N_ERROR_ILLEGAL_PAD_POSITION)); + err_map.insert(make_pair(U_UNMATCHED_BRACES, I18N_ERROR_UNMATCHED_BRACES)); + err_map.insert(make_pair(U_ARGUMENT_TYPE_MISMATCH, I18N_ERROR_ARGUMENT_TYPE_MISMATCH)); + err_map.insert(make_pair(U_DUPLICATE_KEYWORD, I18N_ERROR_DUPLICATE_KEYWORD)); + err_map.insert(make_pair(U_UNDEFINED_KEYWORD, I18N_ERROR_UNDEFINED_KEYWORD)); + err_map.insert(make_pair(U_DEFAULT_KEYWORD_MISSING, I18N_ERROR_DEFAULT_KEYWORD_MISSING)); + err_map.insert(make_pair(U_DECIMAL_NUMBER_SYNTAX_ERROR, I18N_ERROR_DECIMAL_NUMBER_SYNTAX)); + err_map.insert(make_pair(U_FORMAT_INEXACT_ERROR, I18N_ERROR_INEXACT_FORMAT)); + err_map.insert(make_pair(U_BRK_INTERNAL_ERROR, I18N_ERROR_UBRK_INTERNAL)); + err_map.insert(make_pair(U_BRK_HEX_DIGITS_EXPECTED, I18N_ERROR_UBRK_HEX_DIGITS_EXPECTED)); + err_map.insert(make_pair(U_BRK_SEMICOLON_EXPECTED, I18N_ERROR_UBRK_SEMICOLON_EXPECTED)); + err_map.insert(make_pair(U_BRK_RULE_SYNTAX, I18N_ERROR_UBRK_RULE_SYNTAX)); + err_map.insert(make_pair(U_BRK_UNCLOSED_SET, I18N_ERROR_UBRK_UNCLOSED_SET)); + err_map.insert(make_pair(U_BRK_ASSIGN_ERROR, I18N_ERROR_UBRK_ASSIGN_ERROR)); + err_map.insert(make_pair(U_BRK_VARIABLE_REDFINITION, I18N_ERROR_UBRK_VARIABLE_REDEFINITION)); + err_map.insert(make_pair(U_BRK_MISMATCHED_PAREN, I18N_ERROR_UBRK_MISMATCHED_PAREN)); + err_map.insert(make_pair(U_BRK_NEW_LINE_IN_QUOTED_STRING, I18N_ERROR_UBRK_NEW_LINE_IN_QUOTED_STRING)); + err_map.insert(make_pair(U_BRK_UNDEFINED_VARIABLE, I18N_ERROR_UBRK_UNDEFINED_VARIABLE)); + err_map.insert(make_pair(U_BRK_INIT_ERROR, I18N_ERROR_UBRK_INIT)); + err_map.insert(make_pair(U_BRK_RULE_EMPTY_SET, I18N_ERROR_UBRK_RULE_EMPTY_SET)); + err_map.insert(make_pair(U_BRK_UNRECOGNIZED_OPTION, I18N_ERROR_UBRK_UNRECOGNIZED_OPTION)); + err_map.insert(make_pair(U_BRK_MALFORMED_RULE_TAG, I18N_ERROR_UBRK_MALFORMED_RULE_TAG)); + } + + return err_map.find(err)->second; +}