|
Open Model Railroad Network (OpenMRN)
|
#include <string>#include <string.h>#include <stdint.h>Go to the source code of this file.
Functions | |
| char * | integer_to_buffer (int value, char *buffer) |
| Renders an integer to string, left-justified. | |
| char * | unsigned_integer_to_buffer (int value, char *buffer) |
| Renders an unsigned integer to string, left-justified. | |
| char * | uint64_integer_to_buffer (uint64_t value, char *buffer) |
| Renders an uint64_t to string, left-justified. | |
| char * | int64_integer_to_buffer (int64_t value, char *buffer) |
| Renders an int64_t to string, left-justified. | |
| char * | unsigned_integer_to_buffer_hex (unsigned int value, char *buffer) |
| Renders an unsigned integer to string, left-justified. | |
| char * | uint64_integer_to_buffer_hex (uint64_t value, char *buffer) |
| Renders an uint64_t to string, left-justified. | |
| char * | int64_integer_to_buffer_hex (int64_t value, char *buffer) |
| Renders an int64_t to string, left-justified. | |
| string | integer_to_string (int value, unsigned padding=0) |
| Renders an integer to std::string, left-justified. | |
| string | uint64_to_string (uint64_t value, unsigned padding=0) |
| Renders an uint64_t to std::string, left-justified. | |
| string | int64_to_string (int64_t value, unsigned padding=0) |
| Renders an int64_t to std::string, left-justified. | |
| string | uint64_to_string_hex (uint64_t value, unsigned padding=0) |
| Renders an uint64_t to std::string, left-justified. | |
| string | int64_to_string_hex (int64_t value, unsigned padding=0) |
| Renders an int64_t to std::string, left-justified. | |
| string | string_to_hex (const string &arg) |
| Converts a (binary) string into a sequence of hex digits. | |
| size_t | hex_to_string (const char *input, size_t len, string *output, bool ignore_nonhex=false) |
| Converts hex bytes to binary representation. | |
| string | mac_to_string (uint8_t mac[6], char colon=':') |
| Formats a MAC address to string. | |
| string | ipv4_to_string (uint8_t ip[4]) |
| Formats an IPv4 address to string. | |
| string | ipv4_to_string (uint32_t ip) |
| Formats an IPv4 address to string. | |
| template<unsigned int N> | |
| void | str_populate (char(&dst)[N], const char *src) |
| Populates a character array with a C string. | |
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Simple codefor some trivial formatting uses.
Definition in file format_utils.hxx.
| size_t hex_to_string | ( | const char * | input, |
| size_t | len, | ||
| string * | output, | ||
| bool | ignore_nonhex = false |
||
| ) |
Converts hex bytes to binary representation.
| input | points to the input hexadecimal string |
| len | how many bytes are there |
| output | parsed byte data will be appended here |
| ignore_nonhex | if true, jumps over all nonhex characters. If false, stops at the first nonhex character. |
Definition at line 262 of file format_utils.cxx.
| char * int64_integer_to_buffer | ( | int64_t | value, |
| char * | buffer | ||
| ) |
Renders an int64_t to string, left-justified.
| buffer | must be an at least 22 character long array. |
| value | will be rendered into the buffer. |
Definition at line 156 of file format_utils.cxx.
| char * int64_integer_to_buffer_hex | ( | int64_t | value, |
| char * | buffer | ||
| ) |
Renders an int64_t to string, left-justified.
| buffer | must be an at least 18 character long array. |
| value | will be rendered into the buffer. |
Definition at line 90 of file format_utils.cxx.
| string int64_to_string | ( | int64_t | value, |
| unsigned | padding = 0 |
||
| ) |
Renders an int64_t to std::string, left-justified.
| value | will be rendered into the buffer. |
| padding | number of bytes that the resulting string should be. |
Definition at line 193 of file format_utils.cxx.
| string int64_to_string_hex | ( | int64_t | value, |
| unsigned | padding = 0 |
||
| ) |
Renders an int64_t to std::string, left-justified.
| value | will be rendered into the buffer. |
| padding | number of bytes that the resulting string should be. |
Definition at line 219 of file format_utils.cxx.
| char * integer_to_buffer | ( | int | value, |
| char * | buffer | ||
| ) |
Renders an integer to string, left-justified.
| buffer | must be an at |
| buffer | must be an at least 10 character long array. |
| value | will be rendered into the buffer. |
Definition at line 145 of file format_utils.cxx.
| string integer_to_string | ( | int | value, |
| unsigned | padding = 0 |
||
| ) |
Renders an integer to std::string, left-justified.
| value | will be rendered into the buffer. |
| padding | number of bytes that the resulting string should be. |
Definition at line 167 of file format_utils.cxx.
|
inline |
Formats an IPv4 address to string.
| ip | a uint32_t storing the IPv4 address. most significant bytes will be printed at the beginning. |
Definition at line 181 of file format_utils.hxx.
| string ipv4_to_string | ( | uint8_t | ip[4] | ) |
Formats an IPv4 address to string.
| ip | a 4-byte array storing the IPv4 address. ip[3] will be printed at the beginning. |
Definition at line 321 of file format_utils.cxx.
| string mac_to_string | ( | uint8_t | mac[6], |
| char | colon = ':' |
||
| ) |
Formats a MAC address to string.
Works both for Ethernet addresses as well as for OpenLCB node IDs.
| mac | a 6-byte array storing the MAC address. mac[0] will be printed at the beginning. |
| colons | Specifies byte separators. Leave as default (':') to print colons, an alternate character to use as separator, or set to 0 to exclude the seperators entirely. |
Definition at line 296 of file format_utils.cxx.
|
inline |
Populates a character array with a C string.
Copies the C string, appropriately truncating if it is too long and filling the remaining space with zeroes. Ensures that at least one null terminator character is present.
| dst | a character array of fixed length, declared as char sdata[N] |
| src | a C string to fill it with. |
Definition at line 193 of file format_utils.hxx.
| string string_to_hex | ( | const string & | arg | ) |
Converts a (binary) string into a sequence of hex digits.
| arg | input string |
Definition at line 232 of file format_utils.cxx.
| char * uint64_integer_to_buffer | ( | uint64_t | value, |
| char * | buffer | ||
| ) |
Renders an uint64_t to string, left-justified.
| buffer | must be an at least 21 character long array. |
| value | will be rendered into the buffer. |
Definition at line 123 of file format_utils.cxx.
| char * uint64_integer_to_buffer_hex | ( | uint64_t | value, |
| char * | buffer | ||
| ) |
Renders an uint64_t to string, left-justified.
| buffer | must be an at least 17 character long array. |
| value | will be rendered into the buffer. |
Definition at line 68 of file format_utils.cxx.
| string uint64_to_string | ( | uint64_t | value, |
| unsigned | padding = 0 |
||
| ) |
Renders an uint64_t to std::string, left-justified.
| value | will be rendered into the buffer. |
| padding | number of bytes that the resulting string should be. |
Definition at line 180 of file format_utils.cxx.
| string uint64_to_string_hex | ( | uint64_t | value, |
| unsigned | padding = 0 |
||
| ) |
Renders an uint64_t to std::string, left-justified.
| value | will be rendered into the buffer. |
| padding | number of bytes that the resulting string should be. |
Definition at line 206 of file format_utils.cxx.
| char * unsigned_integer_to_buffer | ( | int | value, |
| char * | buffer | ||
| ) |
Renders an unsigned integer to string, left-justified.
| buffer | must be an at least 10 character long array. |
| value | will be rendered into the buffer. |
Definition at line 101 of file format_utils.cxx.
| char * unsigned_integer_to_buffer_hex | ( | unsigned int | value, |
| char * | buffer | ||
| ) |
Renders an unsigned integer to string, left-justified.
| buffer | must be an at least 10 character long array. |
| value | will be rendered into the buffer. |
Definition at line 46 of file format_utils.cxx.