diff options
| author | Jeff Smith | 2017-10-01 23:39:05 -0500 |
|---|---|---|
| committer | John Keeping | 2017-10-03 19:19:34 +0100 |
| commit | 70787254b270b1505aa8427813f64131be5df86c (patch) | |
| tree | 5a6d23b8186d4d9d7e2bd5b84d3c3d092edd4e30 /html.c | |
| parent | 3b485cc5422f800d142c7023295e82c0a1c10b19 (diff) | |
| download | cgit-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.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, ...) |
