• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 #include "i18n_break_iterator.h"
16 
17 #include "brkiter.h"
18 #include "string"
19 #include "utypes.h"
20 
21 namespace OHOS {
22 namespace Global {
23 namespace I18n {
I18nBreakIterator(std::string localeTag)24 I18nBreakIterator::I18nBreakIterator(std::string localeTag)
25 {
26     UErrorCode status = U_ZERO_ERROR;
27     iter = icu::BreakIterator::createLineInstance(localeTag.c_str(), status);
28     if (!U_SUCCESS(status)) {
29         if (iter != nullptr) {
30             delete iter;
31         }
32         iter = nullptr;
33     }
34 }
35 
~I18nBreakIterator()36 I18nBreakIterator::~I18nBreakIterator()
37 {
38     if (iter != nullptr) {
39         delete iter;
40     }
41 }
42 
Current()43 int32_t I18nBreakIterator::Current()
44 {
45     if (iter != nullptr) {
46         return iter->current();
47     }
48     return OFF_BOUND;
49 }
50 
First()51 int32_t I18nBreakIterator::First()
52 {
53     if (iter != nullptr) {
54         return iter->first();
55     }
56     return OFF_BOUND;
57 }
58 
Last()59 int32_t I18nBreakIterator::Last()
60 {
61     if (iter != nullptr) {
62         return iter->last();
63     }
64     return OFF_BOUND;
65 }
66 
Previous()67 int32_t I18nBreakIterator::Previous()
68 {
69     if (iter != nullptr) {
70         return iter->previous();
71     }
72     return OFF_BOUND;
73 }
74 
Next(int32_t number)75 int32_t I18nBreakIterator::Next(int32_t number)
76 {
77     if (iter != nullptr) {
78         return iter->next(number);
79     }
80     return OFF_BOUND;
81 }
82 
Next()83 int32_t I18nBreakIterator::Next()
84 {
85     if (iter != nullptr) {
86         return iter->next();
87     }
88     return OFF_BOUND;
89 }
90 
Following(int32_t offset)91 int32_t I18nBreakIterator::Following(int32_t offset)
92 {
93     if (iter != nullptr) {
94         return iter->following(offset);
95     }
96     return OFF_BOUND;
97 }
98 
SetText(const char * text)99 void I18nBreakIterator::SetText(const char *text)
100 {
101     if (iter != nullptr) {
102         ftext = text;
103         iter->setText(ftext);
104     }
105 }
106 
GetText(std::string & str)107 void I18nBreakIterator::GetText(std::string &str)
108 {
109     if (iter != nullptr) {
110         ftext.toUTF8String(str);
111     }
112 }
113 
IsBoundary(int32_t offset)114 bool I18nBreakIterator::IsBoundary(int32_t offset)
115 {
116     if (iter != nullptr) {
117         return iter->isBoundary(offset);
118     }
119     return false;
120 }
121 } // namespace I18n
122 } // namespace Global
123 } // namespace OHOS