BDE 4.14.0 Production release
Loading...
Searching...
No Matches
balxml::Formatter_CompactImplUtil Struct Reference

#include <balxml_formatter_compactimpl.h>

Public Types

typedef Formatter_CompactImplState State
 
typedef Formatter_CompactImplStateId 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 valueFormattingMode=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_CompactImplState, this struct provides an implementation of a state machine for such pretty-printing.

Member Typedef Documentation

◆ State

◆ StateId

◆ WhitespaceType

Member Function Documentation

◆ addAttribute()

template<class VALUE_TYPE >
bsl::ostream & balxml::Formatter_CompactImplUtil::addAttribute ( bsl::ostream &  stream,
State state,
const bsl::string_view name,
const VALUE_TYPE &  value,
int  valueFormattingMode = 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 a valueFormattingMode 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.

◆ addBlankLine()

static bsl::ostream & balxml::Formatter_CompactImplUtil::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.

◆ addComment()

static bsl::ostream & balxml::Formatter_CompactImplUtil::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 >.

◆ addData()

template<class VALUE_TYPE >
bsl::ostream & balxml::Formatter_CompactImplUtil::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. 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 theformattingMode' 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.

◆ addElementAndData()

template<class TYPE >
bsl::ostream & balxml::Formatter_CompactImplUtil::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.

◆ addHeader()

static bsl::ostream & balxml::Formatter_CompactImplUtil::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.

◆ addListData()

template<class VALUE_TYPE >
bsl::ostream & balxml::Formatter_CompactImplUtil::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 theformattingMode' 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.

◆ addNewline()

static bsl::ostream & balxml::Formatter_CompactImplUtil::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.

◆ addValidComment()

static int balxml::Formatter_CompactImplUtil::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 >.

◆ closeElement()

static bsl::ostream & balxml::Formatter_CompactImplUtil::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.

◆ flush()

static bsl::ostream & balxml::Formatter_CompactImplUtil::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.

◆ openElement()

static bsl::ostream & balxml::Formatter_CompactImplUtil::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.

◆ reset()

void balxml::Formatter_CompactImplUtil::reset ( State state)
inlinestatic

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: