@@ -99,13 +99,6 @@ lxb_css_syntax_state_consume_numeric(lxb_css_syntax_tokenizer_t *tkz,
99
99
const lxb_char_t * data ,
100
100
const lxb_char_t * end );
101
101
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
-
109
102
static const lxb_char_t *
110
103
lxb_css_syntax_state_consume_numeric_name_start (lxb_css_syntax_tokenizer_t * tkz ,
111
104
lxb_css_syntax_token_t * token ,
@@ -706,8 +699,6 @@ lxb_css_syntax_state_plus(lxb_css_syntax_tokenizer_t *tkz,
706
699
lxb_css_syntax_token_t * token ,
707
700
const lxb_char_t * data , const lxb_char_t * end )
708
701
{
709
- lxb_char_t buf [128 ];
710
-
711
702
/* Skip U+002B PLUS SIGN (+). */
712
703
data += 1 ;
713
704
@@ -732,8 +723,8 @@ lxb_css_syntax_state_plus(lxb_css_syntax_tokenizer_t *tkz,
732
723
/* U+0030 DIGIT ZERO (0) and U+0039 DIGIT NINE (9) */
733
724
if (* data >= 0x30 && * data <= 0x39 ) {
734
725
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 );
737
728
}
738
729
739
730
data -= 1 ;
@@ -804,6 +795,7 @@ lxb_css_syntax_state_full_stop(lxb_css_syntax_tokenizer_t *tkz,
804
795
const lxb_char_t * data , const lxb_char_t * end )
805
796
{
806
797
if (lxb_css_syntax_state_start_number (data , end )) {
798
+ lxb_css_syntax_token_number (token )-> have_sign = false;
807
799
return lxb_css_syntax_state_consume_numeric (tkz , token , data , end );
808
800
}
809
801
@@ -935,37 +927,26 @@ lxb_css_syntax_state_rc_bracket(lxb_css_syntax_tokenizer_t *tkz, lxb_css_syntax_
935
927
* Numeric
936
928
*/
937
929
lxb_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 )
955
935
{
956
936
if (e_is_negative ) {
957
- exponent -= e_digit ;
937
+ exponent = e_digit - exponent ;
938
+ exponent = - exponent ;
958
939
}
959
940
else {
960
- exponent + = e_digit ;
941
+ exponent = e_digit + exponent ;
961
942
}
962
943
963
944
double num = lexbor_strtod_internal (start , (end - start ), exponent );
964
945
965
946
token -> type = LXB_CSS_SYNTAX_TOKEN_NUMBER ;
966
947
948
+ lxb_css_syntax_token_number (token )-> is_float = is_float ;
967
949
lxb_css_syntax_token_number (token )-> num = num ;
968
- lxb_css_syntax_token_number (token )-> is_float = true;
969
950
}
970
951
971
952
const lxb_char_t *
@@ -985,95 +966,77 @@ lxb_css_syntax_state_consume_numeric(lxb_css_syntax_tokenizer_t *tkz,
985
966
const lxb_char_t * data ,
986
967
const lxb_char_t * end )
987
968
{
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 ;
990
975
lxb_char_t buf [128 ];
991
976
992
977
buf_p = buf ;
993
978
buf_end = buf + sizeof (buf );
994
979
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 ;
1000
982
983
+ /* U+0030 DIGIT ZERO (0) and U+0039 DIGIT NINE (9) */
984
+ while (* data >= 0x30 && * data <= 0x39 ) {
1001
985
if (buf_p != buf_end ) {
1002
986
* buf_p ++ = * data ;
1003
987
}
1004
988
1005
989
data += 1 ;
1006
990
1007
991
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 );
1009
994
return data ;
1010
995
}
1011
996
}
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
- }
1021
997
1022
- data += 1 ;
998
+ exponent = 0 ;
999
+ is_float = false;
1023
1000
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 ;
1032
1004
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
+ }
1046
1011
1047
- begin = data ;
1012
+ begin = buf_p ;
1048
1013
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
+ }
1051
1019
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 ;
1056
1021
}
1022
+ while (data < end && * data >= 0x30 && * data <= 0x39 );
1057
1023
1058
- data += 1 ;
1024
+ exponent = - (int ) (buf_p - begin );
1025
+ is_float = true;
1059
1026
1060
1027
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 );
1065
1030
return data ;
1066
1031
}
1067
1032
}
1068
- while (* data >= 0x30 && * data <= 0x39 );
1069
1033
1070
1034
ch = * data ;
1071
- exponent = 0 - (int ) (data - begin );
1072
1035
1073
1036
/* U+0045 Latin Capital Letter (E) or U+0065 Latin Small Letter (e) */
1074
1037
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 );
1077
1040
1078
1041
return lxb_css_syntax_state_consume_numeric_name_start (tkz , token ,
1079
1042
data , end );
@@ -1087,11 +1050,10 @@ lxb_css_syntax_state_decimal(lxb_css_syntax_tokenizer_t *tkz,
1087
1050
data -= 1 ;
1088
1051
1089
1052
lxb_css_syntax_token_base (t_str )-> length = 1 ;
1090
-
1091
1053
lxb_css_syntax_buffer_append_m (tkz , data , 1 );
1092
1054
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 );
1095
1057
1096
1058
token -> type = LXB_CSS_SYNTAX_TOKEN_DIMENSION ;
1097
1059
@@ -1122,8 +1084,8 @@ lxb_css_syntax_state_decimal(lxb_css_syntax_tokenizer_t *tkz,
1122
1084
data -= 1 ;
1123
1085
}
1124
1086
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 );
1127
1089
1128
1090
token -> type = LXB_CSS_SYNTAX_TOKEN_DIMENSION ;
1129
1091
@@ -1135,7 +1097,6 @@ lxb_css_syntax_state_decimal(lxb_css_syntax_tokenizer_t *tkz,
1135
1097
return begin ;
1136
1098
}
1137
1099
1138
- begin = data ;
1139
1100
e_digit = 0 ;
1140
1101
1141
1102
/* 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,
1145
1106
data += 1 ;
1146
1107
1147
1108
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 ;
1152
1113
}
1153
1114
}
1154
1115
while (* data >= 0x30 && * data <= 0x39 );
1155
1116
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 );
1158
1120
1159
1121
return lxb_css_syntax_state_consume_numeric_name_start (tkz , token ,
1160
1122
data , end );
0 commit comments