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