Vault  4.1
Public Member Functions | Static Public Member Functions
VHex Class Reference

VHex is mainly a namespace for some global functions converting to/from hexadecimal strings and buffer display. More...

#include <vhex.h>

List of all members.

Public Member Functions

 VHex (VTextIOStream *outputStream=NULL, int numBytesPerRow=16, int indentCount=2, bool labelsInHex=false, bool showASCIIValues=true)
 Creates a hex dump object with specified parameters.
virtual ~VHex ()
 Destructor.
void printHex (const Vu8 *buffer, Vs64 length, Vs64 offset=0)
 Prints a buffer of hex data according to the settings set at construction.
void reset ()
 Resets the object so it can be re-used for a brand new hex dump.
void flush ()
 Flushes any unwritten output.

Static Public Member Functions

static void bufferToHexString (const Vu8 *buffer, Vs64 bufferLength, VString &s, bool wantLeading0x=false)
 Produces a hexadecimal string representation of the specified buffer data.
static void hexStringToBuffer (const VString &hexDigits, Vu8 *buffer, bool hasLeading0x=false)
 Produces a buffer of bytes as specified by a supplied hexadecimal string representation.
static void stringToHex (const VString &text, VString &hexDigits, bool wantLeading0x=false)
 Produces a hexadecimal string representation of the specified buffer data.
static void hexToString (const VString &hexDigits, VString &text, bool hasLeading0x=false)
 Produces a buffer of bytes as specified by a supplied hexadecimal string representation.
static void byteToHexString (Vu8 byteValue, VString &s)
 Produces a 2-character hexadecimal string representing the supplied byte value.
static void byteToHexChars (Vu8 byteValue, char *highNibbleChar, char *lowNibbleChar)
 Produces two hexadecimal characters representing the supplied byte value.
static Vu8 hexStringToByte (const char *twoHexDigits)
 Produces a byte value as specified by a supplied pair of hexadecimal chars.
static Vu8 hexCharsToByte (char highNibbleChar, char lowNibbleChar)
 Produces a byte value as specified by a supplied pair of hexadecimal chars.
static char nibbleToHexChar (Vu8 nibbleValue)
 Produces a char representing the low nibble of a supplied byte value.
static Vu8 hexCharToNibble (char hexChar)
 Produces a byte value with a zero high nibble and a low nibble as specified by a supplied hex digit char.
static void bufferToPrintableASCIIString (const Vu8 *buffer, Vs64 bufferLength, VString &s)
 Produces a string representation of the specified buffer data, where any byte in the printable ASCII range 0x20 to 0x7E is shown as its ASCII character, and anything else is a period ('.
static void readHexDump (VTextIOStream &inputStream, VBinaryIOStream &outputStream)
 This function can be used to read a hex dump and create an in-memory buffer from it.

Detailed Description

VHex is mainly a namespace for some global functions converting to/from hexadecimal strings and buffer display.

You can also instantiate an object for hex dump generation.

The static functions can be used standalone; they build up functionality to convert between buffer and hex string, using simpler functions to convert between shorter sequences of bytes and characters.

If you want a pretty hex dump, instantiate a VHex object with formatting parameters, and then call its printHex() method with the desired output object.

Definition at line 35 of file vhex.h.


Constructor & Destructor Documentation

VHex::VHex ( VTextIOStream outputStream = NULL,
int  numBytesPerRow = 16,
int  indentCount = 2,
bool  labelsInHex = false,
bool  showASCIIValues = true 
)

Creates a hex dump object with specified parameters.

Parameters:
outputStreamthe text stream to print to, or NULL for stdout
numBytesPerRowthe number of data bytes to display per row of text output
indentCountthe number of spaces to lead each row with
labelsInHextrue if the offset labels should be given in hex, false for decimal
showASCIIValuestrue if each byte's ASCII equivalent should be displayed

Definition at line 205 of file vhex.cpp.


Member Function Documentation

void VHex::bufferToHexString ( const Vu8 buffer,
Vs64  bufferLength,
VString s,
bool  wantLeading0x = false 
) [static]

Produces a hexadecimal string representation of the specified buffer data.

Parameters:
bufferpointer to the data to parse
bufferLengththe length of data to parse
sthe string to format
wantLeading0xtrue if you want the string prefaced with the text "0x"

Definition at line 17 of file vhex.cpp.

References VString::buffer(), byteToHexChars(), VString::postflight(), and VString::preflight().

void VHex::hexStringToBuffer ( const VString hexDigits,
Vu8 buffer,
bool  hasLeading0x = false 
) [static]

Produces a buffer of bytes as specified by a supplied hexadecimal string representation.

Parameters:
hexDigitsthe hexadecimal string
bufferthe buffer to fill (must be big enough!)
hasLeading0xtrue if the hexadecimal string starts with a leading "0x"

Definition at line 47 of file vhex.cpp.

References VString::charAt(), hexCharsToByte(), and VString::length().

void VHex::stringToHex ( const VString text,
VString hexDigits,
bool  wantLeading0x = false 
) [static]

Produces a hexadecimal string representation of the specified buffer data.

Parameters:
textthe string to convert
hexDigitsthe returned hex string
wantLeading0xtrue if you want the string prefaced with the text "0x"

Definition at line 74 of file vhex.cpp.

References bufferToHexString(), VString::getDataBufferConst(), and VString::length().

void VHex::hexToString ( const VString hexDigits,
VString text,
bool  hasLeading0x = false 
) [static]

Produces a buffer of bytes as specified by a supplied hexadecimal string representation.

Parameters:
hexDigitsthe hexadecimal string
textthe returned plain text string
hasLeading0xtrue if the hexadecimal string starts with a leading "0x" that must be ignored

Definition at line 79 of file vhex.cpp.

References VString::getDataBuffer(), hexStringToBuffer(), VString::length(), VString::postflight(), and VString::preflight().

void VHex::byteToHexString ( Vu8  byteValue,
VString s 
) [static]

Produces a 2-character hexadecimal string representing the supplied byte value.

Parameters:
byteValuethe byte value to convert to hex
sthe string to format

Definition at line 92 of file vhex.cpp.

References byteToHexChars().

void VHex::byteToHexChars ( Vu8  byteValue,
char *  highNibbleChar,
char *  lowNibbleChar 
) [static]

Produces two hexadecimal characters representing the supplied byte value.

Parameters:
byteValuethe byte value to convert to hex
highNibbleCharpointer to the char that will contain the high nibble hex digit
lowNibbleCharpointer to the char that will contain the low nibble hex digit

Definition at line 102 of file vhex.cpp.

References nibbleToHexChar().

Vu8 VHex::hexStringToByte ( const char *  twoHexDigits) [static]

Produces a byte value as specified by a supplied pair of hexadecimal chars.

Parameters:
twoHexDigitspointer to buffer containing (at least) two chars
Returns:
the byte containing the value specified by the two hex digits

Definition at line 108 of file vhex.cpp.

References hexCharToNibble().

Vu8 VHex::hexCharsToByte ( char  highNibbleChar,
char  lowNibbleChar 
) [static]

Produces a byte value as specified by a supplied pair of hexadecimal chars.

Parameters:
highNibbleChara hex digit char specifying the high nibble of the byte
lowNibbleChara hex digit char specifying the low nibble of the byte
Returns:
the byte containing the value specified by the two hex digits

Definition at line 116 of file vhex.cpp.

References hexCharToNibble().

char VHex::nibbleToHexChar ( Vu8  nibbleValue) [static]

Produces a char representing the low nibble of a supplied byte value.

Parameters:
nibbleValuea byte whose low nibble will be converted to hex
Returns:
the hex digit representing the supplied byte's low nibble

Definition at line 124 of file vhex.cpp.

Vu8 VHex::hexCharToNibble ( char  hexChar) [static]

Produces a byte value with a zero high nibble and a low nibble as specified by a supplied hex digit char.

Parameters:
hexCharthe hex digit
Returns:
a byte value whose low nibble is specified by the hexChar param

Definition at line 134 of file vhex.cpp.

void VHex::bufferToPrintableASCIIString ( const Vu8 buffer,
Vs64  bufferLength,
VString s 
) [static]

Produces a string representation of the specified buffer data, where any byte in the printable ASCII range 0x20 to 0x7E is shown as its ASCII character, and anything else is a period ('.

').

Parameters:
bufferpointer to the data to parse
bufferLengththe length of data to parse
sthe string to format

Definition at line 146 of file vhex.cpp.

void VHex::readHexDump ( VTextIOStream inputStream,
VBinaryIOStream outputStream 
) [static]

This function can be used to read a hex dump and create an in-memory buffer from it.

The input text is presumed to be in the format generated by VHex::printHex, and each time you call this function it will return a newly allocated buffer for the next chunk of the hex dump. A chunk is delineated by a blank line, so this function returns after reading a blank line, with the i/o mark ending at the next chunk header line. If the next line in the stream is blank when you call this function, the outputStream returned will be empty. If you call this repeatedly on an input file stream, you will eventually see a VEOFException thrown by the file reader at the end of the file. If this function encounters a line in an unexpected format, it will simply skip that line; this could allow you to annotate a hex dump. The lines this function expects are: 1. Lines of hex data in the form, detected by offset label, colon, hex data, ascii data e.g.: 00000000: 00 00 00 01 00 00 00 20 11 77 6F 72 6B 2E 69 6E .........work.in Only the hex bytes are processed; end of data is indicated by more than one space. 2. Blank lines (treated as end of chunk) 3. Anything else. (ignored)

Definition at line 157 of file vhex.cpp.

References hexCharsToByte(), VString::isEmpty(), VChar::isHexadecimal(), VString::isNotEmpty(), VString::length(), VTextIOStream::readLine(), VString::startsWith(), VString::trim(), and VBinaryIOStream::writeU8().

void VHex::printHex ( const Vu8 buffer,
Vs64  length,
Vs64  offset = 0 
)

Prints a buffer of hex data according to the settings set at construction.

Parameters:
bufferpointer to the buffer of data to dump
lengththe number of bytes of data to dump
offsetbyte offset in the buffer of the first byte of data to be dumped

Definition at line 225 of file vhex.cpp.

References flush().


The documentation for this class was generated from the following files:

Copyright ©1997-2014 Trygve Isaacson. All rights reserved. This documentation was generated with Doxygen.