On Wed, Jun 07, 2017 at 09:18:09PM -0500, Jeff Smith wrote:
> 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 <whydo...@gmail.com>
> ---
>  html.c | 37 ++++++++++++++++---------------------
>  html.h |  1 +
>  2 files changed, 17 insertions(+), 21 deletions(-)

We only use the current html_ntxt() function in one place so I don't
think there's any real need to keep the name as is.

The end result would be nicer if html_ntxt() is your new "no ellipsis"
variant which can return an int to indicate whether the text was
truncated, then ui-repolist can switch to a new html_txt_ellipsis()
which has the same effect as the current html_ntxt().

> 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("&gt;");
> -                     else if (c == '<')
> -                             html("&lt;");
> -                     else if (c == '&')
> -                             html("&amp;");
> -                     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
> 
> _______________________________________________
> CGit mailing list
> CGit@lists.zx2c4.com
> https://lists.zx2c4.com/mailman/listinfo/cgit
_______________________________________________
CGit mailing list
CGit@lists.zx2c4.com
https://lists.zx2c4.com/mailman/listinfo/cgit

Reply via email to