MCPcopy Create free account
hub / github.com/bcndev/bytecoin / StringView

Class StringView

src/common/StringView.hpp:14–59  ·  view source on GitHub ↗

'StringView' is a pair of pointer to constant char and size. It is recommended to pass 'StringView' to procedures by value.

Source from the content-addressed store, hash-verified

12// 'StringView' is a pair of pointer to constant char and size.
13// It is recommended to pass 'StringView' to procedures by value.
14class StringView {
15public:
16 typedef char Char;
17 typedef size_t Size;
18
19 constexpr static Size INVALID = std::numeric_limits<Size>::max();
20
21 StringView() : m_data(nullptr), m_size(0) {}
22
23 StringView(const Char *data, Size size) : m_data(data), m_size(size) {
24 // assert(m_data != nullptr || m_size == 0);
25 }
26
27 template<Size size>
28 StringView(const Char (&data)[size]) : m_data(data), m_size(size - 1) {
29 // assert(m_data != nullptr || m_size == 0);
30 }
31
32 StringView(const std::string &string) : m_data(string.data()), m_size(string.size()) {}
33
34 explicit operator std::string() const { return std::string(m_data, m_size); }
35
36 const Char *data() const { return m_data; }
37 Size size() const { return m_size; }
38 bool empty() const { return m_size == 0; }
39
40 Char operator[](Size index) const {
41 // assert(index < m_size);
42 return *(m_data + index);
43 }
44 Char at(Size index) const;
45
46 const Char *begin() const { return m_data; }
47 const Char *end() const { return m_data + m_size; }
48
49 bool operator==(const StringView &other) const;
50 bool operator!=(const StringView &other) const { return !(*this == other); }
51 bool operator<(const StringView &other) const;
52 bool operator<=(const StringView &other) const { return !(other < *this); }
53 bool operator>(const StringView &other) const { return other < *this; }
54 bool operator>=(const StringView &other) const { return !(*this < other); }
55
56protected:
57 const Char *m_data;
58 Size m_size;
59};
60} // namespace common

Callers 5

insert_or_pushMethod · 0.85
append_prefixMethod · 0.85
begin_objectMethod · 0.85
begin_arrayMethod · 0.85
write_element_prefixMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected