BDE 4.14.0 Production release
|
Provide a utility for printing types using XML formatting.
The balxml::TypesPrintUtil
struct
provided by this component contains the following functions:
print
: Print an object using the supplied formatting mode.
printBase64
: Print an object using bdlat_FormattingMode::e_BASE64
.
printDecimal
: Print an object using bdlat_FormattingMode::e_DEC
.
printDefault
: Print an object using bdlat_FormattingMode::e_DEFAULT
.
printHex
: Print an object using bdlat_FormattingMode::e_HEX
.
printList
: Print an object using bdlat_FormattingMode::e_IS_LIST
.
printText
: Print an object using bdlat_FormattingMode::e_TEXT
.
The output is generated according to each type's lexical representation as described in the XML Schema Specification, which is available at http://www.w3.org/TR/xmlschema-2/
. The text input is parsed and output according to the XML-1.0 with UTF-8 encoding, which prevents control characters (accepted by UTF-8) but otherwise accepts valid characters as described in the Unicode Standard 4.0, which is available at http://www.unicode.org/versions/Unicode4.0.0/
(well-formed UTF-8 byte sequences are described in Chapter 3, Section 3.9 and Table 3.5).
The following C++ Type / Formatting Mode combinations are supported by this component:
In addition to the types listed above, this component also recognizes the following bdlat
type categories:
When bdlat_FormattingMode::e_DEFAULT
is used, the actual formatting mode selected is based on the following mapping:
The output of printText
will always be valid XML 1.0 with UTF-8 encoding. When attempting to print text data that contains non-valid UTF-8 characters or non-printable control characters using printText
, this component prints the valid characters up to and excluding the first invalid character. See the second example in the Usage
section for an illustration.
The following snippets of code illustrates how to print an bsl::vector<char>
object in Base64 format:
The following snippet of shows what can be expected when printing valid or invalid data via printText
:
Note that all characters in the range 0x01
to 0x7F
are valid first bytes (including printable ASCII, TAB 0x09
, or LF 0x0a
, but excluding control characters other than TAB and LF) and that ampersand (&
or 0x26
), less-than (<
or 0x3c
), greater-than (>
or 0x3e
), apostrophe (0x27
), and quote ("</tt>) will be printed as <tt>\&</tt>, <tt>\<</tt>, <tt>\></tt>,
<tt>\'</tt> and <tt>\"</tt> respectively. Hence the expected output for the above
string <tt>VALID_STR</tt> is:
@code
const char EXPECTED_RESULT[] = "Hello \t 'World'";
@endcode
We can test that <tt>printText</tt> will successfully print the string:
@code
balxml::TypesPrintUtil::printText(ss, VALID_STR);
assert(ss.good());
assert(EXPECTED_RESULT == ss.str());
@endcode
In addition, when invalid data is printed, the stream is set to a bad state
which is the proper means for the user to detect an error, as shown in the
following code snippet:
@code
ss.str("");
const char INVALID_STR[] = "Hello \300\t 'World'";
balxml::TypesPrintUtil::printText(ss, INVALID_STR);
assert(ss.fail());
assert("Hello " == ss.str()); }