add scan_html_tagarg

master
leitner 10 years ago
parent 1d723c8da4
commit 8bdf66a1f5

@ -16,7 +16,7 @@
switch epoll from level triggering to edge triggering
introduce io_eagain_read and io_eagain_write (discontinue using io_eagain plz)
fix buffer_get
add fmt_html_tagarg, fmt_xml
add fmt_html_tagarg, fmt_xml, scan_html_tagarg
0.29:
save 8 bytes in taia.h for 64-bit systems

@ -64,7 +64,12 @@ size_t scan_urlencoded(const char *src,char *dest,size_t *destlen);
size_t scan_urlencoded2(const char* src,char* dest,size_t* destlen);
size_t scan_yenc(const char* src,char* dest,size_t* destlen);
size_t scan_hexdump(const char* src,char* dest,size_t* destlen);
/* decodes all html5-standardized &foo; escapes, and also
* "<br>" to "\n" and "<p>" to "\n\n", leaves the rest of the tags alone */
size_t scan_html(const char* src,char* dest,size_t* destlen);
/* decodes all html5-standardized &foo; escapes, but leaves all tags
* alone */
size_t scan_html_tagarg(const char* src,char* dest,size_t* destlen);
size_t scan_cescape(const char* src,char* dest,size_t* destlen);
size_t scan_ldapescape(const char* src,char* dest,size_t* destlen);
size_t scan_jsonescape(const char* src,char* dest,size_t* destlen);

@ -13,6 +13,10 @@ size_t fmt_html(char* dest,const char* src,size_t len) {
case '<': seq="&lt;"; goto doit;
case '>': seq="&gt;"; goto doit;
case '\n':
if (i<len && s[i+1]=='\n') {
seq="<p>";
++i;
} else
seq="<br>";
doit:
written+=fmt_str(dest?dest+written:0,seq);

@ -25,7 +25,7 @@ static const char* lookup(size_t ofs,const char* t) {
return NULL;
}
size_t scan_html(const char *src,char *dest,size_t *destlen) {
static size_t scan_html_inner(const char *src,char *dest,size_t *destlen,int flag) {
register const unsigned char* s=(const unsigned char*) src;
size_t written=0,i;
for (i=0; s[i]; ++i) {
@ -58,7 +58,7 @@ size_t scan_html(const char *src,char *dest,size_t *destlen) {
continue;
} else
dest[written]='&';
} else if (s[i]=='<') {
} else if (flag && s[i]=='<') {
if (case_starts((const char*)s+i+1,"br>")) {
dest[written]='\n';
i+=3;
@ -75,3 +75,11 @@ size_t scan_html(const char *src,char *dest,size_t *destlen) {
*destlen=written;
return i;
}
size_t scan_html_tagarg(const char *src,char *dest,size_t *destlen) {
return scan_html_inner(src,dest,destlen,1);
}
size_t scan_html(const char *src,char *dest,size_t *destlen) {
return scan_html_inner(src,dest,destlen,0);
}

Loading…
Cancel
Save