Quick Links:

bal | bbl | bdl | bsl

Public Types | Static Public Member Functions

balxml::Formatter_PrettyImplUtil Struct Reference

#include <balxml_formatter_prettyimpl.h>

List of all members.

Public Types

typedef Formatter_PrettyImplState State
typedef Formatter_PrettyImplStateId StateId
typedef FormatterWhitespaceType WhitespaceType

Static Public Member Functions

template<class VALUE_TYPE >
static bsl::ostream & addAttribute (bsl::ostream &stream, State *state, const bsl::string_view &name, const VALUE_TYPE &value, int formattingMode=0, const EncoderOptions &encoderOptions=EncoderOptions())
static bsl::ostream & addBlankLine (bsl::ostream &stream, State *state)
static bsl::ostream & addComment (bsl::ostream &stream, State *state, const bsl::string_view &comment, bool forceNewline=true)
template<class VALUE_TYPE >
static bsl::ostream & addData (bsl::ostream &stream, State *state, const VALUE_TYPE &value, int formattingMode=0, const EncoderOptions &encoderOptions=EncoderOptions())
template<class TYPE >
static bsl::ostream & addElementAndData (bsl::ostream &stream, State *state, const bsl::string_view &name, const TYPE &value, int formattingMode=0, const EncoderOptions &encoderOptions=EncoderOptions())
static bsl::ostream & addHeader (bsl::ostream &stream, State *state, const bsl::string_view &encoding)
template<class VALUE_TYPE >
static bsl::ostream & addListData (bsl::ostream &stream, State *state, const VALUE_TYPE &value, int formattingMode=0, const EncoderOptions &encoderOptions=EncoderOptions())
static bsl::ostream & addNewline (bsl::ostream &stream, State *state)
static int addValidComment (bsl::ostream &stream, State *state, const bsl::string_view &comment, bool forceNewline=true, bool omitEnclosingWhitespace=false)
static bsl::ostream & closeElement (bsl::ostream &stream, State *state, const bsl::string_view &name)
static bsl::ostream & flush (bsl::ostream &stream, State *state)
static bsl::ostream & openElement (bsl::ostream &stream, State *state, const bsl::string_view &name, WhitespaceType::Enum whitespaceMode=WhitespaceType::e_PRESERVE_WHITESPACE)
static void reset (State *state)

Detailed Description

This utility struct provides a namespace for a suite of operations used to pretty-print XML documents given a sequence of tokens to emit. Together with Formatter_PrettyImplState, this struct provides an implementation of a state machine for such pretty-printing.

See Component balxml_formatter_prettyimpl


Member Typedef Documentation


Member Function Documentation

template<class VALUE_TYPE >
static bsl::ostream& balxml::Formatter_PrettyImplUtil::addAttribute ( bsl::ostream &  stream,
State state,
const bsl::string_view &  name,
const VALUE_TYPE &  value,
int  formattingMode = 0,
const EncoderOptions encoderOptions = EncoderOptions() 
) [static]

Add an attribute of the specified name and specified value to the currently open element in the specified stream, with formatting depending on the specified state, and update the state accordingly. Return the stream. value can be of the following types: char, short, int, bsls::Types::Int64, float, double, bsl::string, bdlt::Datetime, bdlt::Date, and bdlt::Time. Precede this name="value" pair with a single space. Wrap line (write the attribute on next line with proper indentation), if the length of name="value" is too long. Optionally specify formattingMode and encoderOptions to control the formatting of value. If value is of type bsl::string, it is truncated at any invalid UTF-8 byte-sequence or any control character. The list of invalid control characters includes characters in the range [0x00, 0x20) and 0x7F (DEL) but does not include 0x9, 0xA, and 0x0D. The five special characters: apostrophe, double quote, ampersand, less than, and greater than are escaped in the output XML. If value is of type char, it is cast to a signed byte value with a range [ -128 .. 127 ]. The behavior is undefined unless the last manipulator was openElement or addAttribute.

static bsl::ostream& balxml::Formatter_PrettyImplUtil::addBlankLine ( bsl::ostream &  stream,
State state 
) [static]

Insert one or two newline characters into the specified stream stream such that a blank line results, depending on the specified state, and update the state accordingly. Return the stream. If the last output was a newline, then only one newline is added, otherwise two newlines are added. If following a call to openElement, or addAttribute, add a closing > to the opened tag.

static bsl::ostream& balxml::Formatter_PrettyImplUtil::addComment ( bsl::ostream &  stream,
State state,
const bsl::string_view &  comment,
bool  forceNewline = true 
) [static]

DEPRECATED: Use addValidComment instead.

Write the specified comment into the specified stream, with formatting depending on the specified state, and update the state accordingly. Return the stream. The optionally specified forceNewline, if true, forces to start a new line solely for the comment if it's not on a new line already. Otherwise, comments continue on current line. If an element-opening tag is not completed with a >, addComment will add >.

template<class VALUE_TYPE >
static bsl::ostream& balxml::Formatter_PrettyImplUtil::addData ( bsl::ostream &  stream,
State state,
const VALUE_TYPE &  value,
int  formattingMode = 0,
const EncoderOptions encoderOptions = EncoderOptions() 
) [static]

Add the specified value as the data content to the specified stream, with formatting depending on the specified state, and update state accordingly. Return the stream. Return the stream. value can be of the following types: char, short, int, bsls::Types::Int64, float, double, bsl::string, bdlt::Datetime, bdlt::Date, and bdlt::Time. Perform no line-wrapping or indentation as if the whitespace constraint were always BAEXML_PRESERVE_WHITESPACE in openElement, with the only exception that an initial newline and an initial indent is added when openElement specifies BAEXML_NEWLINE_INDENT option. If value is of type bsl::string, it is truncated at any invalid UTF-8 byte-sequence or any control character. The list of invalid control characters includes characters in the range [0x00, 0x20) and 0x7F (DEL) but does not include 0x9, 0xA, and 0x0D. The five special characters: apostrophe, double quote, ampersand, less than, and greater than are escaped in the output XML. If value is of type char, it is cast to a signed byte value with a range of '[ -128 .. 127 ]'. Optionally specify the formattingMode and encoderOptions to specify the format used to encode value. The behavior is undefined if the call is made when there are no opened elements.

template<class TYPE >
static bsl::ostream& balxml::Formatter_PrettyImplUtil::addElementAndData ( bsl::ostream &  stream,
State state,
const bsl::string_view &  name,
const TYPE &  value,
int  formattingMode = 0,
const EncoderOptions encoderOptions = EncoderOptions() 
) [static]

Add element of the specified name and the specified value as the data content to the specified stream, with formatting depending on the specified state and the optionally specified encoderOptions, and update state accordingly. Return the stream. This has the same effect as calling the following sequence: 'openElement(name); addData(value), closeElement(name);'. Optionally specify the formattingMode.

static bsl::ostream& balxml::Formatter_PrettyImplUtil::addHeader ( bsl::ostream &  stream,
State state,
const bsl::string_view &  encoding 
) [static]

Add XML header with optionally specified encoding to the specified stream, with formatting depending on the specified state, and update state accordingly. Return the stream. Version is always "1.0". The behavior is undefined unless addHeader is the first manipulator (with the exception of rawOutputStream) after construction or reset.

template<class VALUE_TYPE >
static bsl::ostream& balxml::Formatter_PrettyImplUtil::addListData ( bsl::ostream &  stream,
State state,
const VALUE_TYPE &  value,
int  formattingMode = 0,
const EncoderOptions encoderOptions = EncoderOptions() 
) [static]

Add the specified value as the data content to the specified stream, with formatting depending on the specified state, and update state accordingly. Return the stream. value can be of the following types: char, short, int, bsls::Types::Int64, float, double, bsl::string, bdlt::Datetime, bdlt::Date, and bdlt::Time. Prefix the value with a space(0x20) unless the data being added is the first data on a line. When adding the data makes the line too long, perform line-wrapping and indentation as determined by the whitespace constraint used when the current element is opened with openElement. If value is of type bsl::string, it is truncated at any invalid UTF-8 byte-sequence or any control character. The list of invalid control characters includes characters in the range [0x00, 0x20) and 0x7F (DEL) but does not include 0x9, 0xA, and 0x0D. The five special characters: apostrophe, double quote, ampersand, less than, and greater than are escaped in the output XML. If value is of type char, it is cast to a signed byte value with a range of '[ -128 .. 127 ]'. Optionally specify the formattingMode and encoderOptions to specify the format used to encode value. The behavior is undefined if the call is made when there are no opened elements.

static bsl::ostream& balxml::Formatter_PrettyImplUtil::addNewline ( bsl::ostream &  stream,
State state 
) [static]

Insert a literal newline into the XML output of the specified stream, with formatting depending on the specified state, and update state accordingly. Return the stream. If following a call to openElement, or addAttribute, add a closing > to the opened tag.

static int balxml::Formatter_PrettyImplUtil::addValidComment ( bsl::ostream &  stream,
State state,
const bsl::string_view &  comment,
bool  forceNewline = true,
bool  omitEnclosingWhitespace = false 
) [static]

Write the specified comment into the specified stream, with formatting depending on the specified state, and update the state accordingly. If the optionally specified forceNewline is true then a new line is inserted for comments not already on a new line. Also optionally specify an omitEnclosingWhitespace that specifies if a space character should be omitted before and after comment. If omitEnclosingWhitespace is not specified then a space character is inserted before and after comment. Return 0 on success, and non-zero value otherwise. Note that a non-zero return value is returned if either comment contains -- or if omitEnclosingWhitespace is true and comment ends with -. Also note that if an element-opening tag is not completed with a >, addValidComment will add >.

static bsl::ostream& balxml::Formatter_PrettyImplUtil::closeElement ( bsl::ostream &  stream,
State state,
const bsl::string_view &  name 
) [static]

Decrement the indent level and add the closing tag for the element of the specified name to the specified stream, with formatting depending on the specified state, and update state accordingly. Return the stream. If the element does not have content, write /> and a newline into stream. Otherwise, write </name> and a newline. If this </name> does not share the same line with data, or it follows another element's closing tag, indent properly before writing </name> and the newline. If name is root element, flush the output stream. The behavior is undefined if name is not the most recently opened element that's yet to be closed.

static bsl::ostream& balxml::Formatter_PrettyImplUtil::flush ( bsl::ostream &  stream,
State state 
) [static]

Insert the closing > if there is an incomplete tag, and flush the specified output stream, with formatting depending on the specified state, and update state accordingly. Return the stream.

static bsl::ostream& balxml::Formatter_PrettyImplUtil::openElement ( bsl::ostream &  stream,
State state,
const bsl::string_view &  name,
WhitespaceType::Enum  whitespaceMode = WhitespaceType::e_PRESERVE_WHITESPACE 
) [static]

Open an element of the specified name at current indent level with the optionally specified whitespace constraint whitespaceMode for its textual data to the specified stream, with formatting depending on the specified state, and update state accordingly, incrementing the indent level. Return the stream. whitespaceMode constrains how textual data is written with addListData for the current element, but not its nested elements. The behavior is undefined if openElement is called after the root element is closed and there is no subsequent call to reset.

static void balxml::Formatter_PrettyImplUtil::reset ( State state  )  [static]

Reset the specified formatter state such that it can be used to format a new XML document as if the formatter were just constructed


The documentation for this struct was generated from the following file: