diff options
author | Kristaps Dzonsons <kristaps@bsd.lv> | 2008-12-04 16:19:52 +0000 |
---|---|---|
committer | Kristaps Dzonsons <kristaps@bsd.lv> | 2008-12-04 16:19:52 +0000 |
commit | 7ea64ffd96cef95695a6c74dbf90f76d73fa961d (patch) | |
tree | 361049b7cd2f7f22d1b50a1dbfd403c7c0cf1182 /ml.c | |
parent | bbaed73e9a14101e88d84225a902613116c536e9 (diff) | |
download | mandoc-7ea64ffd96cef95695a6c74dbf90f76d73fa961d.tar.gz |
Character-encoding tests.
Diffstat (limited to 'ml.c')
-rw-r--r-- | ml.c | 41 |
1 files changed, 30 insertions, 11 deletions
@@ -34,30 +34,44 @@ ml_nputstring(struct md_mbuf *p, const char *buf, size_t sz, size_t *pos) { int i; + const char *seq; + size_t ssz; for (i = 0; i < (int)sz; i++) { switch (buf[i]) { + + /* Ampersand ml-escape. */ case ('&'): - if ( ! ml_nputs(p, "&", 5, pos)) - return(0); + seq = "&"; + ssz = 5; break; + + /* Quotation ml-escape. */ case ('"'): - if ( ! ml_nputs(p, """, 6, pos)) - return(0); + seq = """; + ssz = 6; break; + + /* Lt ml-escape. */ case ('<'): - if ( ! ml_nputs(p, "<", 4, pos)) - return(0); + seq = "<"; + ssz = 4; break; + + /* Gt ml-escape. */ case ('>'): - if ( ! ml_nputs(p, ">", 4, pos)) - return(0); + seq = ">"; + ssz = 4; break; + default: - if ( ! ml_nputs(p, &buf[i], 1, pos)) - return(0); + seq = &buf[i]; + ssz = 1; break; } + + if ( ! ml_nputs(p, seq, ssz, pos)) + return(-1); } return(1); } @@ -67,6 +81,9 @@ int ml_nputs(struct md_mbuf *p, const char *buf, size_t sz, size_t *pos) { + if (0 == sz) + return(1); + if ( ! md_buf_puts(p, buf, sz)) return(0); @@ -80,7 +97,9 @@ ml_puts(struct md_mbuf *p, const char *buf, size_t *pos) { size_t sz; - sz = strlen(buf); + if (0 == (sz = strlen(buf))) + return(1); + if ( ! md_buf_puts(p, buf, sz)) return(0); *pos += sz; |