Markup processor.
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / text / markup-processor-helper-functions.cpp
1 /*
2  * Copyright (c) 2015 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 // FILE HEADER
19 #include <dali-toolkit/internal/text/markup-processor-helper-functions.h>
20
21 namespace Dali
22 {
23
24 namespace Toolkit
25 {
26
27 namespace Text
28 {
29
30 namespace
31 {
32 const char WHITE_SPACE       = 0x20; // ASCII value of the white space.
33 const char LAST_UPPER_CASE   = 0x5b; // ASCII value of the one after the last upper case character (Z).
34 const char TO_LOWER_CASE     = 32;   // Value to add to a upper case character to transform it into a lower case.
35 }
36
37 bool TokenComparison( const std::string& string1, const char* const stringBuffer2, Length length )
38 {
39   const Length stringSize = string1.size();
40   if( stringSize != length )
41   {
42     // Early return. Strings have different sizes.
43     return false;
44   }
45
46   const char* const stringBuffer1 = string1.c_str();
47
48   for( std::size_t index = 0; index < stringSize; ++index )
49   {
50     char character = *( stringBuffer2 + index );
51     if( *( stringBuffer1 + index ) != ( ( ( character < LAST_UPPER_CASE ) && ( '0' != character ) ) ? character + TO_LOWER_CASE : character ) )
52     {
53       return false;
54     }
55   }
56
57   return true;
58 }
59
60 void SkipWhiteSpace( const char*& markupStringBuffer,
61                      const char* const markupStringEndBuffer )
62 {
63   for( ; ( WHITE_SPACE >= *markupStringBuffer ) && ( markupStringBuffer < markupStringEndBuffer ); ++markupStringBuffer );
64 }
65
66 } // namespace Text
67
68 } // namespace Toolkit
69
70 } // namespace Dali