![]() |
Spicy
|
#include <bytes.h>
Public Types | |
| using | Base = std::string |
| using | const_iterator = bytes::SafeIterator |
| using | unsafe_const_iterator = bytes::detail::UnsafeConstIterator |
| using | Offset = uint64_t |
| using | size_type = integer::safe< uint64_t > |
| using | C = std::shared_ptr< const Base * > |
Public Member Functions | |
| Bytes (Base s) | |
| Bytes (const Bytes &xs) | |
| Bytes (Bytes &&xs) noexcept | |
| Bytes & | operator= (const Bytes &b) |
| Bytes & | operator= (Bytes &&b) noexcept |
| void | append (const Bytes &d) |
| void | append (const stream::View &view) |
| void | append (const uint8_t x) |
| const std::string & | str () const & |
| std::string | str () && |
| const_iterator | begin () const |
| const_iterator | cbegin () const |
| auto | unsafeBegin () const |
| const_iterator | end () const |
| const_iterator | cend () const |
| auto | unsafeEnd () const |
| const_iterator | at (Offset o) const |
| bool | isEmpty () const |
| size_type | size () const |
| const_iterator | find (value_type needle, const const_iterator &start=const_iterator()) const |
| Tuple< bool, const_iterator > | find (const Bytes &needle, const const_iterator &start=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 |
| Bytes | extract (unsigned char *dst, uint64_t n) const |
| std::string | decode (unicode::Charset cs, unicode::DecodeErrorStrategy errors=unicode::DecodeErrorStrategy::REPLACE) const |
| bool | startsWith (const Bytes &prefix) const |
| bool | endsWith (const Bytes &suffix) const |
| Bytes | upper (unicode::Charset cs, unicode::DecodeErrorStrategy errors=unicode::DecodeErrorStrategy::REPLACE) const |
| Bytes | lower (unicode::Charset cs, unicode::DecodeErrorStrategy errors=unicode::DecodeErrorStrategy::REPLACE) 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 |
| Tuple< Bytes, Bytes > | split1 () const |
| Vector< Bytes > | split (const Bytes &sep) const |
| 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 |
| integer::safe< int64_t > | toInt (hilti::rt::ByteOrder byte_order) const |
| integer::safe< uint64_t > | toUInt (hilti::rt::ByteOrder byte_order) const |
| double | toReal () 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.
|
inline |
Creates a bytes instance from a raw string representation.
|
inline |
Appends the contents of a stream view to the data.
| void hilti::rt::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.
|
inline |
Same as begin(), just for compatibility with std types.
|
inline |
Same as end(), just for compatibility with std types.
| std::string hilti::rt::Bytes::decode | ( | unicode::Charset | cs, |
| unicode::DecodeErrorStrategy | errors = unicode::DecodeErrorStrategy::REPLACE |
||
| ) | 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 |
| errors | how to handle errors when decoding the data |
|
inline |
Returns an iterator representing the end of the instance.
|
inline |
Returns true if the data begins with a given, other bytes instance.
|
inline |
Extracts a fixed number of bytes from the data
| dst | array to writes bytes into |
| n | number of bytes to extract |
| Tuple<bool, const_iterator> hilti::rt::Bytes::find | ( | const Bytes & | needle, |
| const const_iterator & | start = const_iterator() |
||
| ) | const |
Returns the position of the first occurrence of a range of bytes
| needle | bytes to search |
| start | optional starting point, which must be inside the same instance |
|
inline |
Returns the position of the first occurrence of a byte.
| needle | byte to search |
| start | 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.
| Bytes hilti::rt::Bytes::lower | ( | unicode::Charset | cs, |
| unicode::DecodeErrorStrategy | errors = unicode::DecodeErrorStrategy::REPLACE |
||
| ) | const |
Returns an upper-case version of the instance.
| cs | character set for decoding/encoding |
| errors | how to handle errors when decoding/encoding the data |
Matches 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 occurrences 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 occurrence 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.
|
inline |
Returns the bytes' data as a string instance.
| Bytes hilti::rt::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. |
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 |
|
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> hilti::rt::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 |
| integer::safe<int64_t> hilti::rt::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 |
| double hilti::rt::Bytes::toReal | ( | ) | const |
Interprets the data as an ASCII representation of a floating point value and extracts that. The data must be in a format that strtod can handle.
|
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 |
|
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 |
| integer::safe<uint64_t> hilti::rt::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 |
| integer::safe<uint64_t> hilti::rt::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 |
|
inline |
Returns an unchecked (but fast) iterator representing the first byte of the instance.
|
inline |
Returns an unchecked (but fast) iterator representing the end of the instance.
| Bytes hilti::rt::Bytes::upper | ( | unicode::Charset | cs, |
| unicode::DecodeErrorStrategy | errors = unicode::DecodeErrorStrategy::REPLACE |
||
| ) | const |
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 |
| errors | how to handle errors when decoding/encoding the data |