• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include <cstdint>
17 #include <cstdlib>
18 #include <chrono>
19 #include <string>
20 #include "i18n_hilog.h"
21 #include "i18n_normalizer_ffi.h"
22 #include "i18n_normalizer_impl.h"
23 
24 namespace OHOS {
25 namespace Global {
26 namespace I18n {
27 using namespace OHOS::FFI;
28 extern "C"
29 {
FfiI18nNormalizerConstructor(int32_t mode)30     int64_t FfiI18nNormalizerConstructor(int32_t mode)
31     {
32         I18nNormalizerMode normalizerMode = I18nNormalizerMode(mode);
33         I18nErrorCode errorCode = I18nErrorCode::SUCCESS;
34         std::unique_ptr<I18nNormalizer> normalizer_ = std::make_unique<I18nNormalizer>(normalizerMode, errorCode);
35         if (errorCode != I18nErrorCode::SUCCESS || !normalizer_) {
36             HILOG_ERROR_I18N("Create I18nNormalizer fail, error code: %d", errorCode);
37             return -1;
38         }
39         auto ffiNormalizerInstance = FFIData::Create<FfiI18nNormalizer>(std::move(normalizer_));
40         if (ffiNormalizerInstance == nullptr) {
41             HILOG_ERROR_I18N("Create FfiI18nNormalizer fail");
42             return -1;
43         }
44         return ffiNormalizerInstance->GetID();
45     }
46 
FfiI18nNormalizerNormalize(int64_t remoteDataID,char * text)47     char* FfiI18nNormalizerNormalize(int64_t remoteDataID, char* text)
48     {
49         auto normalizer = FFIData::GetData<FfiI18nNormalizer>(remoteDataID);
50         if (!normalizer) {
51             HILOG_ERROR_I18N("The FfiI18nNormalizer instance is nullptr");
52             return nullptr;
53         }
54         return normalizer->normalize(text);
55     }
56 }
57 }  // namespace I18n
58 }  // namespace Global
59 }  // namespace OHOS