Quick Links:

bal | bbl | bdl | bsl

Namespaces

Component balxml_typesparserutil
[Package balxml]

Provide a utility for parsing types using XML formatting. More...

Namespaces

namespace  balxml

Detailed Description

Outline
Purpose:
Provide a utility for parsing types using XML formatting.
Classes:
balxml::TypesParserUtil utility for parsing using XML formatting
See also:
http://www.w3.org/TR/xmlschema-2/
Description:
The balxml::TypesParserUtil struct provided by this component contains the following functions:
  o 'parse':        Parse a string using the supplied formatting mode.
  o 'parseBase64':  Parse a string using
                    'bdlat_FormattingMode::e_BASE64'.
  o 'parseDecimal': Parse a string using 'bdlat_FormattingMode::e_DEC'.
  o 'parseDefault': Parse a string using
                    'bdlat_FormattingMode::e_DEFAULT'.
  o 'parseHex':     Parse a string using 'bdlat_FormattingMode::e_HEX'.
  o 'parseList':    Parse a string using
                    'bdlat_FormattingMode::e_IS_LIST'.
  o 'parseText':    Parse a string using 'bdlat_FormattingMode::e_TEXT'.
The input strings are parsed 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 following C++ Type / Formatting Mode combinations are supported by this component:
      C++ Type                            Formatting Mode
      --------                            ---------------
      bool                                DEFAULT, DEC, TEXT
      char                                DEFAULT, DEC, TEXT
      unsigned char                       DEFAULT, DEC
      [unsigned] short                    DEFAULT, DEC
      [unsigned] int                      DEFAULT, DEC
      [unsigned] long                     DEFAULT, DEC
      bsls::Types::[Uint64|Int64]         DEFAULT, DEC
      float                               DEFAULT, DEC
      double                              DEFAULT, DEC
      bdldfp::Decimal64                   DEFAULT, DEC
      bsl::string                         DEFAULT, TEXT, BASE64, HEX
      bdlt::Date                          DEFAULT
      bdlt::DateTz                        DEFAULT
      bdlt::Datetime                      DEFAULT
      bdlt::DateTimeTz                    DEFAULT
      bdlt::Time                          DEFAULT
      bdlt::TimeTz                        DEFAULT
      bdlb::Variant2<DateTz, Date>        DEFAULT
      bdlb::Variant2<TimeTz, Time>        DEFAULT
      Variant2<DatetimeTz, Datetime>      DEFAULT
      bsl::vector<char>                   DEFAULT, BASE64, HEX, TEXT, IS_LIST
In addition to the types listed above, this component also recognizes the following bdlat type categories:
      'bdlat' Type Category               Formatting Mode
      ---------------------               ---------------
      Array                               IS_LIST
      CustomizedType                      Base type's formatting modes
      DynamicType                         Runtime type's formatting modes
      Enumeration                         DEFAULT, TEXT, DECIMAL
When bdlat_FormattingMode::e_DEFAULT is used, the actual formatting mode selected is based on the following mapping:
      C++ Type                            Default Formatting Mode
      --------                            -----------------------
      bool                                DEC or TEXT
      [unsigned] char                     DEC
      [unsigned] short                    DEC
      [unsigned] int                      DEC
      [unsigned] long                     DEC
      bsls::Types::[Uint64|Int64]         DEC
      bsl::string                         TEXT
      bsl::vector<char>                   BASE64

      'bdlat' Type Category               Default Formatting Mode
      ---------------------               -----------------------
      Enumeration                         TEXT
Usage:
The following snippets of code illustrate how to parse a Base64 string into an bsl::vector<char>:
  #include <balxml_typesparserutil.h>

  #include <cassert>
  #include <vector>

  using namespace BloombergLP;

  void usageExample()
  {
      const char INPUT[]      = "YWJjZA==";  // "abcd" in Base64
      const int  INPUT_LENGTH = sizeof(INPUT) - 1;

      bsl::vector<char> vec;

      int retCode = balxml::TypesParserUtil::parseBase64(&vec,
                                                         INPUT,
                                                         INPUT_LENGTH);

      assert(0   == retCode);
      assert(4   == vec.size());
      assert('a' == vec[0]);
      assert('b' == vec[1]);
      assert('c' == vec[2]);
      assert('d' == vec[3]);
  }