27#ifdef DEBUG_BYTE_FORMAT
28 #define LOG(s) printf("%s\n", astring(s).s())
42 int temp = to_print % 128;
44 else out += char(temp);
49 for (
int i = 0; i < len; i++)
56 while (thresh >= 0x10) {
67 text_dump(to_return, location, length, label, eol);
94 for (
basis::un_int i = 0; i < length; i += entries_per_line) {
98 if (i + j >= length) {
102 int ord_of_current_char = *(location + i + j) & 0xFF;
103 if (ord_of_current_char < 0x10) to_return +=
'0';
111 if (k >= length) to_return +=
' ';
115 to_return +=
astring(
" |") + eol;
124 for (
int i = 0; i < dumped_form.
length(); i++) {
125 int indy = dumped_form.
find(
'\n', i);
130 if (i < dumped_form.
length() - 1) {
138 lines_found += dumped_form.
substring(i, indy - 1);
142 for (
int j = 0; j < lines_found.
length(); j++) {
146 int bar_one = s.
find(
'|', 0);
150 int bar_two = s.
find(
'|', bar_one + 1);
155 bytes_found += this_part;
162 bool space_delimited)
164 if (!to_convert || !length)
return;
170 if (space_delimited) pattern +=
" ";
173 for (
int i = 0; i < length; i++)
182 return ( (to_check <=
'9') && (to_check >=
'0') )
183 || ( (to_check <=
'f') && (to_check >=
'a') )
184 || ( (to_check <=
'F') && (to_check >=
'A') );
190 const int len = int(strlen(to_convert));
193 enum states { FINDING_HEX, IGNORING_JUNK };
194 states state = IGNORING_JUNK;
200 for (
int i = 0; i < len; i++) {
202 case IGNORING_JUNK: {
214 as_array +=
abyte(accumulator);
218 state = IGNORING_JUNK;
236 state = IGNORING_JUNK;
245 as_array +=
abyte(accumulator);
250 bool space_delimited)
261#ifdef DEBUG_BYTE_FORMAT
262 FUNCDEF(
"bytes_to_shifted_string");
266 for (i = 0; i < splitter.
bits(); i += 7) {
268 for (
int j = i; j < i + 7; j++) {
270 if (j < splitter.
bits())
273 as_string += char(curr);
275#ifdef DEBUG_BYTE_FORMAT
283#ifdef DEBUG_BYTE_FORMAT
284 FUNCDEF(
"shifted_string_to_bytes");
288 for (
int i = 0; i < to_convert.
length(); i++) {
293 for (
int j = 0; j < 7; j++) {
296 abyte set_here = current & 0x80;
298 accumulator.
set_bit(i * 7 + j,
bool(set_here));
302 int remainder = accumulator.
bits() % 8;
303 accumulator.
resize(accumulator.
bits() - remainder);
306#ifdef DEBUG_BYTE_FORMAT
309 if (accumulator.
bits() % 8)
310 deadly_error(
"byte_formatter", func,
"number of bits is erroneous.");
314 for (
int q = 0; q < accumulator.
bits() / 8; q++)
315 as_array += accumref[q];
317#ifdef DEBUG_BYTE_FORMAT
a_sprintf is a specialization of astring that provides printf style support.
void reset(int number=0, const contents *initial_contents=NULL_POINTER)
Resizes this array and sets the contents from an array of contents.
const contents * observe() const
Returns a pointer to the underlying C array of data.
int length() const
Returns the current reported length of the allocated C array.
Provides a dynamically resizable ASCII character string.
const char * s() const
synonym for observe. the 's' stands for "string", if that helps.
bool substring(astring &target, int start, int end) const
a version that stores the substring in an existing "target" string.
int length() const
Returns the current length of the string.
int find(char to_find, int position=0, bool reverse=false) const
Locates "to_find" in "this".
A very common template for a dynamic array of bytes.
An array of bits with operations for manipulating and querying individual bits.
bool on(int position) const
returns true if the bit at "position" is set.
int bits() const
returns the number of bits in the vector.
void set_bit(int position, bool value)
sets the bit at "position" to a particular "value".
void resize(int size)
Changes the size of the bit_vector to "size" bits.
An array of strings with some additional helpful methods.
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 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 bool in_hex_range(char to_check)
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 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 parse_dump(const basis::astring &dumped_form, basis::byte_array &bytes_found)
this operation performs the inverse of a text_dump.
static void make_eight(basis::un_int num, basis::astring &out)
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 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 bool is_printable_ascii(char to_check)
returns true if "to_check" is a normally visible ASCII character.
static basis::abyte char_to_hex(char to_convert)
Converts a single character into the corresponding hex nibble.
#define deadly_error(c, f, i)
#define FUNCDEF(func_in)
FUNCDEF sets the name of a function (and plugs it into the callstack).
The guards collection helps in testing preconditions and reporting errors.
unsigned char abyte
A fairly important unit which is seldom defined...
unsigned int un_int
Abbreviated name for unsigned integers.
bool negative(const type &a)
negative returns true if "a" is less than zero.
A dynamic container class that holds any kind of object via pointers.