Remove useless iteration when debug mode
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / text / markup-processor-helper-functions.h
1 #ifndef DALI_TOOLKIT_TEXT_MARKUP_PROCESSOR_HELPER_FUNCTIONS_H
2 #define DALI_TOOLKIT_TEXT_MARKUP_PROCESSOR_HELPER_FUNCTIONS_H
3
4 /*
5  * Copyright (c) 2022 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */
20
21 // EXTERNAL INCLUDES
22 #include <dali/public-api/common/dali-vector.h>
23 #include <string>
24
25 // INTERNAL INCLUDES
26 #include <dali-toolkit/internal/text/text-definitions.h>
27 #include <dali-toolkit/public-api/text/text-enumerations.h>
28
29 namespace Dali
30 {
31 struct Vector2;
32 struct Vector4;
33
34 namespace Toolkit
35 {
36 namespace Text
37 {
38 /**
39  * @brief Stores an attribute pair: name, value.
40  */
41 struct Attribute
42 {
43   const char* nameBuffer;
44   const char* valueBuffer;
45   Length      nameLength;
46   Length      valueLength;
47 };
48
49 /**
50  * @brief Stores a tag and its attributes.
51  */
52 struct Tag
53 {
54   Vector<Attribute> attributes;
55   const char*       buffer;
56   Length            length;
57   bool              isEndTag;
58 };
59
60 /**
61  * @brief Compare if two tokens are equal.
62  *
63  * @pre @p string1 must be lower case. (The html-ish constant tokens)
64  * The @p stringBuffer2 parameter is transformed to lower case.
65  * This function is used in the mark-up parser.
66  * It has no sense to transform the constants html-ish tokens to lower case when
67  * it's known they already are.
68  *
69  * @param[in] string1 The html-ish constant token.
70  * @param[in] stringBuffer2 Pointer to the html-ish token buffer.
71  * @param[in] length The length of the html-ish token.
72  *
73  * @return @e true if both strings are equal.
74  */
75 bool TokenComparison(const std::string& string1, const char* const stringBuffer2, Length length);
76
77 /**
78  * @brief Skips any unnecessary white space.
79  *
80  * @param[in,out] stringBuffer The string buffer. It's a const iterator pointing the current character.
81  * @param[in] stringEndBuffer Pointer to one character after the end of the string buffer.
82  */
83 void SkipWhiteSpace(const char*&      stringBuffer,
84                     const char* const stringEndBuffer);
85
86 /**
87  * @Brief Jumps to the next white space.
88  *
89  * @param[in,out] stringBuffer The string buffer. It's a const iterator pointing the current character.
90  * @param[in] stringEndBuffer Pointer to one character after the end of the string buffer.
91  */
92 void JumpToWhiteSpace(const char*&      stringBuffer,
93                       const char* const stringEndBuffer);
94
95 /**
96 * @brief Converts a string into an unsigned int.
97 *
98 * @param[in] uintStr An unsigned int packed inside a string.
99 *
100 * @return The unsigned int value.
101 */
102 unsigned int StringToUint(const char* const uintStr);
103
104 /**
105  * @brief Converts a string into an hexadecimal unsigned int.
106  *
107  * @param[in] uintStr An hexadecimal unsigned int packed inside a string.
108  *
109  * @return The hexadecimal value.
110  */
111 unsigned int StringToHex(const char* const uintStr);
112
113 /**
114  * @brief Converts a string into a float value.
115  *
116  * @param[in] floatStr A float packed inside a string.
117  *
118  * @return The float value.
119  */
120 float StringToFloat(const char* const floatStr);
121
122 /**
123  * @brief Converts a float into a string.
124  *
125  * @param[in] value The float value.
126  * @param[out] floatStr The string.
127  */
128 void FloatToString(float value, std::string& floatStr);
129
130 /**
131  * @brief Converts an unsigned int into a string.
132  *
133  * @param[in] value The unsigned int value.
134  * @param[out] uIntStr The string.
135  */
136 void UintToString(unsigned int value, std::string& uIntStr);
137
138 /**
139  * @brief Converts an ARGB color packed in 4 byte unsigned int into a Vector4 color used in Dali.
140  *
141  * @param[in] color An ARGB color packed in an unsigned int.
142  * @param[out] retColor A Vector4 with the converted color.
143  */
144 void UintColorToVector4(unsigned int color, Vector4& retColor);
145
146 /**
147  * @brief Converts a color packed inside a string into an ARGB Vector4 color.
148  *
149  * The string color could be in hexadecimal ( 0xFF0000FF ), webcolor ( #0000FF or #00F ) or some constant values:
150  * black, white, red, green, blue, yellow, magenta, cyan or transparent.
151  *
152  * @param[in] colorStr A color packed inside a string.
153  * @param[in] length The length of the color string.
154  * @param[out] retColor A color packed inside a Vector4.
155  */
156 void ColorStringToVector4(const char* const colorStr, Length length, Vector4& retColor);
157
158 /**
159  * @brief Converts a color packed in a Vector4 into a string.
160  *
161  * Constant colors will be converted to the strings black, white, red, green, blue, yellow, magenta, cyan or transparent.
162  *
163  * If is not a constant color it will be converted to a string with hexadecimal ARGB content.
164  *
165  * @param[in] value The color value.
166  * @param[out] colorStr The string.
167  */
168 void Vector4ToColorString(const Vector4& value, std::string& vector2Str);
169
170 /**
171  * @brief Converts a two dimension vector packed inside a string into a Vector2.
172  *
173  * @param[in] vectorStr The two dimension vector packed inside a string.
174  * @param[in] length The length of the string.
175  * @param[out] vector2 The Vector2.
176  */
177 void StringToVector2(const char* const vectorStr, Length length, Vector2& vector2);
178
179 /**
180  * @brief Converts a Vector2 into a string.
181  *
182  * @param[in] value The vector2 value.
183  * @param[out] vector2Str The string.
184  */
185 void Vector2ToString(const Vector2& value, std::string& vector2Str);
186
187 /**
188  * @brief Converts a string into its value in the enum Text::Underline::Type.
189  *
190  * @param[in] typeStr The underline type value packed inside a string.
191  * @param[in] length The length of the string.
192  * @param[out] retType The Underline type.
193  */
194 void UnderlineTypeStringToTypeValue(const char* const typeStr, Length length, Text::Underline::Type& retType);
195
196 /**
197  * @brief Converts a string into a float value.
198  *
199  * @param[in] floatStr A float packed inside a string.
200  *
201  * @return The float value.
202  */
203 float StringToFloat(const char* const floatStr);
204
205 /**
206  * @brief Converts a string into its value in the enum Text::HorizontalAlignment::Type.
207  *
208  * @param[in] typeStr The horizontal-alignment type value packed inside a string.
209  * @param[in] length The length of the string.
210  * @param[out] retType The HorizontalAlignment type.
211  *
212  * @return Whether the value parsed or not.
213  */
214 bool HorizontalAlignmentTypeStringToTypeValue(const char* const typeStr, Length length, Text::HorizontalAlignment::Type& retType);
215
216 } // namespace Text
217
218 } // namespace Toolkit
219
220 } // namespace Dali
221
222 #endif // DALI_TOOLKIT_TEXT_MARKUP_PROCESSOR_HELPER_FUNCTIONS_H