summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAli Alzyod <ali198724@gmail.com>2020-08-05 11:27:03 +0900
committerWooHyun Jung <wh0705.jung@samsung.com>2020-08-05 11:27:04 +0900
commit86c274ea3395a02ee9ee2a252113982e4f60077e (patch)
treeca78867a2aa227dbd0e4e6a071c08b657bccdc78
parent5d3497e506e0ec8fed17db83ca22119cc693e77d (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
-rw-r--r--src/lib/evas/canvas/evas_object_textblock.c433
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 */
977typedef struct _Escape_Value Escape_Value; 971typedef struct _Escape_Value Escape_Value;
978 972
979struct _Escape_Value 973struct _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
989static 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 */
988static const Escape_Value html_common_escapes[] = {
989 ESCAPE_VALUE("&amp;", "\x26"),
990 ESCAPE_VALUE("&apos;", "\x27"),
991 ESCAPE_VALUE("&gt;", "\x3e"),
992 ESCAPE_VALUE("&lt;", "\x3c"),
993 ESCAPE_VALUE("&quot;", "\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
1003static const Escape_Value html_escapes[] = {
990 ESCAPE_VALUE("&Aacute;", "\xc3\x81"), 1004 ESCAPE_VALUE("&Aacute;", "\xc3\x81"),
991 ESCAPE_VALUE("&Acirc;", "\xc3\x82"), 1005 ESCAPE_VALUE("&Acirc;", "\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("&psi;", "\xce\xa8"), 1118 ESCAPE_VALUE("&psi;", "\xce\xa8"),
1105 ESCAPE_VALUE("&raquo;", "\xc2\xbb"), 1119 ESCAPE_VALUE("&raquo;", "\xc2\xbb"),
1106 ESCAPE_VALUE("&rarr;", "\xe2\x86\x92"), 1120 ESCAPE_VALUE("&rarr;", "\xe2\x86\x92"),
1107 ESCAPE_VALUE("&rarr;", "\xe2\x87\x92"), 1121 ESCAPE_VALUE("&rArr;", "\xe2\x87\x92"),
1108 ESCAPE_VALUE("&reg;", "\xc2\xae"), 1122 ESCAPE_VALUE("&reg;", "\xc2\xae"),
1109 ESCAPE_VALUE("&rho;", "\xce\xa1"), 1123 ESCAPE_VALUE("&rho;", "\xce\xa1"),
1110 ESCAPE_VALUE("&rlm;", "\xe2\x80\x8f"), 1124 ESCAPE_VALUE("&rlm;", "\xe2\x80\x8f"),
@@ -1136,188 +1150,182 @@ static const Escape_Value escape_values_e_sorted[] = {
1136 ESCAPE_VALUE("&zwnj;", "\xe2\x80\x8c"), 1150 ESCAPE_VALUE("&zwnj;", "\xe2\x80\x8c"),
1137}; 1151};
1138 1152
1153static 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/** 1161static 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;
1145static const Escape_Value escape_values_e_common_sorted[] = { 1166 return strcmp(v_a, v_b);
1146 ESCAPE_VALUE("&amp;", "\x26"), 1167}
1147 ESCAPE_VALUE("&apos;", "\x27"),
1148 ESCAPE_VALUE("&gt;", "\x3e"),
1149 ESCAPE_VALUE("&lt;", "\x3c"),
1150 ESCAPE_VALUE("&quot;", "\x22"),
1151};
1152 1168
1153/** 1169static Escape_Value **
1154 * @internal 1170escape_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;
1159static const Escape_Value escape_values_v_sorted[] = { 1175 int (*compare_fun)(const void*,const void*);
1160 ESCAPE_VALUE("&nbsp;", "\xc2\xa0"),
1161 ESCAPE_VALUE("&iexcl;", "\xc2\xa1"),
1162 ESCAPE_VALUE("&cent;", "\xc2\xa2"),
1163 ESCAPE_VALUE("&pound;", "\xc2\xa3"),
1164 ESCAPE_VALUE("&curren;", "\xc2\xa4"),
1165 ESCAPE_VALUE("&yen;", "\xc2\xa5"),
1166 ESCAPE_VALUE("&brvbar;", "\xc2\xa6"),
1167 ESCAPE_VALUE("&sect;", "\xc2\xa7"),
1168 ESCAPE_VALUE("&uml;", "\xc2\xa8"),
1169 ESCAPE_VALUE("&copy;", "\xc2\xa9"),
1170 ESCAPE_VALUE("&ordf;", "\xc2\xaa"),
1171 ESCAPE_VALUE("&laquo;", "\xc2\xab"),
1172 ESCAPE_VALUE("&not;", "\xc2\xac"),
1173 ESCAPE_VALUE("&shy;", "\xc2\xad"),
1174 ESCAPE_VALUE("&reg;", "\xc2\xae"),
1175 ESCAPE_VALUE("&macr;", "\xc2\xaf"),
1176 ESCAPE_VALUE("&deg;", "\xc2\xb0"),
1177 ESCAPE_VALUE("&plusmn;", "\xc2\xb1"),
1178 ESCAPE_VALUE("&sup2;", "\xc2\xb2"),
1179 ESCAPE_VALUE("&sup3;", "\xc2\xb3"),
1180 ESCAPE_VALUE("&acute;", "\xc2\xb4"),
1181 ESCAPE_VALUE("&micro;", "\xc2\xb5"),
1182 ESCAPE_VALUE("&para;", "\xc2\xb6"),
1183 ESCAPE_VALUE("&middot;", "\xc2\xb7"),
1184 ESCAPE_VALUE("&cedil;", "\xc2\xb8"),
1185 ESCAPE_VALUE("&sup1;", "\xc2\xb9"),
1186 ESCAPE_VALUE("&ordm;", "\xc2\xba"),
1187 ESCAPE_VALUE("&raquo;", "\xc2\xbb"),
1188 ESCAPE_VALUE("&frac14;", "\xc2\xbc"),
1189 ESCAPE_VALUE("&frac12;", "\xc2\xbd"),
1190 ESCAPE_VALUE("&frac34;", "\xc2\xbe"),
1191 ESCAPE_VALUE("&iquest;", "\xc2\xbf"),
1192 ESCAPE_VALUE("&Agrave;", "\xc3\x80"),
1193 ESCAPE_VALUE("&Aacute;", "\xc3\x81"),
1194 ESCAPE_VALUE("&Acirc;", "\xc3\x82"),
1195 ESCAPE_VALUE("&Atilde;", "\xc3\x83"),
1196 ESCAPE_VALUE("&Auml;", "\xc3\x84"),
1197 ESCAPE_VALUE("&Aring;", "\xc3\x85"),
1198 ESCAPE_VALUE("&Aelig;", "\xc3\x86"),
1199 ESCAPE_VALUE("&Ccedil;", "\xc3\x87"),
1200 ESCAPE_VALUE("&Egrave;", "\xc3\x88"),
1201 ESCAPE_VALUE("&Eacute;", "\xc3\x89"),
1202 ESCAPE_VALUE("&Ecirc;", "\xc3\x8a"),
1203 ESCAPE_VALUE("&Euml;", "\xc3\x8b"),
1204 ESCAPE_VALUE("&Igrave;", "\xc3\x8c"),
1205 ESCAPE_VALUE("&Iacute;", "\xc3\x8d"),
1206 ESCAPE_VALUE("&Icirc;", "\xc3\x8e"),
1207 ESCAPE_VALUE("&Iuml;", "\xc3\x8f"),
1208 ESCAPE_VALUE("&Eth;", "\xc3\x90"),
1209 ESCAPE_VALUE("&Ntilde;", "\xc3\x91"),
1210 ESCAPE_VALUE("&Ograve;", "\xc3\x92"),
1211 ESCAPE_VALUE("&Oacute;", "\xc3\x93"),
1212 ESCAPE_VALUE("&Ocirc;", "\xc3\x94"),
1213 ESCAPE_VALUE("&Otilde;", "\xc3\x95"),
1214 ESCAPE_VALUE("&Ouml;", "\xc3\x96"),
1215 ESCAPE_VALUE("&times;", "\xc3\x97"),
1216 ESCAPE_VALUE("&Oslash;", "\xc3\x98"),
1217 ESCAPE_VALUE("&Ugrave;", "\xc3\x99"),
1218 ESCAPE_VALUE("&Uacute;", "\xc3\x9a"),
1219 ESCAPE_VALUE("&Ucirc;", "\xc3\x9b"),
1220 ESCAPE_VALUE("&Yacute;", "\xc3\x9d"),
1221 ESCAPE_VALUE("&Thorn;", "\xc3\x9e"),
1222 ESCAPE_VALUE("&szlig;", "\xc3\x9f"),
1223 ESCAPE_VALUE("&agrave;", "\xc3\xa0"),
1224 ESCAPE_VALUE("&aacute;", "\xc3\xa1"),
1225 ESCAPE_VALUE("&acirc;", "\xc3\xa2"),
1226 ESCAPE_VALUE("&atilde;", "\xc3\xa3"),
1227 ESCAPE_VALUE("&auml;", "\xc3\xa4"),
1228 ESCAPE_VALUE("&aring;", "\xc3\xa5"),
1229 ESCAPE_VALUE("&aelig;", "\xc3\xa6"),
1230 ESCAPE_VALUE("&ccedil;", "\xc3\xa7"),
1231 ESCAPE_VALUE("&egrave;", "\xc3\xa8"),
1232 ESCAPE_VALUE("&eacute;", "\xc3\xa9"),
1233 ESCAPE_VALUE("&ecirc;", "\xc3\xaa"),
1234 ESCAPE_VALUE("&euml;", "\xc3\xab"),
1235 ESCAPE_VALUE("&igrave;", "\xc3\xac"),
1236 ESCAPE_VALUE("&iacute;", "\xc3\xad"),
1237 ESCAPE_VALUE("&icirc;", "\xc3\xae"),
1238 ESCAPE_VALUE("&iuml;", "\xc3\xaf"),
1239 ESCAPE_VALUE("&eth;", "\xc3\xb0"),
1240 ESCAPE_VALUE("&ntilde;", "\xc3\xb1"),
1241 ESCAPE_VALUE("&ograve;", "\xc3\xb2"),
1242 ESCAPE_VALUE("&oacute;", "\xc3\xb3"),
1243 ESCAPE_VALUE("&ocirc;", "\xc3\xb4"),
1244 ESCAPE_VALUE("&otilde;", "\xc3\xb5"),
1245 ESCAPE_VALUE("&ouml;", "\xc3\xb6"),
1246 ESCAPE_VALUE("&divide;", "\xc3\xb7"),
1247 ESCAPE_VALUE("&oslash;", "\xc3\xb8"),
1248 ESCAPE_VALUE("&ugrave;", "\xc3\xb9"),
1249 ESCAPE_VALUE("&uacute;", "\xc3\xba"),
1250 ESCAPE_VALUE("&ucirc;", "\xc3\xbb"),
1251 ESCAPE_VALUE("&uuml;", "\xc3\xbc"),
1252 ESCAPE_VALUE("&yacute;", "\xc3\xbd"),
1253 ESCAPE_VALUE("&thorn;", "\xc3\xbe"),
1254 ESCAPE_VALUE("&yuml;", "\xc3\xbf"),
1255 ESCAPE_VALUE("&alpha;", "\xce\x91"),
1256 ESCAPE_VALUE("&beta;", "\xce\x92"),
1257 ESCAPE_VALUE("&gamma;", "\xce\x93"),
1258 ESCAPE_VALUE("&delta;", "\xce\x94"),
1259 ESCAPE_VALUE("&epsilon;", "\xce\x95"),
1260 ESCAPE_VALUE("&zeta;", "\xce\x96"),
1261 ESCAPE_VALUE("&eta;", "\xce\x97"),
1262 ESCAPE_VALUE("&theta;", "\xce\x98"),
1263 ESCAPE_VALUE("&iota;", "\xce\x99"),
1264 ESCAPE_VALUE("&kappa;", "\xce\x9a"),
1265 ESCAPE_VALUE("&lambda;", "\xce\x9b"),
1266 ESCAPE_VALUE("&mu;", "\xce\x9c"),
1267 ESCAPE_VALUE("&nu;", "\xce\x9d"),
1268 ESCAPE_VALUE("&xi;", "\xce\x9e"),
1269 ESCAPE_VALUE("&omicron;", "\xce\x9f"),
1270 ESCAPE_VALUE("&pi;", "\xce\xa0"),
1271 ESCAPE_VALUE("&rho;", "\xce\xa1"),
1272 ESCAPE_VALUE("&sigma;", "\xce\xa3"),
1273 ESCAPE_VALUE("&tau;", "\xce\xa4"),
1274 ESCAPE_VALUE("&upsilon;", "\xce\xa5"),
1275 ESCAPE_VALUE("&phi;", "\xce\xa6"),
1276 ESCAPE_VALUE("&chi;", "\xce\xa7"),
1277 ESCAPE_VALUE("&psi;", "\xce\xa8"),
1278 ESCAPE_VALUE("&omega;", "\xce\xa9"),
1279 ESCAPE_VALUE("&zwnj;", "\xe2\x80\x8c"),
1280 ESCAPE_VALUE("&zwj;", "\xe2\x80\x8d"),
1281 ESCAPE_VALUE("&lrm;", "\xe2\x80\x8e"),
1282 ESCAPE_VALUE("&rlm;", "\xe2\x80\x8f"),
1283 ESCAPE_VALUE("&dagger;", "\xe2\x80\xa0"),
1284 ESCAPE_VALUE("&Dagger;", "\xe2\x80\xa1"),
1285 ESCAPE_VALUE("&bull;", "\xe2\x80\xa2"),
1286 ESCAPE_VALUE("&hellip;", "\xe2\x80\xa6"),
1287 ESCAPE_VALUE("&euro;", "\xe2\x82\xac"),
1288 ESCAPE_VALUE("&larr;", "\xe2\x86\x90"),
1289 ESCAPE_VALUE("&uarr;", "\xe2\x86\x91"),
1290 ESCAPE_VALUE("&rarr;", "\xe2\x86\x92"),
1291 ESCAPE_VALUE("&darr;", "\xe2\x86\x93"),
1292 ESCAPE_VALUE("&harr;", "\xe2\x86\x94"),
1293 ESCAPE_VALUE("&larr;", "\xe2\x87\x90"),
1294 ESCAPE_VALUE("&rarr;", "\xe2\x87\x92"),
1295 ESCAPE_VALUE("&forall;", "\xe2\x88\x80"),
1296 ESCAPE_VALUE("&exist;", "\xe2\x88\x83"),
1297 ESCAPE_VALUE("&nabla;", "\xe2\x88\x87"),
1298 ESCAPE_VALUE("&prod;", "\xe2\x88\x8f"),
1299 ESCAPE_VALUE("&sum;", "\xe2\x88\x91"),
1300 ESCAPE_VALUE("&and;", "\xe2\x88\xa7"),
1301 ESCAPE_VALUE("&or;", "\xe2\x88\xa8"),
1302 ESCAPE_VALUE("&int;", "\xe2\x88\xab"),
1303 ESCAPE_VALUE("&ne;", "\xe2\x89\xa0"),
1304 ESCAPE_VALUE("&equiv;", "\xe2\x89\xa1"),
1305 ESCAPE_VALUE("&oplus;", "\xe2\x8a\x95"),
1306 ESCAPE_VALUE("&perp;", "\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
1314static const Escape_Value escape_values_v_common_sorted[] = { 1182 Escape_Value **ret_list = malloc(len * sizeof(Escape_Value *));
1315 ESCAPE_VALUE("&quot;", "\x22"), 1183 for (i = 0 ; i < len ; i++)
1316 ESCAPE_VALUE("&amp;", "\x26"), 1184 {
1317 ESCAPE_VALUE("&apos;", "\x27"), 1185 ret_list[i] = (Escape_Value *)(&source[i]);
1318 ESCAPE_VALUE("&lt;", "\x3c"), 1186 }
1319 ESCAPE_VALUE("&gt;", "\x3e"), 1187
1320}; 1188 qsort(&ret_list[0], len, sizeof(Escape_Value *), compare_fun);
1189 return ret_list;
1190}
1191
1192static Escape_Value **
1193escape_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
1215static Escape_Value **
1216escape_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
1238static Escape_Value **
1239escape_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
1260static Escape_Value **
1261get_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
1278static Escape_Value **
1279get_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
1296static Escape_Value **
1297get_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
1313static Escape_Value **
1314get_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 */
8492static int 8500static 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 ("&gt;",1,....) 8516 //example ("&gt;",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 */
8527static int 8538static 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
8553static inline const char * 8567static 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