From: Bruno Haible Date: Tue, 12 Mar 2019 18:28:19 +0000 (+0100) Subject: libtextstyle: New function html_ostream_flush_to_current_style. X-Git-Tag: v0.20~139 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cf266f140bfedb01aaaab111d01a7e3e2b611f05;p=thirdparty%2Fgettext.git libtextstyle: New function html_ostream_flush_to_current_style. * gnulib-local/lib/html-ostream.oo.h (struct html_ostream): Add method flush_to_current_style. * gnulib-local/lib/html-ostream.oo.c (html_ostream::flush_to_current_style): New method. * libtextstyle/lib/textstyle.h (html_ostream_flush_to_current_style): New declaration. * libtextstyle/doc/libtextstyle.texi (The html_ostream class): Document html_ostream_flush_to_current_style. * libtextstyle/NEWS: Mention the change. --- diff --git a/gnulib-local/lib/html-ostream.oo.c b/gnulib-local/lib/html-ostream.oo.c index 41df513fe..6c55847a8 100644 --- a/gnulib-local/lib/html-ostream.oo.c +++ b/gnulib-local/lib/html-ostream.oo.c @@ -312,6 +312,17 @@ html_ostream::end_span (html_ostream_t stream, const char *classname) abort (); } +static void +html_ostream::flush_to_current_style (html_ostream_t stream) +{ + verify_invariants (stream); + /* stream->buf[] contains only a few bytes that don't correspond to a + character. Can't flush it. */ + /* Open all requested tags. */ + emit_pending_spans (stream, true); + verify_invariants (stream); +} + /* Constructor. */ html_ostream_t diff --git a/gnulib-local/lib/html-ostream.oo.h b/gnulib-local/lib/html-ostream.oo.h index 72aa15690..dd25aabac 100644 --- a/gnulib-local/lib/html-ostream.oo.h +++ b/gnulib-local/lib/html-ostream.oo.h @@ -1,5 +1,5 @@ /* Output stream that produces HTML output. - Copyright (C) 2006 Free Software Foundation, Inc. + Copyright (C) 2006, 2019 Free Software Foundation, Inc. Written by Bruno Haible , 2006. This program is free software: you can redistribute it and/or modify @@ -33,6 +33,14 @@ methods: /* End a element. The begin_span / end_span calls must match properly. */ void end_span (html_ostream_t stream, const char *classname); + + /* Like html_ostream_flush (first_arg, FLUSH_THIS_STREAM), except that it + leaves the destination with the current text style enabled, instead + of with the default text style. + After calling this function, you can output strings without newlines(!) + to the underlying stream, and they will be rendered like strings passed + to 'ostream_write_mem' or 'ostream_write_str'. */ + void flush_to_current_style (html_ostream_t stream); }; diff --git a/libtextstyle/NEWS b/libtextstyle/NEWS index 088704511..1ecb72c37 100644 --- a/libtextstyle/NEWS +++ b/libtextstyle/NEWS @@ -3,6 +3,8 @@ New in 0.6: ostream_flush_scope_t. * The term_ostream_t type supports a new function term_ostream_flush_to_current_style. +* The html_ostream_t type supports a new function + html_ostream_flush_to_current_style. New in 0.5: diff --git a/libtextstyle/doc/libtextstyle.texi b/libtextstyle/doc/libtextstyle.texi index 6f62281ab..fd4beb239 100644 --- a/libtextstyle/doc/libtextstyle.texi +++ b/libtextstyle/doc/libtextstyle.texi @@ -855,6 +855,16 @@ The @code{html_ostream_begin_span} / @code{html_ostream_end_span} calls must match properly. @end deftypefn +@deftypefn Function void html_ostream_flush_to_current_style (html_ostream_t@tie{}@var{stream}) +This function acts like @code{ostream_flush (@var{stream}, FLUSH_THIS_STREAM)}, +except that it leaves the destination with the current text style enabled, +instead of with the default text style. + +After calling this function, you can output strings without newlines(!) to the +underlying stream, and they will be rendered like strings passed to +@code{ostream_write_mem} or @code{ostream_write_str}. +@end deftypefn + @node The memory_ostream class @subsubsection The @code{memory_ostream} class diff --git a/libtextstyle/lib/textstyle.h b/libtextstyle/lib/textstyle.h index 013a8b41b..7450fbbb1 100644 --- a/libtextstyle/lib/textstyle.h +++ b/libtextstyle/lib/textstyle.h @@ -348,6 +348,13 @@ extern void html_ostream_flush (html_ostream_t first_arg, ostream_flush_scope_t extern void html_ostream_free (html_ostream_t first_arg); extern void html_ostream_begin_span (html_ostream_t first_arg, const char *classname); extern void html_ostream_end_span (html_ostream_t first_arg, const char *classname); +/* Like html_ostream_flush (first_arg, FLUSH_THIS_STREAM), except that it + leaves the destination with the current text style enabled, instead + of with the default text style. + After calling this function, you can output strings without newlines(!) + to the underlying stream, and they will be rendered like strings passed + to 'ostream_write_mem' or 'ostream_write_str'. */ +extern void html_ostream_flush_to_current_style (html_ostream_t stream); #ifdef __cplusplus } #endif