From mboxrd@z Thu Jan 1 00:00:00 1970 From: whydoubt at gmail.com (Jeff Smith) Date: Wed, 7 Jun 2017 21:18:09 -0500 Subject: [RFC PATCH 3/4] ui-blame: create needed html_ntxt_noellipsis function In-Reply-To: <20170608021810.12964-1-whydoubt@gmail.com> References: <20170608021810.12964-1-whydoubt@gmail.com> Message-ID: <20170608021810.12964-4-whydoubt@gmail.com> 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 --- html.c | 37 ++++++++++++++++--------------------- html.h | 1 + 2 files changed, 17 insertions(+), 21 deletions(-) diff --git a/html.c b/html.c index e7e6e07..c7d1c64 100644 --- a/html.c +++ b/html.c @@ -122,10 +122,10 @@ void html_vtxtf(const char *format, va_list ap) strbuf_release(&buf); } -void html_txt(const char *txt) +static int _html_txt(int len, const char *txt) { const char *t = txt; - while (t && *t) { + while (t && *t && len--) { int c = *t; if (c == '<' || c == '>' || c == '&') { html_raw(txt, t - txt); @@ -140,32 +140,27 @@ void html_txt(const char *txt) t++; } if (t != txt) - html(txt); + html_raw(txt, t - txt); + return len; +} + +void html_txt(const char *txt) +{ + if (txt) + _html_txt(strlen(txt), txt); } void html_ntxt(int len, const char *txt) { - const char *t = txt; - while (t && *t && len--) { - int c = *t; - if (c == '<' || c == '>' || c == '&') { - html_raw(txt, t - txt); - if (c == '>') - html(">"); - else if (c == '<') - html("<"); - else if (c == '&') - html("&"); - txt = t + 1; - } - t++; - } - if (t != txt) - html_raw(txt, t - txt); - if (len < 0) + if (_html_txt(len, txt) < 0) html("..."); } +void html_ntxt_noellipsis(int len, const char *txt) +{ + _html_txt(len, txt); +} + void html_attrf(const char *fmt, ...) { va_list ap; diff --git a/html.h b/html.h index 1b24e55..e1b85b3 100644 --- a/html.h +++ b/html.h @@ -20,6 +20,7 @@ extern void html_attrf(const char *format,...); extern void html_txt(const char *txt); extern void html_ntxt(int len, const char *txt); +extern void html_ntxt_noellipsis(int len, const char *txt); extern void html_attr(const char *txt); extern void html_url_path(const char *txt); extern void html_url_arg(const char *txt); -- 2.9.3