diff options
Diffstat (limited to 'html.c')
-rw-r--r-- | html.c | 32 |
1 files changed, 11 insertions, 21 deletions
@@ -124,29 +124,20 @@ void html_vtxtf(const char *format, va_list ap) | |||
124 | 124 | ||
125 | void html_txt(const char *txt) | 125 | void html_txt(const char *txt) |
126 | { | 126 | { |
127 | const char *t = txt; | 127 | if (txt) |
128 | while (t && *t) { | 128 | html_ntxt(txt, strlen(txt)); |
129 | int c = *t; | ||
130 | if (c == '<' || c == '>' || c == '&') { | ||
131 | html_raw(txt, t - txt); | ||
132 | if (c == '>') | ||
133 | html(">"); | ||
134 | else if (c == '<') | ||
135 | html("<"); | ||
136 | else if (c == '&') | ||
137 | html("&"); | ||
138 | txt = t + 1; | ||
139 | } | ||
140 | t++; | ||
141 | } | ||
142 | if (t != txt) | ||
143 | html(txt); | ||
144 | } | 129 | } |
145 | 130 | ||
146 | void html_ntxt(int len, const char *txt) | 131 | ssize_t html_ntxt(const char *txt, size_t len) |
147 | { | 132 | { |
148 | const char *t = txt; | 133 | const char *t = txt; |
149 | while (t && *t && len--) { | 134 | ssize_t slen; |
135 | |||
136 | if (len > SSIZE_MAX) | ||
137 | return -1; | ||
138 | |||
139 | slen = (ssize_t) len; | ||
140 | while (t && *t && slen--) { | ||
150 | int c = *t; | 141 | int c = *t; |
151 | if (c == '<' || c == '>' || c == '&') { | 142 | if (c == '<' || c == '>' || c == '&') { |
152 | html_raw(txt, t - txt); | 143 | html_raw(txt, t - txt); |
@@ -162,8 +153,7 @@ void html_ntxt(int len, const char *txt) | |||
162 | } | 153 | } |
163 | if (t != txt) | 154 | if (t != txt) |
164 | html_raw(txt, t - txt); | 155 | html_raw(txt, t - txt); |
165 | if (len < 0) | 156 | return slen; |
166 | html("..."); | ||
167 | } | 157 | } |
168 | 158 | ||
169 | void html_attrf(const char *fmt, ...) | 159 | void html_attrf(const char *fmt, ...) |