diff --git a/CHANGES b/CHANGES index 931eefd..30fb65f 100644 --- a/CHANGES +++ b/CHANGES @@ -16,6 +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 0.29: save 8 bytes in taia.h for 64-bit systems diff --git a/textcode.h b/textcode.h index 4032c1b..336668a 100644 --- a/textcode.h +++ b/textcode.h @@ -27,8 +27,15 @@ size_t fmt_urlencoded2(char* dest,const char* src,size_t len,const char* escapem size_t fmt_yenc(char* dest,const char* src,size_t len); /* Needs len*2 bytes */ size_t fmt_hexdump(char* dest,const char* src,size_t len); -/* Change '<' to '<' and '&' to '&'; worst case: len*5 */ +/* Change '<' to '<' and '&' to '&' and '\n' to '
'; worst case: len*5 */ +/* This is meant for outputting text that goes between tags */ size_t fmt_html(char* dest,const char* src,size_t len); +/* Change '<' to '<' and '&' to '&' and '"' to '"'; worst case: len*6 */ +/* This is meant for outputting text that goes in a tag argument between double quotes*/ +size_t fmt_html_tagarg(char* dest,const char* src,size_t len); +/* Change '<' to '<' and '&' to '&'; worst case: len*5 */ +size_t fmt_xml(char* dest,const char* src,size_t len); + /* Change '\' to "\\", '\n' to "\n", ^A to "\x01" etc; worst case: len*4 */ size_t fmt_cescape(char* dest,const char* src,size_t len); /* Worst case: len*4 */ diff --git a/textcode/fmt_html_tagarg.c b/textcode/fmt_html_tagarg.c new file mode 100644 index 0000000..57bd79e --- /dev/null +++ b/textcode/fmt_html_tagarg.c @@ -0,0 +1,26 @@ +#include "fmt.h" +#include "textcode.h" +#include "str.h" +#include "haveinline.h" + +size_t fmt_html_tagarg(char* dest,const char* src,size_t len) { + register const unsigned char* s=(const unsigned char*) src; + size_t written=0,i; + const char* seq; + for (i=0; i': seq=">"; goto doit; + case '"': + seq="&dquot;"; + doit: + written+=fmt_str(dest?dest+written:0,seq); + break; + default: if (dest) dest[written]=s[i]; ++written; break; + } + /* in case someone gives us malicious input */ + if (written>((size_t)-1)/2) return (size_t)-1; + } + return written; +} diff --git a/textcode/fmt_xml.c b/textcode/fmt_xml.c new file mode 100644 index 0000000..2c20253 --- /dev/null +++ b/textcode/fmt_xml.c @@ -0,0 +1,23 @@ +#include "fmt.h" +#include "textcode.h" +#include "str.h" +#include "haveinline.h" + +size_t fmt_xml(char* dest,const char* src,size_t len) { + register const unsigned char* s=(const unsigned char*) src; + size_t written=0,i; + const char* seq; + for (i=0; i((size_t)-1)/2) return (size_t)-1; + } + return written; +}