Dali-Text: Keyboard Shortcuts
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / text / xhtml-entities.cpp
1 /*
2  * Copyright (c) 2017 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 // EXTERNAL INCLUDES
19 #include <cstring> // for strlen()
20
21 // FILE HEADER
22 #include "xhtml-entities.h"
23
24 namespace Dali
25 {
26
27 namespace Toolkit
28 {
29
30 namespace Text
31 {
32
33 namespace
34 {
35 /**
36  * Implementation of the XHTML Entity matching
37  */
38 struct XHTMLEntityLookup
39 {
40     const char* const entityName;  // XHTML Named Entity string
41     const char* const entityCode;  // Corresponding UTF-8
42 };
43
44 /* table of html name entities supported in DALi
45  *
46  * these are stored as pair with Named entity as Key and
47  * its utf 8 as value
48  */
49 const XHTMLEntityLookup XHTMLEntityLookupTable[] =
50   {
51   { "&quot;\0"    ,"\x22\0" },
52   { "&amp;\0"     ,"\x26\0" },
53   { "&apos;\0"    ,"\x27\0" },
54   { "&lt;\0"      ,"\x3c\0" },
55   { "&gt;\0"      ,"\x3e\0" },
56   { "&nbsp;\0"    ,"\xc2\xa0\0" },
57   { "&iexcl;\0"   ,"\xc2\xa1\0" },
58   { "&cent;\0"    ,"\xc2\xa2\0" },
59   { "&pound;\0"   ,"\xc2\xa3\0" },
60   { "&curren;\0"  ,"\xc2\xa4\0" },
61   { "&yen;\0"     ,"\xc2\xa5\0" },
62   { "&brvbar;\0"  ,"\xc2\xa6\0" },
63   { "&sect;\0"    ,"\xc2\xa7\0" },
64   { "&uml;\0"     ,"\xc2\xa8\0" },
65   { "&copy;\0"    ,"\xc2\xa9\0" },
66   { "&ordf;\0"    ,"\xc2\xaa\0" },
67   { "&laquo;\0"   ,"\xc2\xab\0" },
68   { "&not;\0"     ,"\xc2\xac\0" },
69   { "&shy;\0"     ,"\xc2\xad\0" },
70   { "&reg;\0"     ,"\xc2\xae\0" },
71   { "&macr;\0"    ,"\xc2\xaf\0" },
72   { "&deg;\0"     ,"\xc2\xb0\0" },
73   { "&plusmn;\0"  ,"\xc2\xb1\0" },
74   { "&sup2;\0"    ,"\xc2\xb2\0" },
75   { "&sup3;\0"    ,"\xc2\xb3\0" },
76   { "&acute;\0"   ,"\xc2\xb4\0" },
77   { "&micro;\0"   ,"\xc2\xb5\0" },
78   { "&para;\0"    ,"\xc2\xb6\0" },
79   { "&middot;\0"  ,"\xc2\xb7\0" },
80   { "&cedil;\0"   ,"\xc2\xb8\0" },
81   { "&sup1;\0"    ,"\xc2\xb9\0" },
82   { "&ordm;\0"    ,"\xc2\xba\0" },
83   { "&raquo;\0"   ,"\xc2\xbb\0" },
84   { "&frac14;\0"  ,"\xc2\xbc\0" },
85   { "&frac12;\0"  ,"\xc2\xbd\0" },
86   { "&frac34;\0"  ,"\xc2\xbe\0" },
87   { "&iquest;\0"  ,"\xc2\xbf\0" },
88   { "&Agrave;\0"  ,"\xc3\x80\0" },
89   { "&Aacute;\0"  ,"\xc3\x81\0" },
90   { "&Acirc;\0"   ,"\xc3\x82\0" },
91   { "&Atilde;\0"  ,"\xc3\x83\0" },
92   { "&Auml;\0"    ,"\xc3\x84\0" },
93   { "&Aring;\0"   ,"\xc3\x85\0" },
94   { "&AElig;\0"   ,"\xc3\x86\0" },
95   { "&Ccedil;\0"  ,"\xc3\x87\0" },
96   { "&Egrave;\0"  ,"\xc3\x88\0" },
97   { "&Eacute;\0"  ,"\xc3\x89\0" },
98   { "&Ecirc;\0"   ,"\xc3\x8a\0" },
99   { "&Euml;\0"    ,"\xc3\x8b\0" },
100   { "&Igrave;\0"  ,"\xc3\x8c\0" },
101   { "&Iacute;\0"  ,"\xc3\x8d\0" },
102   { "&Icirc;\0"   ,"\xc3\x8e\0" },
103   { "&Iuml;\0"    ,"\xc3\x8f\0" },
104   { "&ETH;\0"     ,"\xc3\x90\0" },
105   { "&Ntilde;\0"  ,"\xc3\x91\0" },
106   { "&Ograve;\0"  ,"\xc3\x92\0" },
107   { "&Oacute;\0"  ,"\xc3\x93\0" },
108   { "&Ocirc;\0"   ,"\xc3\x94\0" },
109   { "&Otilde;\0"  ,"\xc3\x95\0" },
110   { "&Ouml;\0"    ,"\xc3\x96\0" },
111   { "&times;\0"   ,"\xc3\x97\0" },
112   { "&Oslash;\0"  ,"\xc3\x98\0" },
113   { "&Ugrave;\0"  ,"\xc3\x99\0" },
114   { "&Uacute;\0"  ,"\xc3\x9a\0" },
115   { "&Ucirc;\0"   ,"\xc3\x9b\0" },
116   { "&Uuml;\0"    ,"\xc3\x9c\0" },
117   { "&Yacute;\0"  ,"\xc3\x9d\0" },
118   { "&THORN;\0"   ,"\xc3\x9e\0" },
119   { "&szlig;\0"   ,"\xc3\x9f\0" },
120   { "&agrave;\0"  ,"\xc3\xa0\0" },
121   { "&aacute;\0"  ,"\xc3\xa1\0" },
122   { "&acirc;\0"   ,"\xc3\xa2\0" },
123   { "&atilde;\0"  ,"\xc3\xa3\0" },
124   { "&auml;\0"    ,"\xc3\xa4\0" },
125   { "&aring;\0"   ,"\xc3\xa5\0" },
126   { "&aelig;\0"   ,"\xc3\xa6\0" },
127   { "&ccedil;\0"  ,"\xc3\xa7\0" },
128   { "&egrave;\0"  ,"\xc3\xa8\0" },
129   { "&eacute;\0"  ,"\xc3\xa9\0" },
130   { "&ecirc;\0"   ,"\xc3\xaa\0" },
131   { "&euml;\0"    ,"\xc3\xab\0" },
132   { "&igrave;\0"  ,"\xc3\xac\0" },
133   { "&iacute;\0"  ,"\xc3\xad\0" },
134   { "&icirc;\0"   ,"\xc3\xae\0" },
135   { "&iuml;\0"    ,"\xc3\xaf\0" },
136   { "&eth;\0"     ,"\xc3\xb0\0" },
137   { "&ntilde;\0"  ,"\xc3\xb1\0" },
138   { "&ograve;\0"  ,"\xc3\xb2\0" },
139   { "&oacute;\0"  ,"\xc3\xb3\0" },
140   { "&ocirc;\0"   ,"\xc3\xb4\0" },
141   { "&otilde;\0"  ,"\xc3\xb5\0" },
142   { "&ouml;\0"    ,"\xc3\xb6\0" },
143   { "&divide;\0"  ,"\xc3\xb7\0" },
144   { "&oslash;\0"  ,"\xc3\xb8\0" },
145   { "&ugrave;\0"  ,"\xc3\xb9\0" },
146   { "&uacute;\0"  ,"\xc3\xba\0" },
147   { "&ucirc;\0"   ,"\xc3\xbb\0" },
148   { "&uuml;\0"    ,"\xc3\xbc\0" },
149   { "&yacute;\0"  ,"\xc3\xbd\0" },
150   { "&thorn;\0"   ,"\xc3\xbe\0" },
151   { "&yuml;\0"    ,"\xc3\xbf\0" },
152   { "&OElig;\0"   ,"\xc5\x92\0" },
153   { "&oelig;\0"   ,"\xc5\x93\0" },
154   { "&Scaron;\0"  ,"\xc5\xa0\0" },
155   { "&scaron;\0"  ,"\xc5\xa1\0" },
156   { "&Yuml;\0"    ,"\xc5\xb8\0" },
157   { "&fnof;\0"    ,"\xc6\x92\0" },
158   { "&circ;\0"    ,"\xcb\x86\0" },
159   { "&tilde;\0"   ,"\xcb\x9c\0" },
160   { "&Alpha;\0"   ,"\xce\x91\0" },
161   { "&Beta;\0"    ,"\xce\x92\0" },
162   { "&Gamma;\0"   ,"\xce\x93\0" },
163   { "&Delta;\0"   ,"\xce\x94\0" },
164   { "&Epsilon;\0" ,"\xce\x95\0" },
165   { "&Zeta;\0"    ,"\xce\x96\0" },
166   { "&Eta;\0"     ,"\xce\x97\0" },
167   { "&Theta;\0"   ,"\xce\x98\0" },
168   { "&Iota;\0"    ,"\xce\x99\0" },
169   { "&Kappa;\0"   ,"\xce\x9a\0" },
170   { "&Lambda;\0"  ,"\xce\x9b\0" },
171   { "&Mu;\0"      ,"\xce\x9c\0" },
172   { "&Nu;\0"      ,"\xce\x9d\0" },
173   { "&Xi;\0"      ,"\xce\x9e\0" },
174   { "&Omicron;\0" ,"\xce\x9f\0" },
175   { "&Pi;\0"      ,"\xce\xa0\0" },
176   { "&Rho;\0"     ,"\xce\xa1\0" },
177   { "&Sigma;\0"   ,"\xce\xa3\0" },
178   { "&Tau;\0"     ,"\xce\xa4\0" },
179   { "&Upsilon;\0" ,"\xce\xa5\0" },
180   { "&Phi;\0"     ,"\xce\xa6\0" },
181   { "&Chi;\0"     ,"\xce\xa7\0" },
182   { "&Psi;\0"     ,"\xce\xa8\0" },
183   { "&Omega;\0"   ,"\xce\xa9\0" },
184   { "&alpha;\0"   ,"\xce\xb1\0" },
185   { "&beta;\0"    ,"\xce\xb2\0" },
186   { "&gamma;\0"   ,"\xce\xb3\0" },
187   { "&delta;\0"   ,"\xce\xb4\0" },
188   { "&epsilon;\0" ,"\xce\xb5\0" },
189   { "&zeta;\0"    ,"\xce\xb6\0" },
190   { "&eta;\0"     ,"\xce\xb7\0" },
191   { "&theta;\0"   ,"\xce\xb8\0" },
192   { "&iota;\0"    ,"\xce\xb9\0" },
193   { "&kappa;\0"   ,"\xce\xba\0" },
194   { "&lambda;\0"  ,"\xce\xbb\0" },
195   { "&mu;\0"      ,"\xce\xbc\0" },
196   { "&nu;\0"      ,"\xce\xbd\0" },
197   { "&xi;\0"      ,"\xce\xbe\0" },
198   { "&omicron;\0" ,"\xce\xbf\0" },
199   { "&pi;\0"      ,"\xcf\x80\0" },
200   { "&rho;\0"     ,"\xcf\x81\0" },
201   { "&sigmaf;\0"  ,"\xcf\x82\0" },
202   { "&sigma;\0"   ,"\xcf\x83\0" },
203   { "&tau;\0"     ,"\xcf\x84\0" },
204   { "&upsilon;\0" ,"\xcf\x85\0" },
205   { "&phi;\0"     ,"\xcf\x86\0" },
206   { "&chi;\0"     ,"\xcf\x87\0" },
207   { "&psi;\0"     ,"\xcf\x88\0" },
208   { "&omega;\0"   ,"\xcf\x89\0" },
209   { "&thetasym;\0","\xcf\x91\0" },
210   { "&upsih;\0"   ,"\xcf\x92\0" },
211   { "&piv;\0"     ,"\xcf\x96\0" },
212   { "&ensp;\0"    ,"\xe2\x80\x82\0" },
213   { "&emsp;\0"    ,"\xe2\x80\x83\0" },
214   { "&thinsp;\0"  ,"\xe2\x80\x89\0" },
215   { "&zwnj;\0"    ,"\xe2\x80\x8c\0" },
216   { "&zwj;\0"     ,"\xe2\x80\x8d\0" },
217   { "&lrm;\0"     ,"\xe2\x80\x8e\0" },
218   { "&rlm;\0"     ,"\xe2\x80\x8f\0" },
219   { "&ndash;\0"   ,"\xe2\x80\x93\0" },
220   { "&mdash;\0"   ,"\xe2\x80\x94\0" },
221   { "&lsquo;\0"   ,"\xe2\x80\x98\0" },
222   { "&rsquo;\0"   ,"\xe2\x80\x99\0" },
223   { "&sbquo;\0"   ,"\xe2\x80\x9a\0" },
224   { "&ldquo;\0"   ,"\xe2\x80\x9c\0" },
225   { "&rdquo;\0"   ,"\xe2\x80\x9d\0" },
226   { "&bdquo;\0"   ,"\xe2\x80\x9e\0" },
227   { "&dagger;\0"  ,"\xe2\x80\xa0\0" },
228   { "&Dagger;\0"  ,"\xe2\x80\xa1\0" },
229   { "&bull;\0"    ,"\xe2\x80\xa2\0" },
230   { "&hellip;\0"  ,"\xe2\x80\xa6\0" },
231   { "&permil;\0"  ,"\xe2\x80\xb0\0" },
232   { "&prime;\0"   ,"\xe2\x80\xb2\0" },
233   { "&Prime;\0"   ,"\xe2\x80\xb3\0" },
234   { "&lsaquo;\0"  ,"\xe2\x80\xb9\0" },
235   { "&rsaquo;\0"  ,"\xe2\x80\xba\0" },
236   { "&oline;\0"   ,"\xe2\x80\xbe\0" },
237   { "&frasl;\0"   ,"\xe2\x81\x84\0" },
238   { "&euro;\0"    ,"\xe2\x82\xac\0" },
239   { "&image;\0"   ,"\xe2\x84\x91\0" },
240   { "&weierp;\0"  ,"\xe2\x84\x98\0" },
241   { "&real;\0"    ,"\xe2\x84\x9c\0" },
242   { "&trade;\0"   ,"\xe2\x84\xa2\0" },
243   { "&alefsym;\0" ,"\xe2\x84\xb5\0" },
244   { "&larr;\0"    ,"\xe2\x86\x90\0" },
245   { "&uarr;\0"    ,"\xe2\x86\x91\0" },
246   { "&rarr;\0"    ,"\xe2\x86\x92\0" },
247   { "&darr;\0"    ,"\xe2\x86\x93\0" },
248   { "&harr;\0"    ,"\xe2\x86\x94\0" },
249   { "&crarr;\0"   ,"\xe2\x86\xb5\0" },
250   { "&lArr;\0"    ,"\xe2\x87\x90\0" },
251   { "&uArr;\0"    ,"\xe2\x87\x91\0" },
252   { "&rArr;\0"    ,"\xe2\x87\x92\0" },
253   { "&dArr;\0"    ,"\xe2\x87\x93\0" },
254   { "&hArr;\0"    ,"\xe2\x87\x94\0" },
255   { "&forall;\0"  ,"\xe2\x88\x80\0" },
256   { "&part;\0"    ,"\xe2\x88\x82\0" },
257   { "&exist;\0"   ,"\xe2\x88\x83\0" },
258   { "&empty;\0"   ,"\xe2\x88\x85\0" },
259   { "&nabla;\0"   ,"\xe2\x88\x87\0" },
260   { "&isin;\0"    ,"\xe2\x88\x88\0" },
261   { "&notin;\0"   ,"\xe2\x88\x89\0" },
262   { "&ni;\0"      ,"\xe2\x88\x8b\0" },
263   { "&prod;\0"    ,"\xe2\x88\x8f\0" },
264   { "&sum;\0"     ,"\xe2\x88\x91\0" },
265   { "&minus;\0"   ,"\xe2\x88\x92\0" },
266   { "&lowast;\0"  ,"\xe2\x88\x97\0" },
267   { "&radic;\0"   ,"\xe2\x88\x9a\0" },
268   { "&prop;\0"    ,"\xe2\x88\x9d\0" },
269   { "&infin;\0"   ,"\xe2\x88\x9e\0" },
270   { "&ang;\0"     ,"\xe2\x88\xa0\0" },
271   { "&and;\0"     ,"\xe2\x88\xa7\0" },
272   { "&or;\0"      ,"\xe2\x88\xa8\0" },
273   { "&cap;\0"     ,"\xe2\x88\xa9\0" },
274   { "&cup;\0"     ,"\xe2\x88\xaa\0" },
275   { "&int;\0"     ,"\xe2\x88\xab\0" },
276   { "&there4;\0"  ,"\xe2\x88\xb4\0" },
277   { "&sim;\0"     ,"\xe2\x88\xbc\0" },
278   { "&cong;\0"    ,"\xe2\x89\x85\0" },
279   { "&asymp;\0"   ,"\xe2\x89\x88\0" },
280   { "&ne;\0"      ,"\xe2\x89\xa0\0" },
281   { "&equiv;\0"   ,"\xe2\x89\xa1\0" },
282   { "&le;\0"      ,"\xe2\x89\xa4\0" },
283   { "&ge;\0"      ,"\xe2\x89\xa5\0" },
284   { "&sub;\0"     ,"\xe2\x8a\x82\0" },
285   { "&sup;\0"     ,"\xe2\x8a\x83\0" },
286   { "&nsub;\0"    ,"\xe2\x8a\x84\0" },
287   { "&sube;\0"    ,"\xe2\x8a\x86\0" },
288   { "&supe;\0"    ,"\xe2\x8a\x87\0" },
289   { "&oplus;\0"   ,"\xe2\x8a\x95\0" },
290   { "&otimes;\0"  ,"\xe2\x8a\x97\0" },
291   { "&perp;\0"    ,"\xe2\x8a\xa5\0" },
292   { "&sdot;\0"    ,"\xe2\x8b\x85\0" },
293   { "&lceil;\0"   ,"\xe2\x8c\x88\0" },
294   { "&rceil;\0"   ,"\xe2\x8c\x89\0" },
295   { "&lfloor;\0"  ,"\xe2\x8c\x8a\0" },
296   { "&rfloor;\0"  ,"\xe2\x8c\x8b\0" },
297   { "&loz;\0"     ,"\xe2\x97\x8a\0" },
298   { "&spades;\0"  ,"\xe2\x99\xa0\0" },
299   { "&clubs;\0"   ,"\xe2\x99\xa3\0" },
300   { "&hearts;\0"  ,"\xe2\x99\xa5\0" },
301   { "&diams;\0"   ,"\xe2\x99\xa6\0" },
302   { "&lang;\0"    ,"\xe2\x9f\xa8\0" },
303   { "&rang;\0"    ,"\xe2\x9f\xa9\0" }
304 };
305
306 const std::size_t XHTMLENTITY_LOOKUP_COUNT = (sizeof( XHTMLEntityLookupTable))/ (sizeof(XHTMLEntityLookup));
307
308 } // unnamed namespace
309
310 const char* const  NamedEntityToUtf8( const char* const markupText, unsigned int len )
311 {
312   // finding if given XHTML named entity is supported or not
313   for( size_t i = 0; i < XHTMLENTITY_LOOKUP_COUNT ; ++i )
314   {
315     unsigned int entityLen = strlen(XHTMLEntityLookupTable[i].entityName);
316     if( len == entityLen )
317     {
318       if( strncmp( markupText, XHTMLEntityLookupTable[i].entityName, len )  == 0 )  // if named Entity found in table
319         {
320           return XHTMLEntityLookupTable[i].entityCode;
321         }
322     }
323   }
324   return NULL;
325 }
326
327 } // namespace  Text
328
329 } // namespace  Toolkit
330
331 } // namespace  Dali