[dali_1.2.11] Merge branch 'devel/master'
[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) 2015 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
28 namespace Dali
29 {
30
31 struct Vector2;
32 struct Vector4;
33
34 namespace Toolkit
35 {
36
37 namespace Text
38 {
39
40 /**
41  * @brief Stores an attribute pair: name, value.
42  */
43 struct Attribute
44 {
45   const char* nameBuffer;
46   const char* valueBuffer;
47   Length nameLength;
48   Length valueLength;
49 };
50
51 /**
52  * @brief Stores a tag and its attributes.
53  */
54  struct Tag
55  {
56    Vector<Attribute> attributes;
57    const char* buffer;
58    Length length;
59    bool isEndTag;
60  };
61
62 /**
63  * @brief Compare if two tokens are equal.
64  *
65  * @pre @p string1 must be lower case. (The html-ish constant tokens)
66  * The @p stringBuffer2 parameter is transformed to lower case.
67  * This function is used in the mark-up parser.
68  * It has no sense to transform the constants html-ish tokens to lower case when
69  * it's known they already are.
70  *
71  * @param[in] string1 The html-ish constant token.
72  * @param[in] stringBuffer2 Pointer to the html-ish token buffer.
73  * @param[in] length The length of the html-ish token.
74  *
75  * @return @e true if both strings are equal.
76  */
77 bool TokenComparison( const std::string& string1, const char* const stringBuffer2, Length length );
78
79 /**
80  * @brief Skips any unnecessary white space.
81  *
82  * @param[in,out] stringBuffer The string buffer. It's a const iterator pointing the current character.
83  * @param[in] stringEndBuffer Pointer to one character after the end of the string buffer.
84  */
85 void SkipWhiteSpace( const char*& stringBuffer,
86                      const char* const stringEndBuffer );
87
88 /**
89  * @Brief Jumps to the next white space.
90  *
91  * @param[in,out] stringBuffer The string buffer. It's a const iterator pointing the current character.
92  * @param[in] stringEndBuffer Pointer to one character after the end of the string buffer.
93  */
94 void JumpToWhiteSpace( const char*& stringBuffer,
95                        const char* const stringEndBuffer );
96
97 /**
98  * @brief Converts a string into an hexadecimal unsigned int.
99  *
100  * @param[in] uintStr An hexadecimal unsigned int packed inside a string.
101  *
102  * @return The hexadecimal value.
103  */
104 unsigned int StringToHex( const char* const uintStr );
105
106 /**
107  * @brief Converts a string into a float value.
108  *
109  * @param[in] floatStr A float packed inside a string.
110  *
111  * @return The float value.
112  */
113 float StringToFloat( const char* const floatStr );
114
115 /**
116  * @brief Converts a float into a string.
117  *
118  * @param[in] value The float value.
119  * @param[out] floatStr The string.
120  */
121 void FloatToString( float value, std::string& floatStr );
122
123 /**
124  * @brief Converts an ARGB color packed in 4 byte unsigned int into a Vector4 color used in Dali.
125  *
126  * @param[in] color An ARGB color packed in an unsigned int.
127  * @param[out] retColor A Vector4 with the converted color.
128  */
129 void UintColorToVector4( unsigned int color, Vector4& retColor );
130
131 /**
132  * @brief Converts a color packed inside a string into an ARGB Vector4 color.
133  *
134  * The string color could be in hexadecimal ( 0xFF0000FF ), webcolor ( #0000FF or #00F ) or some constant values:
135  * black, white, red, green, blue, yellow, magenta, cyan or transparent.
136  *
137  * @param[in] colorStr A color packed inside a string.
138  * @param[in] length The length of the color string.
139  * @param[out] retColor A color packed inside a Vector4.
140  */
141 void ColorStringToVector4( const char* const colorStr, Length length, Vector4& retColor );
142
143 /**
144  * @brief Converts a color packed in a Vector4 into a string.
145  *
146  * Constant colors will be converted to the strings black, white, red, green, blue, yellow, magenta, cyan or transparent.
147  *
148  * If is not a constant color it will be converted to a string with hexadecimal ARGB content.
149  *
150  * @param[in] value The color value.
151  * @param[out] colorStr The string.
152  */
153 void Vector4ToColorString( const Vector4& value, std::string& vector2Str );
154
155 /**
156  * @brief Converts a two dimension vector packed inside a string into a Vector2.
157  *
158  * @param[in] vectorStr The two dimension vector packed inside a string.
159  * @param[in] length The length of the string.
160  * @param[out] vector2 The Vector2.
161  */
162 void StringToVector2( const char* const vectorStr, Length length, Vector2& vector2 );
163
164 /**
165  * @brief Converts a Vector2 into a string.
166  *
167  * @param[in] value The vector2 value.
168  * @param[out] vector2Str The string.
169  */
170 void Vector2ToString( const Vector2& value, std::string& vector2Str );
171
172 } // namespace Text
173
174 } // namespace Toolkit
175
176 } // namespace Dali
177
178 #endif // __DALI_TOOLKIT_TEXT_MARKUP_PROCESSOR_HELPER_FUNCTIONS_H__