feisty meow concerns codebase  2.140
textual::byte_formatter Class Reference

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

#include <byte_formatter.h>

Inheritance diagram for textual::byte_formatter:
Collaboration diagram for textual::byte_formatter:

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. More...
 
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". More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
static void parse_dump (const basis::astring &dumped_form, basis::byte_array &bytes_found)
 this operation performs the inverse of a text_dump. More...
 
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. More...
 
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". More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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

◆ ~byte_formatter()

virtual textual::byte_formatter::~byte_formatter ( )
inlinevirtual

Definition at line 28 of file byte_formatter.h.

Member Function Documentation

◆ bytes_to_shifted_string()

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 structures::bit_vector::bits(), FUNCDEF, basis::array< contents >::length(), basis::astring::length(), LOG, basis::array< contents >::observe(), structures::bit_vector::on(), and basis::astring::s().

◆ bytes_to_string() [1/2]

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.

Definition at line 161 of file byte_formatter.cpp.

References basis::negative(), basis::astring::s(), and basis::astring::SPRINTF.

◆ bytes_to_string() [2/2]

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().

◆ DEFINE_CLASS_NAME()

textual::byte_formatter::DEFINE_CLASS_NAME ( "byte_formatter"  )

◆ in_hex_range()

bool textual::byte_formatter::in_hex_range ( char  to_check)
static

Definition at line 179 of file byte_formatter.cpp.

◆ make_eight()

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

Definition at line 53 of file byte_formatter.cpp.

References eml_to_txt::num.

◆ parse_dump()

void textual::byte_formatter::parse_dump ( const basis::astring dumped_form,
basis::byte_array bytes_found 
)
static

◆ print_char()

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.

Definition at line 40 of file byte_formatter.cpp.

◆ print_chars()

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".

Definition at line 47 of file byte_formatter.cpp.

◆ shifted_string_to_bytes()

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(), basis::astring::s(), and structures::bit_vector::set_bit().

◆ string_to_bytes() [1/2]

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().

◆ string_to_bytes() [2/2]

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 basis::array< contents >::reset().

◆ text_dump() [1/4]

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.

Definition at line 85 of file byte_formatter.cpp.

References LINE_SIZE, and basis::astring::SPRINTF.

◆ text_dump() [2/4]

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(), and basis::array< contents >::observe().

◆ text_dump() [3/4]

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.

Definition at line 63 of file byte_formatter.cpp.

◆ text_dump() [4/4]

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(), and basis::array< contents >::observe().


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