Remove useless iteration when debug mode
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / text / hyphenator.cpp
1 /*
2  * Copyright (c) 2021 Samsung Electronics Co., Ltd.
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
18 // CLASS HEADER
19 #include <dali-toolkit/internal/text/hyphenator.h>
20
21 // EXTERNAL INCLUDES
22 #include <dali/devel-api/text-abstraction/hyphenation.h>
23
24 // INTERNAL INCLUDES
25 #include <dali-toolkit/internal/text/character-set-conversion.h>
26
27 #include <cstring> // for strcmp
28
29 namespace Dali
30 {
31 namespace Toolkit
32 {
33 namespace Text
34 {
35 const char* UTF8 = "UTF-8";
36
37 Vector<bool> GetWordHyphens(const Character* word,
38                             Length           wordSize,
39                             const char*      lang)
40 {
41   Vector<bool> hyphens;
42
43   if(0u == wordSize || word == nullptr)
44   {
45     // Nothing to do if there are no characters.
46     return hyphens;
47   }
48
49   TextAbstraction::Hyphenation hyphenation = TextAbstraction::Hyphenation::Get();
50
51   // first get the needed encoding
52   std::string text;
53   if(strcmp(hyphenation.GetDictionaryEncoding(lang), UTF8) == 0)
54   {
55     Utf32ToUtf8(word, wordSize, text);
56   }
57   else
58   {
59     text = std::string((char*)word, (size_t)(wordSize * sizeof(Character)));
60   }
61
62   return hyphenation.GetWordHyphens(text.c_str(), (int)text.length(), lang);
63 }
64
65 } // namespace Text
66
67 } // namespace Toolkit
68
69 } // namespace Dali