123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219 |
- <chapter xml:id="base16.h">
- <title><tt>__vic/base16.h</tt></title>
- <p>Base16 encoder and decoder.</p>
- <chapter xml:id="base16">
- <title><tt>base16</tt></title>
- <p>A class used as a namespace. Contains only types, constants and static
- functions. No objects of this class are supposed to be created.</p>
- </chapter>
- <chapter xml:id="base16--bad_format">
- <title><tt>base16::bad_format</tt></title>
- <code-block lang="C++">
- struct base16::bad_format : public std::exception {};
- </code-block>
- <p>Abstract base exception class.</p>
- </chapter>
- <chapter xml:id="base16--bad_digit">
- <title><tt>base16::bad_digit</tt></title>
- <code-block lang="C++">
- struct base16::bad_digit : public base16::bad_format
- {
- const char *what() const noexcept;
- };
- </code-block>
- <p>Exception class thrown by <xref to="base16--decode"/> when the input sequence
- contains character that is not a valid HEX digit.</p>
- </chapter>
- <chapter xml:id="base16--bad_length">
- <title><tt>base16::bad_length</tt></title>
- <code-block lang="C++">
- struct base16::bad_length : public base16::bad_format
- {
- const char *what() const noexcept;
- };
- </code-block>
- <p>Exception class thrown by <xref to="base16--decode"/> when the input sequence
- length is odd.</p>
- </chapter>
- <chapter xml:id="base16--status">
- <title><tt>base16::status</tt></title>
- <code-block lang="C++">
- enum class base16::status
- {
- ok,
- invalid_length,
- invalid_digit
- };
- using base16::status_t = base16::status; // for C++98
- </code-block>
- <p>Input sequence parsing outcome status codes returned by
- <xref to="base16--try_decode"/>.</p>
- </chapter>
- <chapter xml:id="base16--encode_upper">
- <title><tt>base16::encode_upper()</tt></title>
- <code-block lang="C++"><![CDATA[
- // Bytes -> Text
- template<class ByteReader, class CharWriter>
- void base16::encode_upper(ByteReader reader, CharWriter writer);
- ]]></code-block>
- <p>Encodes bytes from <tt>reader</tt> and writes the resulting characters to
- <tt>writer</tt>. Upper case is used for hexadecimal digits.</p>
- <p><tt>ByteReader</tt> has to model <tt>Reader<unsigned char></tt> concept.
- See <xref to="readers"/>.</p>
- <p><tt>CharWriter</tt> has to model <tt>Writer<char></tt> concept.
- See <xref to="writers"/>.</p>
- <section><title>Example</title>
- <code-block lang="C++"><![CDATA[
- #include<__vic/readers/string.h>
- #include<__vic/writers/string.h>
- using bytes = std::string;
- using bytes_reader = __vic::string_reader;
- std::string encode_base16(const bytes &s)
- {
- std::string res;
- res.reserve(s.length() * 2);
- __vic::base16::encode_upper(bytes_reader(s), __vic::string_writer(res));
- return res;
- }
- ]]></code-block>
- </section>
- </chapter>
- <chapter xml:id="base16--encode_lower">
- <title><tt>base16::encode_lower()</tt></title>
- <code-block lang="C++"><![CDATA[
- // Bytes -> Text
- template<class ByteReader, class CharWriter>
- void base16::encode_lower(ByteReader reader, CharWriter writer);
- ]]></code-block>
- <p>Same as <xref to="base16--encode_upper"/> but lower case is used for
- hexadecimal digits.</p>
- </chapter>
- <chapter xml:id="base16--encode_byte_lower">
- <title><tt>base16::encode_byte_lower()</tt></title>
- <code-block lang="C++"><![CDATA[
- // Byte -> Text
- template<class CharWriter>
- void base16::encode_byte_lower(unsigned char byte, CharWriter writer);
- ]]></code-block>
- <p>Same as <xref to="base16--encode_lower"/> but encodes only single byte.</p>
- </chapter>
- <chapter xml:id="base16--encode_byte_upper">
- <title><tt>base16::encode_byte_upper()</tt></title>
- <code-block lang="C++"><![CDATA[
- // Byte -> Text
- template<class CharWriter>
- void base16::encode_byte_upper(unsigned char byte, CharWriter writer);
- ]]></code-block>
- <p>Same as <xref to="base16--encode_upper"/> but encodes only single byte.</p>
- </chapter>
- <chapter xml:id="base16--decode">
- <title><tt>base16::decode()</tt></title>
- <code-block lang="C++"><![CDATA[
- // Text -> Bytes
- template<class CharReader, class ByteWriter>
- void base16::decode(CharReader reader, ByteWriter writer);
- ]]></code-block>
- <p>Decodes characters from <tt>reader</tt> and writes the resulting bytes to
- <tt>writer</tt>. Exception derived from <xref to="base16--bad_format"/> is
- thrown if the input sequence has invalid Base16 format.</p>
- <p><tt>CharReader</tt> has to model <tt>Reader<char></tt> concept.
- See <xref to="readers"/>.</p>
- <p><tt>ByteWriter</tt> has to model <tt>Writer<unsigned char></tt> concept.
- See <xref to="writers"/>.</p>
- <section><title>Example</title>
- <code-block lang="C++"><![CDATA[
- #include<__vic/readers/string.h>
- #include<__vic/writers/string.h>
- using bytes = std::string;
- using bytes_writer = __vic::string_writer;
- bytes decode_base16(const std::string &s)
- {
- bytes res;
- res.reserve(s.length() / 2);
- __vic::base16::decode(__vic::string_reader(s), bytes_writer(res));
- return res;
- }
- ]]></code-block>
- </section>
- </chapter>
- <chapter xml:id="base16--try_decode">
- <title><tt>base16::try_decode()</tt></title>
- <code-block lang="C++"><![CDATA[
- // Text -> Bytes
- template<class CharReader, class ByteWriter>
- base16::status_t base16::try_decode(CharReader reader, ByteWriter writer);
- ]]></code-block>
- <p>Same as <xref to="base16--decode"/> but returns <xref to="base16--status"/>
- different from <tt>base16::status::ok</tt> in case of invalid input sequence
- instead of throwing exception.</p>
- </chapter>
- </chapter>
|