aboutsummaryrefslogtreecommitdiffstats
path: root/html.c
diff options
context:
space:
mode:
authorJeff Smith2017-10-01 23:39:05 -0500
committerJohn Keeping2017-10-03 19:19:34 +0100
commit70787254b270b1505aa8427813f64131be5df86c (patch)
tree5a6d23b8186d4d9d7e2bd5b84d3c3d092edd4e30 /html.c
parent3b485cc5422f800d142c7023295e82c0a1c10b19 (diff)
downloadcgit-70787254b270b1505aa8427813f64131be5df86c.tar.gz
cgit-70787254b270b1505aa8427813f64131be5df86c.tar.bz2
cgit-70787254b270b1505aa8427813f64131be5df86c.zip
html: html_ntxt with no ellipsis
For implementing a ui-blame page, there is need for a function that outputs a selection from a block of text, transformed for HTML output, but with no further modifications or additions. Signed-off-by: Jeff Smith <whydoubt@gmail.com> Reviewed-by: John Keeping <john@keeping.me.uk>
Diffstat (limited to 'html.c')
-rw-r--r--html.c32
1 files changed, 11 insertions, 21 deletions
diff --git a/html.c b/html.c
index e7e6e07..7f81965 100644
--- a/html.c
+++ b/html.c
@@ -124,29 +124,20 @@ void html_vtxtf(const char *format, va_list ap)
124 124
125void html_txt(const char *txt) 125void 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("&gt;");
134 else if (c == '<')
135 html("&lt;");
136 else if (c == '&')
137 html("&amp;");
138 txt = t + 1;
139 }
140 t++;
141 }
142 if (t != txt)
143 html(txt);
144} 129}
145 130
146void html_ntxt(int len, const char *txt) 131ssize_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
169void html_attrf(const char *fmt, ...) 159void html_attrf(const char *fmt, ...)