summaryrefslogtreecommitdiffstats
path: root/ml.c
diff options
context:
space:
mode:
authorKristaps Dzonsons <kristaps@bsd.lv>2008-12-04 16:19:52 +0000
committerKristaps Dzonsons <kristaps@bsd.lv>2008-12-04 16:19:52 +0000
commit7ea64ffd96cef95695a6c74dbf90f76d73fa961d (patch)
tree361049b7cd2f7f22d1b50a1dbfd403c7c0cf1182 /ml.c
parentbbaed73e9a14101e88d84225a902613116c536e9 (diff)
downloadmandoc-7ea64ffd96cef95695a6c74dbf90f76d73fa961d.tar.gz
Character-encoding tests.
Diffstat (limited to 'ml.c')
-rw-r--r--ml.c41
1 files changed, 30 insertions, 11 deletions
diff --git a/ml.c b/ml.c
index 04980b8f..e174ccfe 100644
--- a/ml.c
+++ b/ml.c
@@ -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, "&amp;", 5, pos))
- return(0);
+ seq = "&amp;";
+ ssz = 5;
break;
+
+ /* Quotation ml-escape. */
case ('"'):
- if ( ! ml_nputs(p, "&quot;", 6, pos))
- return(0);
+ seq = "&quot;";
+ ssz = 6;
break;
+
+ /* Lt ml-escape. */
case ('<'):
- if ( ! ml_nputs(p, "&lt;", 4, pos))
- return(0);
+ seq = "&lt;";
+ ssz = 4;
break;
+
+ /* Gt ml-escape. */
case ('>'):
- if ( ! ml_nputs(p, "&gt;", 4, pos))
- return(0);
+ seq = "&gt;";
+ 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;