8#ifndef INCLUDED_BDLDE_HEXDECODER
9#define INCLUDED_BDLDE_HEXDECODER
308#include <bdlscm_version.h>
312#include <bsl_iterator.h>
336 const char *d_decodeTable_p;
342 static bool isSpace(
char character);
346 static bool isXdigit(
char character);
378 template <
class OUTPUT_ITERATOR,
class INPUT_ITERATOR>
379 int convert(OUTPUT_ITERATOR out,
380 INPUT_ITERATOR begin,
382 template <
class OUTPUT_ITERATOR,
class INPUT_ITERATOR>
383 int convert(OUTPUT_ITERATOR out,
386 INPUT_ITERATOR begin,
442bool HexDecoder::isSpace(
char character)
444 static const bool k_SPACE_TABLE[256] = {
446 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0,
447 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
448 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
449 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
450 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
451 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
452 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
453 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
456 return k_SPACE_TABLE[
static_cast<unsigned char>(character)];
460bool HexDecoder::isXdigit(
char character)
462 static const bool k_XDIGIT_TABLE[256] = {
464 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
465 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
466 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
467 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0,
468 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0,
469 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
470 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0,
471 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
474 return k_XDIGIT_TABLE[
static_cast<unsigned char>(character)];
478template <
class OUTPUT_ITERATOR,
class INPUT_ITERATOR>
480 INPUT_ITERATOR begin,
486 return convert(out, &dummyNumOut, &dummyNumIn, begin, end, -1);
489template <
class OUTPUT_ITERATOR,
class INPUT_ITERATOR>
493 INPUT_ITERATOR begin,
500 if (e_ERROR_STATE == d_state || e_DONE_STATE == d_state) {
501 int rv = e_DONE_STATE == d_state ? -2 : -1;
502 d_state = e_ERROR_STATE;
508 if (0 == maxNumOut) {
514 INPUT_ITERATOR originalBegin = begin;
517 while (begin != end && numEmitted != maxNumOut) {
518 const char digit =
static_cast<char>(*begin);
521 if (!isSpace(digit)) {
522 if (!isXdigit(digit)) {
523 *numOut = numEmitted;
524 d_outputLength += numEmitted;
525 *numIn =
static_cast<int>(bsl::distance(originalBegin, begin));
526 d_state = e_ERROR_STATE;
530 if (0 == d_firstDigit) {
531 d_firstDigit = digit;
534 char value =
static_cast<char>(
535 (d_decodeTable_p[
static_cast<int>(d_firstDigit)] << 4) |
536 (d_decodeTable_p[
static_cast<int>(digit )]));
546 *numOut = numEmitted;
547 d_outputLength += numEmitted;
548 *numIn =
static_cast<int>(bsl::distance(originalBegin, begin));
555 d_state = e_INPUT_STATE;
564 return e_INPUT_STATE == d_state && !d_firstDigit;
570 return e_DONE_STATE == d_state;
576 return e_ERROR_STATE == d_state;
582 return e_INPUT_STATE == d_state && 0 == d_outputLength && !d_firstDigit;
594 return d_outputLength;
Definition bdlde_hexdecoder.h:321
void reset()
Definition bdlde_hexdecoder.h:553
bool isInitialState() const
Definition bdlde_hexdecoder.h:580
bool isAcceptable() const
Definition bdlde_hexdecoder.h:562
int convert(OUTPUT_ITERATOR out, INPUT_ITERATOR begin, INPUT_ITERATOR end)
Definition bdlde_hexdecoder.h:479
HexDecoder()
Create a Hex decoder in the initial state.
int outputLength() const
Definition bdlde_hexdecoder.h:592
bool isDone() const
Definition bdlde_hexdecoder.h:568
bool isMaximal() const
Definition bdlde_hexdecoder.h:586
bool isError() const
Definition bdlde_hexdecoder.h:574
~HexDecoder()=default
Destroy this object.
#define BSLS_ASSERT(X)
Definition bsls_assert.h:1804
#define BSLS_IDENT(str)
Definition bsls_ident.h:195
Definition bdlde_base64alphabet.h:118