@@ -99,13 +99,6 @@ lxb_css_syntax_state_consume_numeric(lxb_css_syntax_tokenizer_t *tkz,
9999 const lxb_char_t * data ,
100100 const lxb_char_t * end );
101101
102- static const lxb_char_t *
103- lxb_css_syntax_state_decimal (lxb_css_syntax_tokenizer_t * tkz ,
104- lxb_css_syntax_token_t * token ,
105- const lxb_char_t * data , const lxb_char_t * end ,
106- lxb_char_t * buf , lxb_char_t * buf_p ,
107- const lxb_char_t * buf_end );
108-
109102static const lxb_char_t *
110103lxb_css_syntax_state_consume_numeric_name_start (lxb_css_syntax_tokenizer_t * tkz ,
111104 lxb_css_syntax_token_t * token ,
@@ -706,8 +699,6 @@ lxb_css_syntax_state_plus(lxb_css_syntax_tokenizer_t *tkz,
706699 lxb_css_syntax_token_t * token ,
707700 const lxb_char_t * data , const lxb_char_t * end )
708701{
709- lxb_char_t buf [128 ];
710-
711702 /* Skip U+002B PLUS SIGN (+). */
712703 data += 1 ;
713704
@@ -732,8 +723,8 @@ lxb_css_syntax_state_plus(lxb_css_syntax_tokenizer_t *tkz,
732723 /* U+0030 DIGIT ZERO (0) and U+0039 DIGIT NINE (9) */
733724 if (* data >= 0x30 && * data <= 0x39 ) {
734725 lxb_css_syntax_token_number (token )-> have_sign = true;
735- return lxb_css_syntax_state_decimal (tkz , token , data , end ,
736- buf , buf , buf + sizeof ( buf ) );
726+ return lxb_css_syntax_state_consume_numeric (tkz , token ,
727+ data - 1 , end );
737728 }
738729
739730 data -= 1 ;
@@ -804,6 +795,7 @@ lxb_css_syntax_state_full_stop(lxb_css_syntax_tokenizer_t *tkz,
804795 const lxb_char_t * data , const lxb_char_t * end )
805796{
806797 if (lxb_css_syntax_state_start_number (data , end )) {
798+ lxb_css_syntax_token_number (token )-> have_sign = false;
807799 return lxb_css_syntax_state_consume_numeric (tkz , token , data , end );
808800 }
809801
@@ -935,37 +927,26 @@ lxb_css_syntax_state_rc_bracket(lxb_css_syntax_tokenizer_t *tkz, lxb_css_syntax_
935927 * Numeric
936928 */
937929lxb_inline void
938- lxb_css_syntax_consume_numeric_set_int (lxb_css_syntax_tokenizer_t * tkz ,
939- lxb_css_syntax_token_t * token ,
940- const lxb_char_t * start , const lxb_char_t * end )
941- {
942- double num = lexbor_strtod_internal (start , (end - start ), 0 );
943-
944- token -> type = LXB_CSS_SYNTAX_TOKEN_NUMBER ;
945-
946- lxb_css_syntax_token_number (token )-> is_float = false;
947- lxb_css_syntax_token_number (token )-> num = num ;
948- }
949-
950- lxb_inline void
951- lxb_css_syntax_consume_numeric_set_float (lxb_css_syntax_tokenizer_t * tkz ,
952- lxb_css_syntax_token_t * token ,
953- const lxb_char_t * start , const lxb_char_t * end ,
954- bool e_is_negative , int exponent , int e_digit )
930+ lxb_css_syntax_consume_numeric_set (lxb_css_syntax_tokenizer_t * tkz ,
931+ lxb_css_syntax_token_t * token ,
932+ const lxb_char_t * start , const lxb_char_t * end ,
933+ bool is_float , bool e_is_negative ,
934+ int exponent , int e_digit )
955935{
956936 if (e_is_negative ) {
957- exponent -= e_digit ;
937+ exponent = e_digit - exponent ;
938+ exponent = - exponent ;
958939 }
959940 else {
960- exponent + = e_digit ;
941+ exponent = e_digit + exponent ;
961942 }
962943
963944 double num = lexbor_strtod_internal (start , (end - start ), exponent );
964945
965946 token -> type = LXB_CSS_SYNTAX_TOKEN_NUMBER ;
966947
948+ lxb_css_syntax_token_number (token )-> is_float = is_float ;
967949 lxb_css_syntax_token_number (token )-> num = num ;
968- lxb_css_syntax_token_number (token )-> is_float = true;
969950}
970951
971952const lxb_char_t *
@@ -985,95 +966,77 @@ lxb_css_syntax_state_consume_numeric(lxb_css_syntax_tokenizer_t *tkz,
985966 const lxb_char_t * data ,
986967 const lxb_char_t * end )
987968{
988- lxb_char_t * buf_p ;
989- const lxb_char_t * buf_end ;
969+ bool e_is_negative , is_float ;
970+ int exponent , e_digit ;
971+ lxb_char_t ch , * buf_p ;
972+ const lxb_char_t * begin , * buf_end ;
973+ lxb_css_syntax_token_t * t_str ;
974+ lxb_css_syntax_token_string_t * str ;
990975 lxb_char_t buf [128 ];
991976
992977 buf_p = buf ;
993978 buf_end = buf + sizeof (buf );
994979
995- do {
996- /* U+0030 DIGIT ZERO (0) and U+0039 DIGIT NINE (9) */
997- if (* data < 0x30 || * data > 0x39 ) {
998- break ;
999- }
980+ str = lxb_css_syntax_token_dimension_string (token );
981+ t_str = (lxb_css_syntax_token_t * ) (void * ) str ;
1000982
983+ /* U+0030 DIGIT ZERO (0) and U+0039 DIGIT NINE (9) */
984+ while (* data >= 0x30 && * data <= 0x39 ) {
1001985 if (buf_p != buf_end ) {
1002986 * buf_p ++ = * data ;
1003987 }
1004988
1005989 data += 1 ;
1006990
1007991 if (data >= end ) {
1008- lxb_css_syntax_consume_numeric_set_int (tkz , token , buf , buf_p );
992+ lxb_css_syntax_consume_numeric_set (tkz , token , buf , buf_p ,
993+ false, false, 0 , 0 );
1009994 return data ;
1010995 }
1011996 }
1012- while (true);
1013-
1014- /* U+002E FULL STOP (.) */
1015- if (* data != 0x2E ) {
1016- lxb_css_syntax_consume_numeric_set_int (tkz , token , buf , buf_p );
1017-
1018- return lxb_css_syntax_state_consume_numeric_name_start (tkz , token ,
1019- data , end );
1020- }
1021997
1022- data += 1 ;
998+ exponent = 0 ;
999+ is_float = false;
10231000
1024- if (data >= end || * data < 0x30 || * data > 0x39 ) {
1025- lxb_css_syntax_consume_numeric_set_int (tkz , token , buf , buf_p );
1026- return data - 1 ;
1027- }
1028-
1029- return lxb_css_syntax_state_decimal (tkz , token , data , end ,
1030- buf , buf_p , buf_end );
1031- }
1001+ /* U+002E FULL STOP (.) */
1002+ if (* data == 0x2E ) {
1003+ data += 1 ;
10321004
1033- static const lxb_char_t *
1034- lxb_css_syntax_state_decimal (lxb_css_syntax_tokenizer_t * tkz ,
1035- lxb_css_syntax_token_t * token ,
1036- const lxb_char_t * data , const lxb_char_t * end ,
1037- lxb_char_t * buf , lxb_char_t * buf_p ,
1038- const lxb_char_t * buf_end )
1039- {
1040- bool e_is_negative ;
1041- int exponent , e_digit ;
1042- lxb_char_t ch ;
1043- const lxb_char_t * begin ;
1044- lxb_css_syntax_token_t * t_str ;
1045- lxb_css_syntax_token_string_t * str ;
1005+ /* U+0030 DIGIT ZERO (0) and U+0039 DIGIT NINE (9) */
1006+ if (data >= end || * data < 0x30 || * data > 0x39 ) {
1007+ lxb_css_syntax_consume_numeric_set (tkz , token , buf , buf_p ,
1008+ false, false, 0 , 0 );
1009+ return data - 1 ;
1010+ }
10461011
1047- begin = data ;
1012+ begin = buf_p ;
10481013
1049- str = lxb_css_syntax_token_dimension_string (token );
1050- t_str = (lxb_css_syntax_token_t * ) (void * ) str ;
1014+ /* U+0030 DIGIT ZERO (0) and U+0039 DIGIT NINE (9) */
1015+ do {
1016+ if (buf_p != buf_end ) {
1017+ * buf_p ++ = * data ;
1018+ }
10511019
1052- /* U+0030 DIGIT ZERO (0) and U+0039 DIGIT NINE (9) */
1053- do {
1054- if (buf_p != buf_end ) {
1055- * buf_p ++ = * data ;
1020+ data += 1 ;
10561021 }
1022+ while (data < end && * data >= 0x30 && * data <= 0x39 );
10571023
1058- data += 1 ;
1024+ exponent = - (int ) (buf_p - begin );
1025+ is_float = true;
10591026
10601027 if (data >= end ) {
1061- exponent = 0 - (int ) (data - begin );
1062-
1063- lxb_css_syntax_consume_numeric_set_float (tkz , token , buf ,
1064- buf_p , 0 , exponent , 0 );
1028+ lxb_css_syntax_consume_numeric_set (tkz , token , buf , buf_p ,
1029+ true, false, exponent , 0 );
10651030 return data ;
10661031 }
10671032 }
1068- while (* data >= 0x30 && * data <= 0x39 );
10691033
10701034 ch = * data ;
1071- exponent = 0 - (int ) (data - begin );
10721035
10731036 /* U+0045 Latin Capital Letter (E) or U+0065 Latin Small Letter (e) */
10741037 if (ch != 0x45 && ch != 0x65 ) {
1075- lxb_css_syntax_consume_numeric_set_float (tkz , token , buf ,
1076- buf_p , 0 , exponent , 0 );
1038+ lxb_css_syntax_consume_numeric_set (tkz , token , buf , buf_p ,
1039+ is_float , false , exponent , 0 );
10771040
10781041 return lxb_css_syntax_state_consume_numeric_name_start (tkz , token ,
10791042 data , end );
@@ -1087,11 +1050,10 @@ lxb_css_syntax_state_decimal(lxb_css_syntax_tokenizer_t *tkz,
10871050 data -= 1 ;
10881051
10891052 lxb_css_syntax_token_base (t_str )-> length = 1 ;
1090-
10911053 lxb_css_syntax_buffer_append_m (tkz , data , 1 );
10921054
1093- lxb_css_syntax_consume_numeric_set_float (tkz , token , buf ,
1094- buf_p , 0 , exponent , 0 );
1055+ lxb_css_syntax_consume_numeric_set (tkz , token , buf , buf_p ,
1056+ is_float , false , exponent , 0 );
10951057
10961058 token -> type = LXB_CSS_SYNTAX_TOKEN_DIMENSION ;
10971059
@@ -1122,8 +1084,8 @@ lxb_css_syntax_state_decimal(lxb_css_syntax_tokenizer_t *tkz,
11221084 data -= 1 ;
11231085 }
11241086
1125- lxb_css_syntax_consume_numeric_set_float (tkz , token , buf ,
1126- buf_p , 0 , exponent , 0 );
1087+ lxb_css_syntax_consume_numeric_set (tkz , token , buf , buf_p ,
1088+ is_float , false , exponent , 0 );
11271089
11281090 token -> type = LXB_CSS_SYNTAX_TOKEN_DIMENSION ;
11291091
@@ -1135,7 +1097,6 @@ lxb_css_syntax_state_decimal(lxb_css_syntax_tokenizer_t *tkz,
11351097 return begin ;
11361098 }
11371099
1138- begin = data ;
11391100 e_digit = 0 ;
11401101
11411102 /* U+0030 DIGIT ZERO (0) and U+0039 DIGIT NINE (9) */
@@ -1145,16 +1106,17 @@ lxb_css_syntax_state_decimal(lxb_css_syntax_tokenizer_t *tkz,
11451106 data += 1 ;
11461107
11471108 if (data >= end ) {
1148- lxb_css_syntax_consume_numeric_set_float (tkz , token , buf , buf_p ,
1149- e_is_negative , exponent ,
1150- e_digit );
1151- return data ;
1109+ lxb_css_syntax_consume_numeric_set (tkz , token , buf , buf_p ,
1110+ true, e_is_negative ,
1111+ exponent , e_digit );
1112+ return data ;
11521113 }
11531114 }
11541115 while (* data >= 0x30 && * data <= 0x39 );
11551116
1156- lxb_css_syntax_consume_numeric_set_float (tkz , token , buf , buf_p ,
1157- e_is_negative , exponent , e_digit );
1117+ lxb_css_syntax_consume_numeric_set (tkz , token , buf , buf_p ,
1118+ true, e_is_negative ,
1119+ exponent , e_digit );
11581120
11591121 return lxb_css_syntax_state_consume_numeric_name_start (tkz , token ,
11601122 data , end );
0 commit comments