![]() |
Spicy
|
#include <bytes.h>
Public Types | |
using | Base = std::string |
using | const_iterator = bytes::Iterator |
using | Offset = uint64_t |
Public Member Functions | |
Bytes (std::string s, bytes::Charset cs) | |
Bytes (Base &&str) | |
Bytes (const Bytes &xs) | |
Bytes (Bytes &&xs) | |
Bytes & | operator= (const Bytes &b) |
Bytes & | operator= (Bytes &&b) |
void | append (const Bytes &d) |
void | append (const stream::View &view) |
void | append (const uint8_t x) |
const std::string & | str () const & |
const_iterator | begin () const |
const_iterator | end () const |
const_iterator | at (Offset o) const |
bool | isEmpty () const |
int64_t | size () const |
const_iterator | find (value_type b, const const_iterator &n=const_iterator()) const |
std::tuple< bool, const_iterator > | find (const Bytes &v, const const_iterator &n=const_iterator()) const |
Bytes | sub (const const_iterator &from, const const_iterator &to) const |
Bytes | sub (const const_iterator &to) const |
Bytes | sub (Offset from, Offset to) const |
Bytes | sub (Offset to) const |
template<int N> | |
Bytes | extract (unsigned char(&dst)[N]) const |
std::string | decode (bytes::Charset cs) const |
bool | startsWith (const Bytes &b) const |
Bytes | upper (bytes::Charset cs) const |
Bytes | lower (bytes::Charset cs) const |
Bytes | strip (const Bytes &set, bytes::Side side=bytes::Side::Both) const |
Bytes | strip (bytes::Side side=bytes::Side::Both) const |
Vector< Bytes > | split () const |
std::tuple< Bytes, Bytes > | split1 () const |
Vector< Bytes > | split (const Bytes &sep) const |
std::tuple< Bytes, Bytes > | split1 (const Bytes &sep) const |
template<typename T > | |
Bytes | join (const Vector< T > &parts) const |
integer::safe< int64_t > | toInt (uint64_t base=10) const |
integer::safe< uint64_t > | toUInt (uint64_t base=10) const |
int64_t | toInt (hilti::rt::ByteOrder byte_order) const |
uint64_t | toUInt (hilti::rt::ByteOrder byte_order) const |
Time | toTime (uint64_t base=10) const |
Time | toTime (hilti::rt::ByteOrder byte_order) const |
Result< Bytes > | match (const RegExp &re, unsigned int group=0) const |
Friends | |
bool | operator== (const Bytes &a, const Bytes &b) |
bool | operator!= (const Bytes &a, const Bytes &b) |
bool | operator< (const Bytes &a, const Bytes &b) |
bool | operator<= (const Bytes &a, const Bytes &b) |
bool | operator> (const Bytes &a, const Bytes &b) |
bool | operator>= (const Bytes &a, const Bytes &b) |
Bytes | operator+ (const Bytes &a, const Bytes &b) |
HILTI's Bytes
is a std::string
-like type for wrapping raw bytes with additional safety guarantees.
If not otherwise specified, member functions have the semantics of std::string
member functions.
Bytes::Bytes | ( | std::string | s, |
bytes::Charset | cs | ||
) |
Creates a bytes instance from a UTF8 string, transforming the contents into a binary representation defined by a specified character set.
s | string assumed to be in UTF8 (as all runtime strings) |
cs | character set to use for the binary encoding |
|
inline |
Appends the contents of a stream view to the data.
void Bytes::append | ( | const stream::View & | view | ) |
Appends the contents of a stream view to the data.
|
inline |
Appends a single byte the data.
|
inline |
Returns an iterator referring to the given offset.
|
inline |
Returns an iterator representing the first byte of the instance.
std::string Bytes::decode | ( | bytes::Charset | cs | ) | const |
Decodes the binary data into a string assuming its encoded in a specified character set.
cs | character set to assume the binary data to be encoded in |
|
inline |
Returns an iterator representing the end of the instance.
|
inline |
Extracts a fixed number of bytes from the data
N | number of bytes to extract |
dst | array to writes bytes into |
|
inline |
Returns the position of the first occurence of a byte.
b | byte to search |
n | optional starting point, which must be inside the same instance |
std::tuple< bool, Bytes::const_iterator > Bytes::find | ( | const Bytes & | v, |
const const_iterator & | n = const_iterator() |
||
) | const |
Returns the position of the first occurence of a range of bytes
v | bytes to search |
n | optional starting point, which must be inside the same instance |
|
inline |
Returns true if the data's size is zero.
Returns the concatenation of all elements in the parts list rendered as printable strings and separated by the bytes value providing this method.
|
inline |
Returns an upper-case version of the instance.
cs | character set for decoding/encoding |
Matchs the data against a regular expression.
re | compiled regular expression |
group | capture group to return |
|
inline |
Returns the size of instance in bytes.
Splits the data at sequences of whitespace, returning the parts.
Splits the data at occurences of a separator, returning the parts.
Splits the data (only) at the first sequence of whitespace, returning the two parts.
Splits the data (only) at the first occurance of a separator, returning the two parts.
sep | Bytes sequence to split at |
|
inline |
Returns true if the data begins with a given, other bytes instance.
|
inline |
Returns the bytes' data as a string instance.
Removes leading and/or trailing sequences of all characters of a set from the bytes instance.
side | side of bytes instance to be stripped. |
set | characters to remove; removes all whitespace if empty |
Bytes Bytes::strip | ( | bytes::Side | side = bytes::Side::Both | ) | const |
Removes leading and/or trailing sequences of white space from the bytes instance.
side | side of bytes instance to be stripped. |
|
inline |
Extracts a subrange of bytes.
from | iterator pointing to start of subrange |
to | iterator pointing to just beyond subrange |
Bytes
instance for the subrange
|
inline |
Extracts a subrange of bytes from the beginning.
to | iterator pointing to just beyond subrange |
Bytes
instance for the subrange
|
inline |
Extracts a subrange of bytes.
offset | of start of subrage |
offset | of one byeond end of subrage |
Bytes
instance for the subrange
|
inline |
Extracts a subrange of bytes from the beginning.
to | offset of one beyond end of subrange |
Bytes
instance for the subrange integer::safe< int64_t > Bytes::toInt | ( | uint64_t | base = 10 | ) | const |
Interprets the data as an ASCII representation of a signed integer and extracts that.
base | base to use for conversion |
int64_t Bytes::toInt | ( | hilti::rt::ByteOrder | byte_order | ) | const |
Interprets the data as an binary representation of a signed integer and extracts that.
byte_order | byte order that the integer is encoded in |
|
inline |
Interprets the data as an ASCII representation of a integer value representing seconds since the UNIX epoch, and extracts that.
base | base to use for conversion |
|
inline |
Interprets the data as an binary representation of a integer value representing seconds since the UNIX epoch, and extracts that.
base | base to use for conversion |
integer::safe< uint64_t > Bytes::toUInt | ( | uint64_t | base = 10 | ) | const |
Interprets the data as an ASCII representation of an unsigned integer and extracts that.
base | base to use for conversion |
uint64_t Bytes::toUInt | ( | hilti::rt::ByteOrder | byte_order | ) | const |
Interprets the data as an binary representation of an unsigned integer and extracts that.
byte_order | byte order that the integer is encoded in |
|
inline |
Returns an upper-case version of the instance. This internally first decodes the data assuming a specified character set, then encodes it back afterwards.
cs | character set for decoding/encoding |