1 /*
2  * Copyright (c) 2020-2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "key_parser.h"
17 #include <cstring>
18 #include "acelite_config.h"
19 #include "js_config.h"
20 #include "keys.h"
21 
22 namespace OHOS {
23 namespace ACELite {
24 #ifdef KEYWORD
25 #undef KEYWORD
26 #endif // KEYWORD
27 
28 // Replace the struct keys.h "KEYWORD" sector for init
29 #ifdef ENABLE_KEY
30 #define KEYWORD(enumkey, keystr) {#keystr, K_##enumkey, static_cast<uint8_t>(strlen(#enumkey))},
31 
32 static const struct {
33     const char * const key;
34 } G_KEYWORD_INFO[KEYWORDS_MAX] = {
35     {"UNKNOWN"},
36 
37 #ifdef OHOS_ACELITE_KEYS_H
38 // include the keys.h again to redefine the "KEYWORD"
39 #undef OHOS_ACELITE_KEYS_H
40 #include "keys.h"
41 #endif // OHOS_ACELITE_KEYS_H
42 };
43 #undef KEYWORD
44 #endif
45 
ParseKeyId(const char * s,const size_t len)46 uint16_t KeyParser::ParseKeyId(const char *s, const size_t len)
47 {
48     if (s == nullptr || len >= UINT16_MAX || len == 0) {
49         return K_UNKNOWN;
50     }
51     /*
52      * The string was compared should be the same as the js define,
53      * with xxx-yyy instead the xxx_yyy,
54      * but the enum type use K_xxx_yyy for Id return
55      */
56     switch (*s++) {
57             // clang-format off
58         case 'a':
59 #if FEATURE_COMPONENT_TEXT_SPANNABLE
60             if (!strcmp(s, "bsolutesizespanstart")) {
61                 return K_ABSOLUTESIZESPANSTART;
62             }
63             if (!strcmp(s, "bsolutesizespanend")) {
64                 return K_ABSOLUTESIZESPANEND;
65             }
66             if (!strcmp(s, "bsolutesizespansize")) {
67                 return K_ABSOLUTESIZESPANSIZE;
68             }
69 #endif // FEATURE_COMPONENT_TEXT_SPANNABLE
70             if (!strcmp(s, "lignItems")) {
71                 return K_ALIGN_ITEMS;
72             }
73 #if (FEATURE_COMPONENT_ANALOG_CLOCK == 1)
74             if (!strcmp(s, "nalog-clock")) {
75                 return K_ANALOG_CLOCK;
76             }
77 #endif // FEATURE_COMPONENT_ANALOG_CLOCK
78             if (!strcmp(s, "nimationDelay")) {
79                 return K_ANIMATION_DELAY;
80             }
81             if (!strcmp(s, "nimationDuration")) {
82                 return K_ANIMATION_DURATION;
83             }
84             if (!strcmp(s, "nimationFillMode")) {
85                 return K_ANIMATION_FILL_MODE;
86             }
87             if (!strcmp(s, "nimationIterationCount")) {
88                 return K_ANIMATION_ITERATION_COUNT;
89             }
90             if (!strcmp(s, "nimationName")) {
91                 return K_ANIMATION_NAME;
92             }
93             if (!strcmp(s, "nimationTimingFunction")) {
94                 return K_ANIMATION_TIMING_FUNCTION;
95             }
96             if (!strcmp(s, "rc")) {
97                 return K_ARC;
98             }
99 #if (FEATURE_COMPONENT_VIDEO == 1)
100             if (!strcmp(s, "utoplay")) {
101                 return K_AUTOPLAY;
102             }
103 #endif // FEATURE_COMPONENT_VIDEO
104             break;
105         case 'b':
106             if (!strcmp(s, "ackgroundColor")) {
107                 return K_BACKGROUND_COLOR;
108             }
109 #if FEATURE_COMPONENT_TEXT_SPANNABLE
110             if (!strcmp(s, "ackgroundcolorspancolor")) {
111                 return K_BACKGROUNDCOLORSPANCOLOR;
112             }
113             if (!strcmp(s, "ackgroundcolorspanstart")) {
114                 return K_BACKGROUNDCOLORSPANSTART;
115             }
116             if (!strcmp(s, "ackgroundcolorspanend")) {
117                 return K_BACKGROUNDCOLORSPANEND;
118             }
119 #endif // FEATURE_COMPONENT_TEXT_SPANNABLE
120             if (!strcmp(s, "ackgroundImage")) {
121                 return K_BACKGROUND_IMAGE;
122             }
123             if (!strcmp(s, "lockColor")) {
124                 return K_BLOCK_COLOR;
125             }
126             if (!strcmp(s, "orderBottomColor")) {
127                 return K_BORDER_BOTTOM_COLOR;
128             }
129             if (!strcmp(s, "orderLeftColor")) {
130                 return K_BORDER_LEFT_COLOR;
131             }
132             if (!strcmp(s, "orderRightColor")) {
133                 return K_BORDER_RIGHT_COLOR;
134             }
135             if (!strcmp(s, "orderTopColor")) {
136                 return K_BORDER_TOP_COLOR;
137             }
138             if (!strcmp(s, "orderColor")) {
139                 return K_BORDER_COLOR;
140             }
141             if (!strcmp(s, "orderRadius")) {
142                 return K_BORDER_RADIUS;
143             }
144             if (!strcmp(s, "orderBottomWidth")) {
145                 return K_BORDER_BOTTOM_WIDTH;
146             }
147             if (!strcmp(s, "orderLeftWidth")) {
148                 return K_BORDER_LEFT_WIDTH;
149             }
150             if (!strcmp(s, "orderRightWidth")) {
151                 return K_BORDER_RIGHT_WIDTH;
152             }
153             if (!strcmp(s, "orderTopWidth")) {
154                 return K_BORDER_TOP_WIDTH;
155             }
156             if (!strcmp(s, "orderWidth")) {
157                 return K_BORDER_WIDTH;
158             }
159             if (!strcmp(s, "reak")) {
160                 return K_BREAK;
161             }
162             break;
163         case 'c':
164 #if (FEATURE_COMPONENT_CAMERA == 1)
165             if (!strcmp(s, "amera")) {
166                 return K_CAMERA;
167             }
168 #endif // FEATURE_COMPONENT_CAMERA
169 #if (FEATURE_COMPONENT_CANVAS == 1)
170             if (!strcmp(s, "anvas")) {
171                 return K_CANVAS;
172             }
173 #endif // FEATURE_COMPONENT_CANVAS
174             if (!strcmp(s, "enter")) {
175                 return K_CENTER;
176             }
177             if (!strcmp(s, "enterX")) {
178                 return K_CENTER_X;
179             }
180             if (!strcmp(s, "enterY")) {
181                 return K_CENTER_Y;
182             }
183             if (!strcmp(s, "olor")) {
184                 return K_COLOR;
185             }
186             if (!strcmp(s, "olumn")) {
187                 return K_COLUMN;
188             }
189             if (!strcmp(s, "olumn-reverse")) {
190                 return K_COLUMN_REVERSE;
191             }
192 #if (FEATURE_COMPONENT_VIDEO == 1)
193             if (!strcmp(s, "ontrols")) {
194                 return K_CONTROLS;
195             }
196 #endif // FEATURE_COMPONENT_VIDEO
197             if (!strcmp(s, "hange")) {
198                 return K_CHANGE;
199             }
200             if (!strcmp(s, "heckbox")) {
201                 return K_CHECKBOX;
202             }
203             if (!strcmp(s, "hecked")) {
204                 return K_CHECKED;
205             }
206             if (!strcmp(s, "lick")) {
207                 return K_CLICK;
208             }
209             if (!strcmp(s, "hart")) {
210                 return K_CHART;
211             }
212             if (!strcmp(s, "lip")) {
213                 return K_CLIP;
214             }
215 #if (FEATURE_COMPONENT_ANALOG_CLOCK == 1)
216             if (!strcmp(s, "lock-hand")) {
217                 return K_CLOCK_HAND;
218             }
219 #endif // FEATURE_COMPONENT_ANALOG_CLOCK
220             if (!strcmp(s, "ontain")) {
221                 return K_CONTAIN;
222             }
223             if (!strcmp(s, "over")) {
224                 return K_COVER;
225             }
226             break;
227         case 'd':
228             if (!strcmp(s, "atasets")) {
229                 return K_DATASETS;
230             }
231 #if (FEATURE_DATE_FORMAT == 1)
232             if (!strcmp(s, "ay")) {
233                 return K_DAY;
234             }
235 #endif
236 #if (FEATURE_COMPONENT_DATE_PICKER == 1)
237             if (!strcmp(s, "ate")) {
238                 return K_DATE;
239             }
240 #endif // FEATURE_COMPONENT_DATE_PICKER
241             if (!strcmp(s, "irection")) {
242                 return K_DIRECTION;
243             }
244             if (!strcmp(s, "isplay")) {
245                 return K_DISPLAY;
246             }
247             if (!strcmp(s, "iv")) {
248                 return K_DIV;
249             }
250             if (!strcmp(s, "rag")) {
251                 return K_DRAG;
252             }
253             if (!strcmp(s, "uration")) {
254                 return K_DURATION;
255             }
256             break;
257         case 'e':
258             if (!strcmp(s, "ase-in")) {
259                 return K_EASE_IN;
260             }
261             if (!strcmp(s, "ase-in-out")) {
262                 return K_EASE_IN_OUT;
263             }
264             if (!strcmp(s, "ase-out")) {
265                 return K_EASE_OUT;
266             }
267             if (!strcmp(s, "llipsis")) {
268                 return K_ELLIPSIS;
269             }
270 #if (FEATURE_COMPONENT_DATE_PICKER == 1)
271             if (!strcmp(s, "nd")) {
272                 return K_END;
273             }
274 #endif // FEATURE_COMPONENT_DATE_PICKER
275 #if ((FEATURE_COMPONENT_CAMERA == 1) || (FEATURE_COMPONENT_VIDEO == 1))
276             if (!strcmp(s, "rror")) {
277                 return K_ERROR;
278             }
279 #endif // ((FEATURE_COMPONENT_CAMERA == 1) || (FEATURE_COMPONENT_VIDEO == 1))
280             if (!strcmp(s, "xpand")) {
281                 return K_EXPAND;
282             }
283             break;
284         case 'f':
285             if (!strcmp(s, "alse")) {
286                 return K_FALSE;
287             }
288             if (!strcmp(s, "ill")) {
289                 return K_FILL;
290             }
291             if (!strcmp(s, "illmode")) {
292                 return K_FILL_MODE;
293             }
294             if (!strcmp(s, "ixedsize")) {
295                 return K_FIXED_SIZE;
296             }
297 #if (FEATURE_COMPONENT_VIDEO == 1)
298             if (!strcmp(s, "inish")) {
299                 return K_FINISH;
300             }
301 #endif // FEATURE_COMPONENT_VIDEO
302             if (!strcmp(s, "itOriginalSize")) {
303                 return K_FIT_ORIGINAL_SIZE;
304             }
305             if (!strcmp(s, "lex-end")) {
306                 return K_FLEX_END;
307             }
308             if (!strcmp(s, "lex-start")) {
309                 return K_FLEX_START;
310             }
311             if (!strcmp(s, "lexDirection")) {
312                 return K_FLEX_DIRECTION;
313             }
314             if (!strcmp(s, "lexWrap")) {
315                 return K_FLEX_WRAP;
316             }
317             if (!strcmp(s, "ontSize")) {
318                 return K_FONT_SIZE;
319             }
320             if (!strcmp(s, "ontFamily")) {
321                 return K_FONT_FAMILY;
322             }
323 #if FEATURE_COMPONENT_TEXT_SPANNABLE
324             if (!strcmp(s, "oregroundcolorspancolor")) {
325                 return K_FOREGROUNDCOLORSPANCOLOR;
326             }
327             if (!strcmp(s, "oregroundcolorspanstart")) {
328                 return K_FOREGROUNDCOLORSPANSTART;
329             }
330             if (!strcmp(s, "oregroundcolorspanend")) {
331                 return K_FOREGROUNDCOLORSPANEND;
332             }
333 #endif // FEATURE_COMPONENT_TEXT_SPANNABLE
334             if (!strcmp(s, "orwards")) {
335                 return K_FORWARDS;
336             }
337             break;
338         case 'h':
339             if (!strcmp(s, "eight")) {
340                 return K_HEIGHT;
341             }
342 #if ((FEATURE_COMPONENT_ANALOG_CLOCK == 1) || (FEATURE_DATE_FORMAT == 1))
343             if (!strcmp(s, "our")) {
344                 return K_HOUR;
345             }
346 #endif // FEATURE_COMPONENT_ANALOG_CLOCK
347 #if (FEATURE_DATE_FORMAT == 1)
348             if (!strcmp(s, "our12")) {
349                 return K_HOUR12;
350             }
351 #endif
352             break;
353         case 'i':
354             if (!strcmp(s, "d")) {
355                 return K_ID;
356             }
357             if (!strcmp(s, "mage")) {
358                 return K_IMAGE;
359             }
360             if (!strcmp(s, "mage-animator")) {
361                 return K_IMAGE_ANIMATOR;
362             }
363             if (!strcmp(s, "mages")) {
364                 return K_IMAGES;
365             }
366             if (!strcmp(s, "nput")) {
367                 return K_INPUT;
368             }
369             if (!strcmp(s, "ndex")) {
370                 return K_INDEX;
371             }
372             if (!strcmp(s, "temselected")) {
373                 return K_ITEM_SELECTED;
374             }
375             if (!strcmp(s, "teration")) {
376                 return K_ITERATION;
377             }
378             break;
379         case 'j':
380             if (!strcmp(s, "ustifyContent")) {
381                 return K_JUSTIFY_CONTENT;
382             }
383             break;
384 #ifdef JS_EXTRA_EVENT_SUPPORT
385         case 'k':
386             if (!strcmp(s, "ey")) {
387                 return K_KEY;
388             }
389             break;
390 #endif
391         case 'l':
392             if (!strcmp(s, "abels")) {
393                 return K_LABELS;
394             }
395             if (!strcmp(s, "arger")) {
396                 return K_LARGER;
397             }
398             if (!strcmp(s, "eft")) {
399                 return K_LEFT;
400             }
401             if (!strcmp(s, "etterSpacing")) {
402                 return K_LETTER_SPACING;
403             }
404 #if FEATURE_COMPONENT_TEXT_SPANNABLE
405             if (!strcmp(s, "inebackgroundcolorspancolor")) {
406                 return K_LINEBACKGROUNDCOLORSPANCOLOR;
407             }
408             if (!strcmp(s, "inebackgroundcolorspanstart")) {
409                 return K_LINEBACKGROUNDCOLORSPANSTART;
410             }
411             if (!strcmp(s, "inebackgroundcolorspanend")) {
412                 return K_LINEBACKGROUNDCOLORSPANEND;
413             }
414 #endif // FEATURE_COMPONENT_TEXT_SPANNABLE
415             if (!strcmp(s, "ineHeight")) {
416                 return K_LINE_HEIGHT;
417             }
418             if (!strcmp(s, "ist")) {
419                 return K_LIST;
420             }
421             if (!strcmp(s, "ist-item")) {
422                 return K_LIST_ITEM;
423             }
424             if (!strcmp(s, "ongpress")) {
425                 return K_LONGPRESS;
426             }
427             if (!strcmp(s, "oop")) {
428                 return K_LOOP;
429             }
430 #if (FEATURE_DATE_FORMAT == 1)
431             if (!strcmp(s, "ong")) {
432                 return K_LONG;
433             }
434 #endif
435             break;
436         case 'm':
437             if (!strcmp(s, "argin")) {
438                 return K_MARGIN;
439             }
440             if (!strcmp(s, "arginBottom")) {
441                 return K_MARGIN_BOTTOM;
442             }
443             if (!strcmp(s, "arginLeft")) {
444                 return K_MARGIN_LEFT;
445             }
446             if (!strcmp(s, "arginRight")) {
447                 return K_MARGIN_RIGHT;
448             }
449             if (!strcmp(s, "arginTop")) {
450                 return K_MARGIN_TOP;
451             }
452             if (!strcmp(s, "arquee")) {
453                 return K_MARQUEE;
454             }
455             if (!strcmp(s, "ax")) {
456                 return K_MAX;
457             }
458 #if (FEATURE_COMPONENT_EDITTEXT == 1)
459             if (!strcmp(s, "axlength")) {
460                 return K_MAX_LENGTH;
461             }
462 #endif // FEATURE_COMPONENT_EDITTEXT
463             if (!strcmp(s, "in")) {
464                 return K_MIN;
465             }
466             if (!strcmp(s, "ini")) {
467                 return K_MINI;
468             }
469 #if (FEATURE_COMPONENT_VIDEO == 1)
470             if (!strcmp(s, "uted")) {
471                 return K_MUTED;
472             }
473 #endif // FEATURE_COMPONENT_VIDEO
474 #if (FEATURE_NUMBER_FORMAT == 1)
475             if (!strcmp(s, "inimumFractionDigits")) {
476                 return K_MINIMUMFRACTIONDIGITS;
477             }
478             if (!strcmp(s, "aximumFractionDigits")) {
479                 return K_MAXIMUMFRACTIONDIGITS;
480             }
481 #endif
482 #if (FEATURE_DATE_FORMAT == 1)
483             if (!strcmp(s, "inute")) {
484                 return K_MINUTE;
485             }
486             if (!strcmp(s, "onth")) {
487                 return K_MONTH;
488             }
489 #endif
490             break;
491         case 'n':
492             if (!strcmp(s, "ame")) {
493                 return K_NAME;
494             }
495             if (!strcmp(s, "one")) {
496                 return K_NONE;
497             }
498 #if (FEATURE_DATE_FORMAT == 1)
499             if (!strcmp(s, "umeric")) {
500                 return K_NUMERIC;
501             }
502 #endif
503             break;
504         case 'o':
505             if (!strcmp(s, "bjectFit")) {
506                 return K_OBJECT_FIT;
507             }
508             if (!strcmp(s, "pacity")) {
509                 return K_OPACITY;
510             }
511             if (!strcmp(s, "ptions")) {
512                 return K_OPTIONS;
513             }
514             break;
515         case 'p':
516             if (!strcmp(s, "adding")) {
517                 return K_PADDING;
518             }
519             if (!strcmp(s, "addingBottom")) {
520                 return K_PADDING_BOTTOM;
521             }
522             if (!strcmp(s, "addingLeft")) {
523                 return K_PADDING_LEFT;
524             }
525             if (!strcmp(s, "addingRight")) {
526                 return K_PADDING_RIGHT;
527             }
528             if (!strcmp(s, "addingTop")) {
529                 return K_PADDING_TOP;
530             }
531 #if (FEATURE_COMPONENT_EDITTEXT == 1)
532             if (!strcmp(s, "assword")) {
533                 return K_PASSWORD;
534             }
535 #endif // FEATURE_COMPONENT_EDITTEXT
536 #if (FEATURE_COMPONENT_VIDEO == 1)
537             if (!strcmp(s, "ause")) {
538                 return K_PAUSE;
539             }
540 #endif // FEATURE_COMPONENT_VIDEO
541             if (!strcmp(s, "ercent")) {
542                 return K_PERCENT;
543             }
544             if (!strcmp(s, "icker-view")) {
545                 return K_PICKER_VIEW;
546             }
547 #if (FEATURE_COMPONENT_ANALOG_CLOCK == 1)
548             if (!strcmp(s, "ivotX")) {
549                 return K_PIVOT_X;
550             }
551             if (!strcmp(s, "ivotY")) {
552                 return K_PIVOT_Y;
553             }
554 #endif // FEATURE_COMPONENT_ANALOG_CLOCK
555 #if (FEATURE_COMPONENT_EDITTEXT == 1)
556             if (!strcmp(s, "laceholder")) {
557                 return K_PLACEHOLDER;
558             }
559             if (!strcmp(s, "laceholderColor")) {
560                 return K_PLACEHOLDER_COLOR;
561             }
562 #endif // FEATURE_COMPONENT_EDITTEXT
563 #if (FEATURE_COMPONENT_VIDEO == 1)
564             if (!strcmp(s, "repared")) {
565                 return K_PREPARED;
566             }
567 #endif // FEATURE_COMPONENT_VIDEO
568             if (!strcmp(s, "rogress")) {
569                 return K_PROGRESS;
570             }
571             break;
572 #if (FEATURE_COMPONENT_QRCODE == 1)
573         case 'q':
574             if (!strcmp(s, "rcode")) {
575                 return K_QRCODE;
576             }
577             break;
578 #endif // FEATURE_COMPONENT_QRCODE
579         case 'r':
580             if (!strcmp(s, "adio")) {
581                 return K_RADIO;
582             }
583             if (!strcmp(s, "adius")) {
584                 return K_RADIUS;
585             }
586             if (!strcmp(s, "ange")) {
587                 return K_RANGE;
588             }
589             if (!strcmp(s, "ef")) {
590                 return K_REF;
591             }
592 #if FEATURE_COMPONENT_TEXT_SPANNABLE
593             if (!strcmp(s, "elativesizespanstart")) {
594                 return K_RELATIVESIZESPANSTART;
595             }
596             if (!strcmp(s, "elativesizespanend")) {
597                 return K_RELATIVESIZESPANEND;
598             }
599             if (!strcmp(s, "elativesizespansize")) {
600                 return K_RELATIVESIZESPANSIZE;
601             }
602 #endif // FEATURE_COMPONENT_TEXT_SPANNABLE
603             if (!strcmp(s, "everse")) {
604                 return K_REVERSE;
605             }
606             if (!strcmp(s, "ight")) {
607                 return K_RIGHT;
608             }
609             if (!strcmp(s, "otate")) {
610                 return K_ROTATE;
611             }
612             if (!strcmp(s, "ow")) {
613                 return K_ROW;
614             }
615             if (!strcmp(s, "ow-reverse")) {
616                 return K_ROW_REVERSE;
617             }
618             break;
619         case 's':
620             if (!strcmp(s, "cale-down")) {
621                 return K_SCALE_DOWN;
622             }
623             if (!strcmp(s, "crollamount")) {
624                 return K_SCROLLAMOUNT;
625             }
626             if (!strcmp(s, "crolldelay")) {
627                 return K_SCROLLDELAY;
628             }
629             if (!strcmp(s, "crollend")) {
630                 return K_SCROLLEND;
631             }
632             if (!strcmp(s, "crollstart")) {
633                 return K_SCROLLSTART;
634             }
635             if (!strcmp(s, "crolltop")) {
636                 return K_SCROLLTOP;
637             }
638             if (!strcmp(s, "crollbottom")) {
639                 return K_SCROLLBOTTOM;
640             }
641 #if (FEATURE_COMPONENT_ANALOG_CLOCK == 1)
642             if (!strcmp(s, "ec")) {
643                 return K_SEC;
644             }
645 #endif // FEATURE_COMPONENT_ANALOG_CLOCK
646 #if (FEATURE_COMPONENT_VIDEO == 1)
647             if (!strcmp(s, "eeked")) {
648                 return K_SEEKED;
649             }
650             if (!strcmp(s, "eeking")) {
651                 return K_SEEKING;
652             }
653 #endif // FEATURE_COMPONENT_VIDEO
654             if (!strcmp(s, "elected")) {
655                 return K_SELECTED;
656             }
657             if (!strcmp(s, "electedColor")) {
658                 return K_SELECTED_COLOR;
659             }
660             if (!strcmp(s, "electedFontFamily")) {
661                 return K_SELECTED_FONT_FAMILY;
662             }
663             if (!strcmp(s, "electedFontSize")) {
664                 return K_SELECTED_FONT_SIZE;
665             }
666             if (!strcmp(s, "how")) {
667                 return K_SHOW;
668             }
669 #if (FEATURE_DATE_FORMAT == 1)
670             if (!strcmp(s, "hort")) {
671                 return K_SHORT;
672             }
673 #endif
674             if (!strcmp(s, "lider")) {
675                 return K_SLIDER;
676             }
677             if (!strcmp(s, "pace-around")) {
678                 return K_SPACE_AROUND;
679             }
680             if (!strcmp(s, "pace-between")) {
681                 return K_SPACE_BETWEEN;
682             }
683             if (!strcmp(s, "pace-evenly")) {
684                 return K_SPACE_EVENLY;
685             }
686 #if FEATURE_COMPONENT_TEXT_SPANNABLE
687             if (!strcmp(s, "pannablestyle")) {
688                 return K_SPANNABLESTYLE;
689             }
690             if (!strcmp(s, "pannablestart")) {
691                 return K_SPANNABLESTART;
692             }
693             if (!strcmp(s, "pannableend")) {
694                 return K_SPANNABLEEND;
695             }
696 #endif // FEATURE_COMPONENT_TEXT_SPANNABLE
697             if (!strcmp(s, "rc")) {
698                 return K_SRC;
699             }
700             if (!strcmp(s, "tack")) {
701                 return K_STACK;
702             }
703             if (!strcmp(s, "top")) {
704                 return K_STOP;
705             }
706 #if ((FEATURE_COMPONENT_DATE_PICKER == 1) || (FEATURE_COMPONENT_VIDEO == 1))
707             if (!strcmp(s, "tart")) {
708                 return K_START;
709             }
710 #endif // ((FEATURE_COMPONENT_DATE_PICKER == 1) || (FEATURE_COMPONENT_VIDEO == 1))
711             if (!strcmp(s, "tartAngle")) {
712                 return K_START_ANGLE;
713             }
714             if (!strcmp(s, "tandard")) {
715                 return K_STANDARD;
716             }
717             if (!strcmp(s, "trokeWidth")) {
718                 return K_STROKE_WIDTH;
719             }
720 #if (FEATURE_NUMBER_FORMAT == 1)
721             if (!strcmp(s, "tyle")) {
722                 return K_STYLE;
723             }
724 #endif // FEATURE_NUMBER_FORMAT
725             if (!strcmp(s, "wipe")) {
726                 return K_SWIPE;
727             }
728             if (!strcmp(s, "wiper")) {
729                 return K_SWIPER;
730             }
731             if (!strcmp(s, "witch")) {
732                 return K_SWITCH;
733             }
734             break;
735         case 't':
736 #if (FEATURE_COMPONENT_TABS == 1)
737             if (!strcmp(s, "ab-bar")) {
738                 return K_TAB_BAR;
739             }
740             if (!strcmp(s, "ab-content")) {
741                 return K_TAB_CONTENT;
742             }
743             if (!strcmp(s, "abs")) {
744                 return K_TABS;
745             }
746 #endif // FEATURE_COMPONENT_TABS
747             if (!strcmp(s, "ime")) {
748                 return K_TIME;
749             }
750 #if (FEATURE_COMPONENT_VIDEO == 1)
751             if (!strcmp(s, "imeupdate")) {
752                 return K_TIME_UPDATE;
753             }
754 #endif // FEATURE_COMPONENT_VIDEO
755             if (!strcmp(s, "op")) {
756                 return K_TOP;
757             }
758             if (!strcmp(s, "otalAngle")) {
759                 return K_TOTAL_ANGLE;
760             }
761             if (!strcmp(s, "ouchend")) {
762                 return K_TOUCHEND;
763             }
764             if (!strcmp(s, "ouchmove")) {
765                 return K_TOUCHMOVE;
766             }
767             if (!strcmp(s, "ouchstart")) {
768                 return K_TOUCHSTART;
769             }
770 #ifdef JS_EXTRA_EVENT_SUPPORT
771             if (!strcmp(s, "ouchcancel")) {
772                 return K_TOUCHCANCEL;
773             }
774 #endif
775             if (!strcmp(s, "ext")) {
776                 return K_TEXT;
777             }
778             if (!strcmp(s, "ranslateX")) {
779                 return K_TRANSLATE_X;
780             }
781             if (!strcmp(s, "ranslateY")) {
782                 return K_TRANSLATE_Y;
783             }
784             if (!strcmp(s, "rue")) {
785                 return K_TRUE;
786             }
787             if (!strcmp(s, "extAlign")) {
788                 return K_TEXT_ALIGN;
789             }
790             if (!strcmp(s, "extOverflow")) {
791                 return K_TEXT_OVERFLOW;
792             }
793 #if ((FEATURE_COMPONENT_ANALOG_CLOCK == 1) || (FEATURE_COMPONENT_EDITTEXT == 1))
794             if (!strcmp(s, "ype")) {
795                 return K_TYPE;
796             }
797 #endif // (FEATURE_COMPONENT_ANALOG_CLOCK == 1) || (FEATURE_COMPONENT_EDITTEXT == 1)
798             break;
799         case 'u':
800 #if (FEATURE_NUMBER_FORMAT == 1)
801             if (!strcmp(s, "seGrouping")) {
802                 return K_USEGROUP;
803             }
804 #endif // FEATURE_NUMBER_FORMAT
805             break;
806         case 'v':
807             if (!strcmp(s, "alue")) {
808                 return K_VALUE;
809             }
810             if (!strcmp(s, "ertical")) {
811                 return K_VERTICAL;
812             }
813 #if (FEATURE_COMPONENT_VIDEO == 1)
814             if (!strcmp(s, "ideo")) {
815                 return K_VIDEO;
816             }
817 #endif // FEATURE_COMPONENT_VIDEO
818             break;
819         case 'w':
820             if (!strcmp(s, "idth")) {
821                 return K_WIDTH;
822             }
823             if (!strcmp(s, "rap")) {
824                 return K_WRAP;
825             }
826             break;
827         case '2':
828 #if (FEATURE_DATE_FORMAT == 1)
829             if (!strcmp(s, "-digit")) {
830                 return K_DIGIT2;
831             }
832             break;
833 #endif
834         default:
835             break;
836             // clang-format on
837     }
838     return K_UNKNOWN;
839 }
840 
ParseKeyId(const char * const s)841 uint16_t KeyParser::ParseKeyId(const char * const s)
842 {
843     if (s == nullptr) {
844         return K_UNKNOWN;
845     }
846 
847     size_t len = strlen(s);
848     if (len >= UINT16_MAX) {
849         return K_UNKNOWN;
850     }
851     return ParseKeyId(s, len);
852 }
853 
IsKeyValid(uint16_t id)854 bool KeyParser::IsKeyValid(uint16_t id)
855 {
856     return ((id > K_UNKNOWN) && (id < KEYWORDS_MAX));
857 }
858 
GetKeyById(uint16_t id)859 const char *KeyParser::GetKeyById(uint16_t id)
860 {
861     if (!IsKeyValid(id)) {
862         return "UNKNOWN";
863     }
864 #if (ENABLE_KEY == 1)
865     return G_KEYWORD_INFO[id].key;
866 #else
867     return "UNKNOWN";
868 #endif // ENABLE_KEY
869 }
870 } // namespace ACELite
871 } // namespace OHOS
872