textual::byte_formatter Class Reference

Provides functions for manipulating arrays of bytes. More...

#include <byte_formatter.h>

Inheritance diagram for textual::byte_formatter:
Inheritance graph
[legend]
Collaboration diagram for textual::byte_formatter:
Collaboration graph
[legend]

List of all members.

Public Member Functions

virtual ~byte_formatter ()
 DEFINE_CLASS_NAME ("byte_formatter")

Static Public Member Functions

static void print_char (basis::abyte to_print, basis::astring &out, char replace= '_')
 prints the byte "to_print" into "out" as long as "to_print" is readable.
static void print_chars (const basis::abyte *to_print, int length, basis::astring &out, char replace= '_')
 sends the bytes in "to_print" of "length" bytes into the string "out".
static void text_dump (basis::astring &output, const basis::abyte *location, basis::un_int length, basis::un_int label=0, const char *eol="\n")
 prints out a block of memory in a human readable form.
static basis::astring text_dump (const basis::abyte *location, basis::un_int length, basis::un_int label=0, const char *eol="\n")
 this is a less efficient version of text_dump that returns a string.
static void text_dump (basis::astring &output, const basis::byte_array &to_dump, basis::un_int label=0, const char *eol="\n")
 a version that operates on a byte_array and stores into a string.
static basis::astring text_dump (const basis::byte_array &to_dump, basis::un_int label=0, const char *eol="\n")
 a version that operates on a byte_array and returns a string.
static void parse_dump (const basis::astring &dumped_form, basis::byte_array &bytes_found)
 this operation performs the inverse of a text_dump.
static void bytes_to_string (const basis::byte_array &to_convert, basis::astring &as_string, bool space_delimited=true)
 converts a byte_array into a string.
static void string_to_bytes (const basis::astring &to_convert, basis::byte_array &as_array)
 wrangles the string "to_convert" into an equivalent byte form "as_array".
static void bytes_to_string (const basis::abyte *to_convert, int length, basis::astring &as_string, bool space_delimited=true)
 a version that accepts a byte pointer and length, rather than byte_array.
static void string_to_bytes (const char *to_convert, basis::byte_array &as_array)
 a version that works with the char pointer rather than an astring.
static void bytes_to_shifted_string (const basis::byte_array &to_convert, basis::astring &as_string)
 this is a special purpose converter from bytes to character strings.
static void shifted_string_to_bytes (const basis::astring &to_convert, basis::byte_array &as_array)
 unshifts a string "to_convert" back into a byte_array.
static void make_eight (basis::un_int num, basis::astring &out)
static bool in_hex_range (char to_check)

Detailed Description

Provides functions for manipulating arrays of bytes.

Definition at line 25 of file byte_formatter.h.


Constructor & Destructor Documentation

virtual textual::byte_formatter::~byte_formatter (  )  [inline, virtual]

Definition at line 28 of file byte_formatter.h.


Member Function Documentation

void textual::byte_formatter::bytes_to_shifted_string ( const basis::byte_array to_convert,
basis::astring as_string 
) [static]

this is a special purpose converter from bytes to character strings.

it merely ensures that the "as_string" version has no zero bytes besides the end of string null byte. this packs 7 bits of data into each character, resulting in an 87.5% efficient string packing of the array. the resulting string is not readable. the "as_string" parameter is not reset; any data will be appended to it.

Definition at line 259 of file byte_formatter.cpp.

References FUNCDEF, basis::astring::length(), basis::array< contents >::length(), LOG, and basis::array< contents >::observe().

static void textual::byte_formatter::bytes_to_string ( const basis::abyte to_convert,
int  length,
basis::astring as_string,
bool  space_delimited = true 
) [static]

a version that accepts a byte pointer and length, rather than byte_array.

void textual::byte_formatter::bytes_to_string ( const basis::byte_array to_convert,
basis::astring as_string,
bool  space_delimited = true 
) [static]

converts a byte_array into a string.

takes an array of bytes "to_convert" and spits out the equivalent form "as_string". if "space_delimited" is true, then the bytes are separated by spaces.

Definition at line 249 of file byte_formatter.cpp.

References basis::array< contents >::length(), and basis::array< contents >::observe().

textual::byte_formatter::DEFINE_CLASS_NAME ( "byte_formatter"   ) 
bool textual::byte_formatter::in_hex_range ( char  to_check  )  [static]

Definition at line 179 of file byte_formatter.cpp.

Referenced by string_to_bytes().

void textual::byte_formatter::make_eight ( basis::un_int  num,
basis::astring out 
) [static]

Definition at line 53 of file byte_formatter.cpp.

void textual::byte_formatter::parse_dump ( const basis::astring dumped_form,
basis::byte_array bytes_found 
) [static]
static void textual::byte_formatter::print_char ( basis::abyte  to_print,
basis::astring out,
char  replace = '_' 
) [static]

prints the byte "to_print" into "out" as long as "to_print" is readable.

if it's not readable, then the "replace" is printed.

static void textual::byte_formatter::print_chars ( const basis::abyte to_print,
int  length,
basis::astring out,
char  replace = '_' 
) [static]

sends the bytes in "to_print" of "length" bytes into the string "out".

void textual::byte_formatter::shifted_string_to_bytes ( const basis::astring to_convert,
basis::byte_array as_array 
) [static]

unshifts a string "to_convert" back into a byte_array.

converts a string "to_convert" created by bytes_to_shifted_string() into the original array of bytes and stores it in "as_array". the "as_array" parameter is not reset; any data will be appended to it.

Definition at line 281 of file byte_formatter.cpp.

References structures::bit_vector::bits(), deadly_error, FUNCDEF, basis::array< contents >::length(), basis::astring::length(), LOG, structures::bit_vector::resize(), and structures::bit_vector::set_bit().

void textual::byte_formatter::string_to_bytes ( const char *  to_convert,
basis::byte_array as_array 
) [static]

a version that works with the char pointer rather than an astring.

Definition at line 187 of file byte_formatter.cpp.

References textual::string_manipulation::char_to_hex(), in_hex_range(), and basis::array< contents >::reset().

void textual::byte_formatter::string_to_bytes ( const basis::astring to_convert,
basis::byte_array as_array 
) [static]

wrangles the string "to_convert" into an equivalent byte form "as_array".

this is a fairly forgiving conversion; it will accept any string and strip out the hexadecimal bytes. spacing is optional, but every two hex nibbles together will be taken as a byte. if there are an odd number of nibbles, then the odd one will be taken as the least significant half of a byte.

Definition at line 256 of file byte_formatter.cpp.

References basis::astring::s().

Referenced by parse_dump().

astring textual::byte_formatter::text_dump ( const basis::byte_array to_dump,
basis::un_int  label = 0,
const char *  eol = "\n" 
) [static]

a version that operates on a byte_array and returns a string.

Definition at line 77 of file byte_formatter.cpp.

References basis::array< contents >::length(), basis::array< contents >::observe(), and text_dump().

void textual::byte_formatter::text_dump ( basis::astring output,
const basis::byte_array to_dump,
basis::un_int  label = 0,
const char *  eol = "\n" 
) [static]

a version that operates on a byte_array and stores into a string.

Definition at line 71 of file byte_formatter.cpp.

References basis::array< contents >::length(), basis::array< contents >::observe(), and text_dump().

static basis::astring textual::byte_formatter::text_dump ( const basis::abyte location,
basis::un_int  length,
basis::un_int  label = 0,
const char *  eol = "\n" 
) [static]

this is a less efficient version of text_dump that returns a string.

it's easier to use when combining astrings.

static void textual::byte_formatter::text_dump ( basis::astring output,
const basis::abyte location,
basis::un_int  length,
basis::un_int  label = 0,
const char *  eol = "\n" 
) [static]

prints out a block of memory in a human readable form.

it is stored in the "output" string. the "location" is where to dump, the "length" is the number of bytes to dump, and the "label" is where to start numbering the location label on the first line. the "eol" supplies the line ending sequence to be used for the output file. this should be "\r\n" for win32.

Referenced by text_dump().


The documentation for this class was generated from the following files:
Generated on Sat Jan 28 04:26:03 2012 for hoople2 project by  doxygen 1.6.3