comparison src/c/urweb.c @ 1059:03a81e26e5fe

Move to simpler HTML escaping
author Adam Chlipala <adamc@hcoop.net>
date Tue, 08 Dec 2009 08:48:29 -0500
parents 118a5a08a881
children e8a35d710ab9
comparison
equal deleted inserted replaced
1058:86b831978b8d 1059:03a81e26e5fe
1429 p += 6; 1429 p += 6;
1430 } else if (c == '&') { 1430 } else if (c == '&') {
1431 strcpy(p, "&amp;"); 1431 strcpy(p, "&amp;");
1432 p += 5; 1432 p += 5;
1433 } 1433 }
1434 else if (isprint(c)) 1434 else
1435 *p++ = c; 1435 *p++ = c;
1436 else if (c / 32 == 6 && isCont(s[1])) {
1437 memcpy(p, s, 2);
1438 p += 2;
1439 ++s;
1440 } else if (c / 16 == 14 && isCont(s[1]) && isCont(s[2])) {
1441 memcpy(p, s, 3);
1442 p += 3;
1443 s += 2;
1444 } else if (c / 8 == 30 && isCont(s[1]) && isCont(s[2]) && isCont(s[3])) {
1445 memcpy(p, s, 4);
1446 p += 4;
1447 s += 3;
1448 } else {
1449 int len2;
1450 sprintf(p, "&#%d;%n", c, &len2);
1451 p += len2;
1452 }
1453 } 1436 }
1454 1437
1455 *p++ = 0; 1438 *p++ = 0;
1456 ctx->heap.front = p; 1439 ctx->heap.front = p;
1457 return result; 1440 return result;
1468 p += 6; 1451 p += 6;
1469 } else if (c == '&') { 1452 } else if (c == '&') {
1470 strcpy(p, "&amp;"); 1453 strcpy(p, "&amp;");
1471 p += 5; 1454 p += 5;
1472 } 1455 }
1473 else if (isprint(c)) 1456 else
1474 *p++ = c; 1457 *p++ = c;
1475 else {
1476 int len2;
1477 sprintf(p, "&#%d;%n", c, &len2);
1478 p += len2;
1479 }
1480 1458
1481 *p++ = 0; 1459 *p++ = 0;
1482 ctx->heap.front = p; 1460 ctx->heap.front = p;
1483 return result; 1461 return result;
1484 } 1462 }
1519 1497
1520 if (c == '"') 1498 if (c == '"')
1521 uw_write_unsafe(ctx, "&quot;"); 1499 uw_write_unsafe(ctx, "&quot;");
1522 else if (c == '&') 1500 else if (c == '&')
1523 uw_write_unsafe(ctx, "&amp;"); 1501 uw_write_unsafe(ctx, "&amp;");
1524 else if (isprint(c)) 1502 else
1525 uw_writec_unsafe(ctx, c); 1503 uw_writec_unsafe(ctx, c);
1526 else if (c / 32 == 6 && isCont(s[1])) {
1527 uw_writec_unsafe(ctx, c);
1528 uw_writec_unsafe(ctx, s[1]);
1529 ++s;
1530 } else if (c / 16 == 14 && isCont(s[1]) && isCont(s[2])) {
1531 uw_writec_unsafe(ctx, c);
1532 uw_writec_unsafe(ctx, s[1]);
1533 uw_writec_unsafe(ctx, s[2]);
1534 s += 2;
1535 } else if (c / 8 == 30 && isCont(s[1]) && isCont(s[2]) && isCont(s[3])) {
1536 uw_writec_unsafe(ctx, c);
1537 uw_writec_unsafe(ctx, s[1]);
1538 uw_writec_unsafe(ctx, s[2]);
1539 uw_writec_unsafe(ctx, s[3]);
1540 s += 3;
1541 } else {
1542 uw_write_unsafe(ctx, "&#");
1543 uw_Basis_attrifyInt_w_unsafe(ctx, c);
1544 uw_writec_unsafe(ctx, ';');
1545 }
1546 } 1504 }
1547 1505
1548 return uw_unit_v; 1506 return uw_unit_v;
1549 } 1507 }
1550 1508
1553 1511
1554 if (c == '"') 1512 if (c == '"')
1555 uw_write_unsafe(ctx, "&quot;"); 1513 uw_write_unsafe(ctx, "&quot;");
1556 else if (c == '&') 1514 else if (c == '&')
1557 uw_write_unsafe(ctx, "&amp;"); 1515 uw_write_unsafe(ctx, "&amp;");
1558 else if (isprint(c)) 1516 else
1559 uw_writec_unsafe(ctx, c); 1517 uw_writec_unsafe(ctx, c);
1560 else {
1561 uw_write_unsafe(ctx, "&#");
1562 uw_Basis_attrifyInt_w_unsafe(ctx, c);
1563 uw_writec_unsafe(ctx, ';');
1564 }
1565 1518
1566 return uw_unit_v; 1519 return uw_unit_v;
1567 } 1520 }
1568 1521
1569 1522
1888 case '&': 1841 case '&':
1889 strcpy(s2, "&amp;"); 1842 strcpy(s2, "&amp;");
1890 s2 += 5; 1843 s2 += 5;
1891 break; 1844 break;
1892 default: 1845 default:
1893 if (isprint(c) || isspace(c)) 1846 *s2++ = c;
1894 *s2++ = c;
1895 else if (c / 32 == 6 && isCont(s[1])) {
1896 memcpy(s2, s, 2);
1897 s2 += 2;
1898 ++s;
1899 } else if (c / 16 == 14 && isCont(s[1]) && isCont(s[2])) {
1900 memcpy(s2, s, 3);
1901 s2 += 3;
1902 s += 2;
1903 } else if (c / 8 == 30 && isCont(s[1]) && isCont(s[2]) && isCont(s[3])) {
1904 memcpy(s2, s, 4);
1905 s2 += 4;
1906 s += 3;
1907 } else {
1908 int len2;
1909 sprintf(s2, "&#%d;%n", c, &len2);
1910 s2 += len2;
1911 }
1912 } 1847 }
1913 } 1848 }
1914 1849
1915 *s2++ = 0; 1850 *s2++ = 0;
1916 ctx->heap.front = s2; 1851 ctx->heap.front = s2;
1929 break; 1864 break;
1930 case '&': 1865 case '&':
1931 uw_write_unsafe(ctx, "&amp;"); 1866 uw_write_unsafe(ctx, "&amp;");
1932 break; 1867 break;
1933 default: 1868 default:
1934 if (isprint(c) || isspace(c)) 1869 uw_writec_unsafe(ctx, c);
1935 uw_writec_unsafe(ctx, c);
1936 else if (c / 32 == 6 && isCont(s[1])) {
1937 uw_writec_unsafe(ctx, c);
1938 uw_writec_unsafe(ctx, s[1]);
1939 ++s;
1940 } else if (c / 16 == 14 && isCont(s[1]) && isCont(s[2])) {
1941 uw_writec_unsafe(ctx, c);
1942 uw_writec_unsafe(ctx, s[1]);
1943 uw_writec_unsafe(ctx, s[2]);
1944 s += 2;
1945 } else if (c / 8 == 30 && isCont(s[1]) && isCont(s[2]) && isCont(s[3])) {
1946 uw_writec_unsafe(ctx, c);
1947 uw_writec_unsafe(ctx, s[1]);
1948 uw_writec_unsafe(ctx, s[2]);
1949 uw_writec_unsafe(ctx, s[3]);
1950 s += 3;
1951 } else {
1952 uw_write_unsafe(ctx, "&#");
1953 uw_Basis_attrifyInt_w_unsafe(ctx, c);
1954 uw_writec_unsafe(ctx, ';');
1955 }
1956 } 1870 }
1957 } 1871 }
1958 1872
1959 return uw_unit_v; 1873 return uw_unit_v;
1960 } 1874 }