Code View

mstring / mstring-1.3.1.2 / src / MText.hh
// SPDX-License-Identifier: MIT
#pragma once

#include <iosfwd>
#include <string>

#include "MWriter.hh"
#include "Message.hh"

/// \file MText.hh
/// \brief Writes the statements that stream one locale's text.

/// \brief One text element: `stream << "literal";`, or a macro
///        `stream << ( expression );` with its formats applied in a block that
///        restores the stream's formatting afterwards.
class TextElementsWriter
  : public Writer
{
  public:
    TextElementsWriter( std::ostream &stream, std::string &indent );

    void operator( )( const TextElement &text );
};

/// \brief All the text elements of \p locale, preceded by an ENCODE comment.
void WriteLocaleText( std::ostream &stream, std::string &indent, const LocaleMessage &locale );

/// \brief The same text appended to `std::string internal_out` instead of
///        streamed: literals with `+=`, a plain macro through
///        `InternalAppend( internal_out, loc, value )`, a macro with formats
///        through a local `std::ostringstream` imbued with `loc`.
void WriteLocaleAppend( std::ostream &stream, std::string &indent, const LocaleMessage &locale );

/// \brief Name of the helper `WriteAppendHelper()` defines.
extern const char *const AppendHelperName;

/// \brief Define `InternalAppend()`: a string-like value is appended as it is,
///        an integer with `std::to_chars` when the locale is "C", anything else
///        through a `std::ostringstream` imbued with the locale — so the result
///        is always what streaming the value would have produced.
void WriteAppendHelper( std::ostream &stream );