feisty meow concerns codebase  2.140
byte_formatter.h
Go to the documentation of this file.
1 #ifndef BYTE_FORMATTER_CLASS
2 #define BYTE_FORMATTER_CLASS
3 
4 /*****************************************************************************\
5 * *
6 * Name : byte_formatter *
7 * Author : Chris Koeritz *
8 * *
9 *******************************************************************************
10 * Copyright (c) 1992-$now By Author. This program is free software; you can *
11 * redistribute it and/or modify it under the terms of the GNU General Public *
12 * License as published by the Free Software Foundation; either version 2 of *
13 * the License or (at your option) any later version. This is online at: *
14 * http://www.fsf.org/copyleft/gpl.html *
15 * Please send any updates to: fred@gruntose.com *
16 \*****************************************************************************/
17 
18 #include <basis/astring.h>
19 #include <basis/definitions.h>
20 
21 namespace textual {
22 
24 
25 class byte_formatter : public virtual basis::root_object
26 {
27 public:
28  virtual ~byte_formatter() {}
29 
30  DEFINE_CLASS_NAME("byte_formatter");
31 
32  static void print_char(basis::abyte to_print, basis::astring &out,
33  char replace = '_');
35 
37  static void print_chars(const basis::abyte *to_print, int length,
38  basis::astring &out, char replace = '_');
40 
41  static void text_dump(basis::astring &output, const basis::abyte *location,
42  basis::un_int length, basis::un_int label = 0, const char *eol = "\n");
44 
50  static basis::astring text_dump(const basis::abyte *location, basis::un_int length,
51  basis::un_int label = 0, const char *eol = "\n");
53 
55  static void text_dump(basis::astring &output,
56  const basis::byte_array &to_dump, basis::un_int label = 0, const char *eol = "\n");
58  static basis::astring text_dump(const basis::byte_array &to_dump,
59  basis::un_int label = 0, const char *eol = "\n");
61 
63  static void parse_dump(const basis::astring &dumped_form,
64  basis::byte_array &bytes_found);
65 
67 
68  static void bytes_to_string(const basis::byte_array &to_convert,
69  basis::astring &as_string, bool space_delimited = true);
71 
75  static void string_to_bytes(const basis::astring &to_convert,
76  basis::byte_array &as_array);
78 
84  static void bytes_to_string(const basis::abyte *to_convert, int length,
85  basis::astring &as_string, bool space_delimited = true);
87 
88  static void string_to_bytes(const char *to_convert,
89  basis::byte_array &as_array);
91 
93 
94  static void bytes_to_shifted_string
95  (const basis::byte_array &to_convert, basis::astring &as_string);
97 
103  static void shifted_string_to_bytes(const basis::astring &to_convert,
104  basis::byte_array &as_array);
106 
111 
112  // utility methods to help building the formatted strings.
113 
114  static void make_eight(basis::un_int num, basis::astring &out);
115 
116  static bool in_hex_range(char to_check);
117 };
118 
119 } //namespace.
120 
121 #endif
122 
Provides a dynamically resizable ASCII character string.
Definition: astring.h:35
A very common template for a dynamic array of bytes.
Definition: byte_array.h:36
Provides functions for manipulating arrays of bytes.
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.
DEFINE_CLASS_NAME("byte_formatter")
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.
Constants and objects used throughout HOOPLE.
unsigned char abyte
A fairly important unit which is seldom defined...
Definition: definitions.h:51
unsigned int un_int
Abbreviated name for unsigned integers.
Definition: definitions.h:62