diff options
author | Ali Alzyod <ali198724@gmail.com> | 2020-08-05 11:27:03 +0900 |
---|---|---|
committer | WooHyun Jung <wh0705.jung@samsung.com> | 2020-08-05 11:27:04 +0900 |
commit | 86c274ea3395a02ee9ee2a252113982e4f60077e (patch) | |
tree | ca78867a2aa227dbd0e4e6a071c08b657bccdc78 /src/lib/evas | |
parent | 5d3497e506e0ec8fed17db83ca22119cc693e77d (diff) |
evas_textblock: enhance escape character handling
Summary:
-Lazy initialization for html escapes lists
-Lower memory consumtion for escapes lists
-Simplify code maintenance by sorting lists on runtime, new items donot need to respect sort order(run time will handle it)
Reviewers: woohyun, bowonryu, cedric, tasn
Reviewed By: woohyun
Subscribers: cedric, #reviewers, #committers
Tags: #efl
Differential Revision: https://phab.enlightenment.org/D9370
Diffstat (limited to 'src/lib/evas')
-rw-r--r-- | src/lib/evas/canvas/evas_object_textblock.c | 433 |
1 files changed, 226 insertions, 207 deletions
diff --git a/src/lib/evas/canvas/evas_object_textblock.c b/src/lib/evas/canvas/evas_object_textblock.c index 4c6fc865d8..6ed1593e15 100644 --- a/src/lib/evas/canvas/evas_object_textblock.c +++ b/src/lib/evas/canvas/evas_object_textblock.c | |||
@@ -968,12 +968,6 @@ _line_free(Evas_Object_Textblock_Line *ln) | |||
968 | */ | 968 | */ |
969 | 969 | ||
970 | 970 | ||
971 | /** | ||
972 | * @internal | ||
973 | * @var escape_values_e_sorted[] | ||
974 | * This array consists of Escape_Value structure sorted by escape string | ||
975 | * And new added value must be placed sorted position, and reflected on escape_values_v_sorted | ||
976 | */ | ||
977 | typedef struct _Escape_Value Escape_Value; | 971 | typedef struct _Escape_Value Escape_Value; |
978 | 972 | ||
979 | struct _Escape_Value | 973 | struct _Escape_Value |
@@ -986,7 +980,27 @@ struct _Escape_Value | |||
986 | 980 | ||
987 | #define ESCAPE_VALUE(e,v) {e,v,strlen(e),strlen(v)} | 981 | #define ESCAPE_VALUE(e,v) {e,v,strlen(e),strlen(v)} |
988 | 982 | ||
989 | static const Escape_Value escape_values_e_sorted[] = { | 983 | /** |
984 | * @internal | ||
985 | * @var html_common_escapes[] | ||
986 | * This array consists of most common html escapes values as _Escape_Value structure | ||
987 | */ | ||
988 | static const Escape_Value html_common_escapes[] = { | ||
989 | ESCAPE_VALUE("&", "\x26"), | ||
990 | ESCAPE_VALUE("'", "\x27"), | ||
991 | ESCAPE_VALUE(">", "\x3e"), | ||
992 | ESCAPE_VALUE("<", "\x3c"), | ||
993 | ESCAPE_VALUE(""", "\x22"), | ||
994 | }; | ||
995 | |||
996 | |||
997 | /** | ||
998 | * @internal | ||
999 | * @var escape_values_e_common_sorted[] | ||
1000 | * This array consists of rest html escapes values as _Escape_Value structure | ||
1001 | */ | ||
1002 | |||
1003 | static const Escape_Value html_escapes[] = { | ||
990 | ESCAPE_VALUE("Á", "\xc3\x81"), | 1004 | ESCAPE_VALUE("Á", "\xc3\x81"), |
991 | ESCAPE_VALUE("Â", "\xc3\x82"), | 1005 | ESCAPE_VALUE("Â", "\xc3\x82"), |
992 | ESCAPE_VALUE("&Aelig;", "\xc3\x86"), | 1006 | ESCAPE_VALUE("&Aelig;", "\xc3\x86"), |
@@ -1104,7 +1118,7 @@ static const Escape_Value escape_values_e_sorted[] = { | |||
1104 | ESCAPE_VALUE("ψ", "\xce\xa8"), | 1118 | ESCAPE_VALUE("ψ", "\xce\xa8"), |
1105 | ESCAPE_VALUE("»", "\xc2\xbb"), | 1119 | ESCAPE_VALUE("»", "\xc2\xbb"), |
1106 | ESCAPE_VALUE("→", "\xe2\x86\x92"), | 1120 | ESCAPE_VALUE("→", "\xe2\x86\x92"), |
1107 | ESCAPE_VALUE("→", "\xe2\x87\x92"), | 1121 | ESCAPE_VALUE("⇒", "\xe2\x87\x92"), |
1108 | ESCAPE_VALUE("®", "\xc2\xae"), | 1122 | ESCAPE_VALUE("®", "\xc2\xae"), |
1109 | ESCAPE_VALUE("ρ", "\xce\xa1"), | 1123 | ESCAPE_VALUE("ρ", "\xce\xa1"), |
1110 | ESCAPE_VALUE("‏", "\xe2\x80\x8f"), | 1124 | ESCAPE_VALUE("‏", "\xe2\x80\x8f"), |
@@ -1136,188 +1150,182 @@ static const Escape_Value escape_values_e_sorted[] = { | |||
1136 | ESCAPE_VALUE("‌", "\xe2\x80\x8c"), | 1150 | ESCAPE_VALUE("‌", "\xe2\x80\x8c"), |
1137 | }; | 1151 | }; |
1138 | 1152 | ||
1153 | static int | ||
1154 | _escape_key_sort(const void *a, const void *b) | ||
1155 | { | ||
1156 | const char *k_a = (*(const Escape_Value **) a)->escape; | ||
1157 | const char *k_b = (*(const Escape_Value **) b)->escape; | ||
1158 | return strcmp(k_a, k_b); | ||
1159 | } | ||
1139 | 1160 | ||
1140 | /** | 1161 | static int |
1141 | * @internal | 1162 | _escape_value_sort(const void *a, const void *b) |
1142 | * @var escape_values_e_common_sorted[] | 1163 | { |
1143 | * same as escape_values_e_sorted with small subset of common escapes | 1164 | const char *v_a = (*(const Escape_Value **) a)->value; |
1144 | */ | 1165 | const char *v_b = (*(const Escape_Value **) b)->value; |
1145 | static const Escape_Value escape_values_e_common_sorted[] = { | 1166 | return strcmp(v_a, v_b); |
1146 | ESCAPE_VALUE("&", "\x26"), | 1167 | } |
1147 | ESCAPE_VALUE("'", "\x27"), | ||
1148 | ESCAPE_VALUE(">", "\x3e"), | ||
1149 | ESCAPE_VALUE("<", "\x3c"), | ||
1150 | ESCAPE_VALUE(""", "\x22"), | ||
1151 | }; | ||
1152 | 1168 | ||
1153 | /** | 1169 | static Escape_Value ** |
1154 | * @internal | 1170 | escape_sorted_common_key_copy() |
1155 | * @var escape_values_v_sorted[] | 1171 | { |
1156 | * This array consists of Escape_Value structure sorted by escape value | 1172 | int i; |
1157 | * And new added value must be placed sorted position, and reflected on escape_values_e_sorted | 1173 | int len; |
1158 | */ | 1174 | const Escape_Value *source; |
1159 | static const Escape_Value escape_values_v_sorted[] = { | 1175 | int (*compare_fun)(const void*,const void*); |
1160 | ESCAPE_VALUE(" ", "\xc2\xa0"), | ||
1161 | ESCAPE_VALUE("¡", "\xc2\xa1"), | ||
1162 | ESCAPE_VALUE("¢", "\xc2\xa2"), | ||
1163 | ESCAPE_VALUE("£", "\xc2\xa3"), | ||
1164 | ESCAPE_VALUE("¤", "\xc2\xa4"), | ||
1165 | ESCAPE_VALUE("¥", "\xc2\xa5"), | ||
1166 | ESCAPE_VALUE("¦", "\xc2\xa6"), | ||
1167 | ESCAPE_VALUE("§", "\xc2\xa7"), | ||
1168 | ESCAPE_VALUE("¨", "\xc2\xa8"), | ||
1169 | ESCAPE_VALUE("©", "\xc2\xa9"), | ||
1170 | ESCAPE_VALUE("ª", "\xc2\xaa"), | ||
1171 | ESCAPE_VALUE("«", "\xc2\xab"), | ||
1172 | ESCAPE_VALUE("¬", "\xc2\xac"), | ||
1173 | ESCAPE_VALUE("­", "\xc2\xad"), | ||
1174 | ESCAPE_VALUE("®", "\xc2\xae"), | ||
1175 | ESCAPE_VALUE("¯", "\xc2\xaf"), | ||
1176 | ESCAPE_VALUE("°", "\xc2\xb0"), | ||
1177 | ESCAPE_VALUE("±", "\xc2\xb1"), | ||
1178 | ESCAPE_VALUE("²", "\xc2\xb2"), | ||
1179 | ESCAPE_VALUE("³", "\xc2\xb3"), | ||
1180 | ESCAPE_VALUE("´", "\xc2\xb4"), | ||
1181 | ESCAPE_VALUE("µ", "\xc2\xb5"), | ||
1182 | ESCAPE_VALUE("¶", "\xc2\xb6"), | ||
1183 | ESCAPE_VALUE("·", "\xc2\xb7"), | ||
1184 | ESCAPE_VALUE("¸", "\xc2\xb8"), | ||
1185 | ESCAPE_VALUE("¹", "\xc2\xb9"), | ||
1186 | ESCAPE_VALUE("º", "\xc2\xba"), | ||
1187 | ESCAPE_VALUE("»", "\xc2\xbb"), | ||
1188 | ESCAPE_VALUE("¼", "\xc2\xbc"), | ||
1189 | ESCAPE_VALUE("½", "\xc2\xbd"), | ||
1190 | ESCAPE_VALUE("¾", "\xc2\xbe"), | ||
1191 | ESCAPE_VALUE("¿", "\xc2\xbf"), | ||
1192 | ESCAPE_VALUE("À", "\xc3\x80"), | ||
1193 | ESCAPE_VALUE("Á", "\xc3\x81"), | ||
1194 | ESCAPE_VALUE("Â", "\xc3\x82"), | ||
1195 | ESCAPE_VALUE("Ã", "\xc3\x83"), | ||
1196 | ESCAPE_VALUE("Ä", "\xc3\x84"), | ||
1197 | ESCAPE_VALUE("Å", "\xc3\x85"), | ||
1198 | ESCAPE_VALUE("&Aelig;", "\xc3\x86"), | ||
1199 | ESCAPE_VALUE("Ç", "\xc3\x87"), | ||
1200 | ESCAPE_VALUE("È", "\xc3\x88"), | ||
1201 | ESCAPE_VALUE("É", "\xc3\x89"), | ||
1202 | ESCAPE_VALUE("Ê", "\xc3\x8a"), | ||
1203 | ESCAPE_VALUE("Ë", "\xc3\x8b"), | ||
1204 | ESCAPE_VALUE("Ì", "\xc3\x8c"), | ||
1205 | ESCAPE_VALUE("Í", "\xc3\x8d"), | ||
1206 | ESCAPE_VALUE("Î", "\xc3\x8e"), | ||
1207 | ESCAPE_VALUE("Ï", "\xc3\x8f"), | ||
1208 | ESCAPE_VALUE("&Eth;", "\xc3\x90"), | ||
1209 | ESCAPE_VALUE("Ñ", "\xc3\x91"), | ||
1210 | ESCAPE_VALUE("Ò", "\xc3\x92"), | ||
1211 | ESCAPE_VALUE("Ó", "\xc3\x93"), | ||
1212 | ESCAPE_VALUE("Ô", "\xc3\x94"), | ||
1213 | ESCAPE_VALUE("Õ", "\xc3\x95"), | ||
1214 | ESCAPE_VALUE("Ö", "\xc3\x96"), | ||
1215 | ESCAPE_VALUE("×", "\xc3\x97"), | ||
1216 | ESCAPE_VALUE("Ø", "\xc3\x98"), | ||
1217 | ESCAPE_VALUE("Ù", "\xc3\x99"), | ||
1218 | ESCAPE_VALUE("Ú", "\xc3\x9a"), | ||
1219 | ESCAPE_VALUE("Û", "\xc3\x9b"), | ||
1220 | ESCAPE_VALUE("Ý", "\xc3\x9d"), | ||
1221 | ESCAPE_VALUE("&Thorn;", "\xc3\x9e"), | ||
1222 | ESCAPE_VALUE("ß", "\xc3\x9f"), | ||
1223 | ESCAPE_VALUE("à", "\xc3\xa0"), | ||
1224 | ESCAPE_VALUE("á", "\xc3\xa1"), | ||
1225 | ESCAPE_VALUE("â", "\xc3\xa2"), | ||
1226 | ESCAPE_VALUE("ã", "\xc3\xa3"), | ||
1227 | ESCAPE_VALUE("ä", "\xc3\xa4"), | ||
1228 | ESCAPE_VALUE("å", "\xc3\xa5"), | ||
1229 | ESCAPE_VALUE("æ", "\xc3\xa6"), | ||
1230 | ESCAPE_VALUE("ç", "\xc3\xa7"), | ||
1231 | ESCAPE_VALUE("è", "\xc3\xa8"), | ||
1232 | ESCAPE_VALUE("é", "\xc3\xa9"), | ||
1233 | ESCAPE_VALUE("ê", "\xc3\xaa"), | ||
1234 | ESCAPE_VALUE("ë", "\xc3\xab"), | ||
1235 | ESCAPE_VALUE("ì", "\xc3\xac"), | ||
1236 | ESCAPE_VALUE("í", "\xc3\xad"), | ||
1237 | ESCAPE_VALUE("î", "\xc3\xae"), | ||
1238 | ESCAPE_VALUE("ï", "\xc3\xaf"), | ||
1239 | ESCAPE_VALUE("ð", "\xc3\xb0"), | ||
1240 | ESCAPE_VALUE("ñ", "\xc3\xb1"), | ||
1241 | ESCAPE_VALUE("ò", "\xc3\xb2"), | ||
1242 | ESCAPE_VALUE("ó", "\xc3\xb3"), | ||
1243 | ESCAPE_VALUE("ô", "\xc3\xb4"), | ||
1244 | ESCAPE_VALUE("õ", "\xc3\xb5"), | ||
1245 | ESCAPE_VALUE("ö", "\xc3\xb6"), | ||
1246 | ESCAPE_VALUE("÷", "\xc3\xb7"), | ||
1247 | ESCAPE_VALUE("ø", "\xc3\xb8"), | ||
1248 | ESCAPE_VALUE("ù", "\xc3\xb9"), | ||
1249 | ESCAPE_VALUE("ú", "\xc3\xba"), | ||
1250 | ESCAPE_VALUE("û", "\xc3\xbb"), | ||
1251 | ESCAPE_VALUE("ü", "\xc3\xbc"), | ||
1252 | ESCAPE_VALUE("ý", "\xc3\xbd"), | ||
1253 | ESCAPE_VALUE("þ", "\xc3\xbe"), | ||
1254 | ESCAPE_VALUE("ÿ", "\xc3\xbf"), | ||
1255 | ESCAPE_VALUE("α", "\xce\x91"), | ||
1256 | ESCAPE_VALUE("β", "\xce\x92"), | ||
1257 | ESCAPE_VALUE("γ", "\xce\x93"), | ||
1258 | ESCAPE_VALUE("δ", "\xce\x94"), | ||
1259 | ESCAPE_VALUE("ε", "\xce\x95"), | ||
1260 | ESCAPE_VALUE("ζ", "\xce\x96"), | ||
1261 | ESCAPE_VALUE("η", "\xce\x97"), | ||
1262 | ESCAPE_VALUE("θ", "\xce\x98"), | ||
1263 | ESCAPE_VALUE("ι", "\xce\x99"), | ||
1264 | ESCAPE_VALUE("κ", "\xce\x9a"), | ||
1265 | ESCAPE_VALUE("λ", "\xce\x9b"), | ||
1266 | ESCAPE_VALUE("μ", "\xce\x9c"), | ||
1267 | ESCAPE_VALUE("ν", "\xce\x9d"), | ||
1268 | ESCAPE_VALUE("ξ", "\xce\x9e"), | ||
1269 | ESCAPE_VALUE("ο", "\xce\x9f"), | ||
1270 | ESCAPE_VALUE("π", "\xce\xa0"), | ||
1271 | ESCAPE_VALUE("ρ", "\xce\xa1"), | ||
1272 | ESCAPE_VALUE("σ", "\xce\xa3"), | ||
1273 | ESCAPE_VALUE("τ", "\xce\xa4"), | ||
1274 | ESCAPE_VALUE("υ", "\xce\xa5"), | ||
1275 | ESCAPE_VALUE("φ", "\xce\xa6"), | ||
1276 | ESCAPE_VALUE("χ", "\xce\xa7"), | ||
1277 | ESCAPE_VALUE("ψ", "\xce\xa8"), | ||
1278 | ESCAPE_VALUE("ω", "\xce\xa9"), | ||
1279 | ESCAPE_VALUE("‌", "\xe2\x80\x8c"), | ||
1280 | ESCAPE_VALUE("‍", "\xe2\x80\x8d"), | ||
1281 | ESCAPE_VALUE("‎", "\xe2\x80\x8e"), | ||
1282 | ESCAPE_VALUE("‏", "\xe2\x80\x8f"), | ||
1283 | ESCAPE_VALUE("†", "\xe2\x80\xa0"), | ||
1284 | ESCAPE_VALUE("‡", "\xe2\x80\xa1"), | ||
1285 | ESCAPE_VALUE("•", "\xe2\x80\xa2"), | ||
1286 | ESCAPE_VALUE("…", "\xe2\x80\xa6"), | ||
1287 | ESCAPE_VALUE("€", "\xe2\x82\xac"), | ||
1288 | ESCAPE_VALUE("←", "\xe2\x86\x90"), | ||
1289 | ESCAPE_VALUE("↑", "\xe2\x86\x91"), | ||
1290 | ESCAPE_VALUE("→", "\xe2\x86\x92"), | ||
1291 | ESCAPE_VALUE("↓", "\xe2\x86\x93"), | ||
1292 | ESCAPE_VALUE("↔", "\xe2\x86\x94"), | ||
1293 | ESCAPE_VALUE("←", "\xe2\x87\x90"), | ||
1294 | ESCAPE_VALUE("→", "\xe2\x87\x92"), | ||
1295 | ESCAPE_VALUE("∀", "\xe2\x88\x80"), | ||
1296 | ESCAPE_VALUE("∃", "\xe2\x88\x83"), | ||
1297 | ESCAPE_VALUE("∇", "\xe2\x88\x87"), | ||
1298 | ESCAPE_VALUE("∏", "\xe2\x88\x8f"), | ||
1299 | ESCAPE_VALUE("∑", "\xe2\x88\x91"), | ||
1300 | ESCAPE_VALUE("∧", "\xe2\x88\xa7"), | ||
1301 | ESCAPE_VALUE("∨", "\xe2\x88\xa8"), | ||
1302 | ESCAPE_VALUE("∫", "\xe2\x88\xab"), | ||
1303 | ESCAPE_VALUE("≠", "\xe2\x89\xa0"), | ||
1304 | ESCAPE_VALUE("≡", "\xe2\x89\xa1"), | ||
1305 | ESCAPE_VALUE("⊕", "\xe2\x8a\x95"), | ||
1306 | ESCAPE_VALUE("⊥", "\xe2\x8a\xa5"), | ||
1307 | }; | ||
1308 | 1176 | ||
1309 | /** | 1177 | len = sizeof(html_common_escapes) / sizeof(Escape_Value); |
1310 | * @internal | 1178 | source = html_common_escapes; |
1311 | * @var escape_values_v_common_sorted[] | 1179 | |
1312 | * same as escape_values_v_sorted with small subset of common escapes | 1180 | compare_fun = _escape_key_sort; |
1313 | */ | 1181 | |
1314 | static const Escape_Value escape_values_v_common_sorted[] = { | 1182 | Escape_Value **ret_list = malloc(len * sizeof(Escape_Value *)); |
1315 | ESCAPE_VALUE(""", "\x22"), | 1183 | for (i = 0 ; i < len ; i++) |
1316 | ESCAPE_VALUE("&", "\x26"), | 1184 | { |
1317 | ESCAPE_VALUE("'", "\x27"), | 1185 | ret_list[i] = (Escape_Value *)(&source[i]); |
1318 | ESCAPE_VALUE("<", "\x3c"), | 1186 | } |
1319 | ESCAPE_VALUE(">", "\x3e"), | 1187 | |
1320 | }; | 1188 | qsort(&ret_list[0], len, sizeof(Escape_Value *), compare_fun); |
1189 | return ret_list; | ||
1190 | } | ||
1191 | |||
1192 | static Escape_Value ** | ||
1193 | escape_sorted_common_value_copy() | ||
1194 | { | ||
1195 | int i; | ||
1196 | int len; | ||
1197 | const Escape_Value *source; | ||
1198 | int (*compare_fun)(const void*,const void*); | ||
1199 | |||
1200 | len = sizeof(html_common_escapes) / sizeof(Escape_Value); | ||
1201 | source = html_common_escapes; | ||
1202 | |||
1203 | compare_fun = _escape_value_sort; | ||
1204 | |||
1205 | Escape_Value **ret_list = malloc(len * sizeof(Escape_Value *)); | ||
1206 | for (i = 0 ; i < len ; i++) | ||
1207 | { | ||
1208 | ret_list[i] = (Escape_Value *)(&source[i]); | ||
1209 | } | ||
1210 | |||
1211 | qsort(&ret_list[0], len, sizeof(Escape_Value *), compare_fun); | ||
1212 | return ret_list; | ||
1213 | } | ||
1214 | |||
1215 | static Escape_Value ** | ||
1216 | escape_sorted_rest_key_copy() | ||
1217 | { | ||
1218 | int i; | ||
1219 | int len; | ||
1220 | const Escape_Value *source; | ||
1221 | int (*compare_fun)(const void*,const void*); | ||
1222 | |||
1223 | len = sizeof(html_escapes) / sizeof(Escape_Value); | ||
1224 | source = html_escapes; | ||
1225 | |||
1226 | compare_fun = _escape_key_sort; | ||
1227 | |||
1228 | Escape_Value **ret_list = malloc(len * sizeof(Escape_Value *)); | ||
1229 | for (i = 0 ; i < len ; i++) | ||
1230 | { | ||
1231 | ret_list[i] = (Escape_Value *)(&source[i]); | ||
1232 | } | ||
1233 | |||
1234 | qsort(&ret_list[0], len, sizeof(Escape_Value *), compare_fun); | ||
1235 | return ret_list; | ||
1236 | } | ||
1237 | |||
1238 | static Escape_Value ** | ||
1239 | escape_sorted_rest_value_copy() | ||
1240 | { | ||
1241 | int i; | ||
1242 | int len; | ||
1243 | const Escape_Value *source; | ||
1244 | int (*compare_fun)(const void*,const void*); | ||
1245 | len = sizeof(html_escapes) / sizeof(Escape_Value); | ||
1246 | source = html_escapes; | ||
1247 | |||
1248 | compare_fun = _escape_value_sort; | ||
1249 | |||
1250 | Escape_Value **ret_list = malloc(len * sizeof(Escape_Value *)); | ||
1251 | for (i = 0 ; i < len ; i++) | ||
1252 | { | ||
1253 | ret_list[i] = (Escape_Value *)(&source[i]); | ||
1254 | } | ||
1255 | |||
1256 | qsort(&ret_list[0], len, sizeof(Escape_Value *), compare_fun); | ||
1257 | return ret_list; | ||
1258 | } | ||
1259 | |||
1260 | static Escape_Value ** | ||
1261 | get_html_escape_array_common_key_sorted(size_t *p_len) | ||
1262 | { | ||
1263 | static Escape_Value **escape_values_common_k_sorted = NULL; | ||
1264 | |||
1265 | static size_t common_len = sizeof(html_common_escapes) / sizeof(Escape_Value); | ||
1266 | |||
1267 | Escape_Value **ret_list = NULL; | ||
1268 | |||
1269 | if (!escape_values_common_k_sorted) | ||
1270 | escape_values_common_k_sorted = escape_sorted_common_key_copy(); | ||
1271 | ret_list = escape_values_common_k_sorted; | ||
1272 | if(p_len) *p_len = common_len; | ||
1273 | |||
1274 | |||
1275 | return ret_list; | ||
1276 | } | ||
1277 | |||
1278 | static Escape_Value ** | ||
1279 | get_html_escape_array_common_value_sorted(size_t *p_len) | ||
1280 | { | ||
1281 | static Escape_Value **escape_values_common_v_sorted = NULL; | ||
1282 | |||
1283 | static size_t common_len = sizeof(html_common_escapes) / sizeof(Escape_Value); | ||
1284 | |||
1285 | Escape_Value **ret_list = NULL; | ||
1286 | |||
1287 | if (!escape_values_common_v_sorted) | ||
1288 | escape_values_common_v_sorted = escape_sorted_common_value_copy(); | ||
1289 | ret_list = escape_values_common_v_sorted; | ||
1290 | if(p_len) *p_len = common_len; | ||
1291 | |||
1292 | |||
1293 | return ret_list; | ||
1294 | } | ||
1295 | |||
1296 | static Escape_Value ** | ||
1297 | get_html_escape_array_rest_key_sorted(size_t *p_len) | ||
1298 | { | ||
1299 | static Escape_Value **escape_values_k_sorted = NULL; | ||
1300 | |||
1301 | static size_t rest_len = sizeof(html_escapes) / sizeof(Escape_Value); | ||
1302 | |||
1303 | Escape_Value **ret_list = NULL; | ||
1304 | |||
1305 | if (!escape_values_k_sorted) | ||
1306 | escape_values_k_sorted = escape_sorted_rest_key_copy(); | ||
1307 | ret_list = escape_values_k_sorted; | ||
1308 | if(p_len) *p_len = rest_len; | ||
1309 | |||
1310 | return ret_list; | ||
1311 | } | ||
1312 | |||
1313 | static Escape_Value ** | ||
1314 | get_html_escape_array_rest_value_sorted(size_t *p_len) | ||
1315 | { | ||
1316 | static Escape_Value **escape_values_v_sorted = NULL; | ||
1317 | |||
1318 | static size_t rest_len = sizeof(html_escapes) / sizeof(Escape_Value); | ||
1319 | |||
1320 | Escape_Value **ret_list = NULL; | ||
1321 | |||
1322 | if (!escape_values_v_sorted) | ||
1323 | escape_values_v_sorted = escape_sorted_rest_value_copy(); | ||
1324 | ret_list = escape_values_v_sorted; | ||
1325 | if(p_len) *p_len = rest_len; | ||
1326 | |||
1327 | return ret_list; | ||
1328 | } | ||
1321 | 1329 | ||
1322 | /** | 1330 | /** |
1323 | * @internal | 1331 | * @internal |
@@ -8490,22 +8498,25 @@ _escaped_is_eq_and_advance(const char *s, const char *s_end, | |||
8490 | * @param escape_values_len is the len of Escape_Value array | 8498 | * @param escape_values_len is the len of Escape_Value array |
8491 | */ | 8499 | */ |
8492 | static int | 8500 | static int |
8493 | _escaped_string_search(const char *s, size_t s_len, const Escape_Value escape_values[], const size_t escape_values_len) | 8501 | _escaped_string_search(const char *s, size_t s_len, Escape_Value **escape_values, const size_t escape_values_len) |
8494 | { | 8502 | { |
8503 | if (!escape_values) | ||
8504 | return -1; | ||
8505 | |||
8495 | int l = 0; | 8506 | int l = 0; |
8496 | int r = escape_values_len - 1; | 8507 | int r = escape_values_len - 1; |
8497 | while (l <= r) | 8508 | while (l <= r) |
8498 | { | 8509 | { |
8499 | int m = (l + r) / 2; | 8510 | int m = (l + r) / 2; |
8500 | int res = strncmp(s, escape_values[m].escape, MAX(escape_values[m].escape_len, s_len)); | 8511 | int res = strncmp(s, escape_values[m]->escape, MAX(escape_values[m]->escape_len, s_len)); |
8501 | if (res == 0) | 8512 | if (res == 0) |
8502 | { | 8513 | { |
8503 | //Handle special case when s_len is less than escape_len | 8514 | //Handle special case when s_len is less than escape_len |
8504 | //then we will continue searching | 8515 | //then we will continue searching |
8505 | //example (">",1,....) | 8516 | //example (">",1,....) |
8506 | if (escape_values[m].escape_len > s_len) | 8517 | if (escape_values[m]->escape_len > s_len) |
8507 | res = -1; | 8518 | res = -1; |
8508 | else if (escape_values[m].escape_len < s_len) | 8519 | else if (escape_values[m]->escape_len < s_len) |
8509 | res = 1; | 8520 | res = 1; |
8510 | else return m; | 8521 | else return m; |
8511 | } | 8522 | } |
@@ -8525,14 +8536,17 @@ _escaped_string_search(const char *s, size_t s_len, const Escape_Value escape_va | |||
8525 | * @param escape_values_len is the len of Escape_Value array | 8536 | * @param escape_values_len is the len of Escape_Value array |
8526 | */ | 8537 | */ |
8527 | static int | 8538 | static int |
8528 | _escaped_value_search(const char *s, const Escape_Value escape_values[], const size_t escape_values_len) | 8539 | _escaped_value_search(const char *s, Escape_Value **escape_values , const size_t escape_values_len) |
8529 | { | 8540 | { |
8541 | if (!escape_values) | ||
8542 | return -1; | ||
8543 | |||
8530 | int l = 0; | 8544 | int l = 0; |
8531 | int r = escape_values_len - 1; | 8545 | int r = escape_values_len - 1; |
8532 | while (l <= r) | 8546 | while (l <= r) |
8533 | { | 8547 | { |
8534 | int m = (l + r) / 2; | 8548 | int m = (l + r) / 2; |
8535 | int res = strncmp(s, escape_values[m].value, escape_values[m].value_len); | 8549 | int res = strncmp(s, escape_values[m]->value, escape_values[m]->value_len); |
8536 | if (res == 0) | 8550 | if (res == 0) |
8537 | return m; | 8551 | return m; |
8538 | if (res > 0) | 8552 | if (res > 0) |
@@ -8553,21 +8567,22 @@ _escaped_value_search(const char *s, const Escape_Value escape_values[], const s | |||
8553 | static inline const char * | 8567 | static inline const char * |
8554 | _escaped_char_match(const char *s, int *adv) | 8568 | _escaped_char_match(const char *s, int *adv) |
8555 | { | 8569 | { |
8556 | static const size_t escape_common_size = sizeof(escape_values_v_common_sorted) / sizeof(Escape_Value); | 8570 | size_t len = 0; |
8557 | int n_ret = _escaped_value_search(s, escape_values_v_common_sorted, escape_common_size); | 8571 | Escape_Value **list = get_html_escape_array_common_value_sorted(&len); |
8572 | int n_ret = _escaped_value_search(s, list, len); | ||
8558 | if (n_ret != -1) | 8573 | if (n_ret != -1) |
8559 | { | 8574 | { |
8560 | *adv = (int) escape_values_v_common_sorted[n_ret].value_len; | 8575 | *adv = (int) list[n_ret]->value_len; |
8561 | return escape_values_v_common_sorted[n_ret].escape; | 8576 | return list[n_ret]->escape; |
8562 | } | 8577 | } |
8563 | else | 8578 | else |
8564 | { | 8579 | { |
8565 | static const size_t escape_size = sizeof(escape_values_v_sorted) / sizeof(Escape_Value); | 8580 | list = get_html_escape_array_rest_value_sorted(&len); |
8566 | n_ret = _escaped_value_search(s, escape_values_v_sorted, escape_size); | 8581 | n_ret = _escaped_value_search(s, list, len); |
8567 | if (n_ret != -1) | 8582 | if (n_ret != -1) |
8568 | { | 8583 | { |
8569 | *adv = (int)escape_values_v_sorted[n_ret].value_len; | 8584 | *adv = (int)list[n_ret]->value_len; |
8570 | return escape_values_v_sorted[n_ret].escape; | 8585 | return list[n_ret]->escape; |
8571 | } | 8586 | } |
8572 | } | 8587 | } |
8573 | return NULL; | 8588 | return NULL; |
@@ -8623,18 +8638,22 @@ _escaped_char_get(const char *s, const char *s_end) | |||
8623 | } | 8638 | } |
8624 | else | 8639 | else |
8625 | { | 8640 | { |
8626 | static const size_t escape_common_size = sizeof(escape_values_e_common_sorted) / sizeof(Escape_Value); | 8641 | size_t len = 0; |
8627 | int n_ret = _escaped_string_search(s, s_end-s, escape_values_e_common_sorted, escape_common_size); | 8642 | Escape_Value **list; |
8643 | list = get_html_escape_array_common_key_sorted(&len); | ||
8644 | int n_ret = _escaped_string_search(s, s_end-s, list, len); | ||
8628 | if (n_ret != -1) | 8645 | if (n_ret != -1) |
8629 | { | 8646 | { |
8630 | return escape_values_e_common_sorted[n_ret].value; | 8647 | return list[n_ret]->value; |
8631 | } | 8648 | } |
8632 | else | 8649 | else |
8633 | { | 8650 | { |
8634 | static const size_t escape_size = sizeof(escape_values_e_sorted) / sizeof(Escape_Value); | 8651 | list = get_html_escape_array_rest_key_sorted(&len); |
8635 | n_ret = _escaped_string_search(s, s_end-s, escape_values_e_sorted, escape_size); | 8652 | n_ret = _escaped_string_search(s, s_end-s, list, len); |
8636 | if (n_ret != -1) | 8653 | if (n_ret != -1) |
8637 | return escape_values_e_sorted[n_ret].value; | 8654 | { |
8655 | return list[n_ret]->value; | ||
8656 | } | ||
8638 | } | 8657 | } |
8639 | } | 8658 | } |
8640 | 8659 | ||