File tree Expand file tree Collapse file tree 2 files changed +80
-0
lines changed Expand file tree Collapse file tree 2 files changed +80
-0
lines changed Original file line number Diff line number Diff line change 1+ // SPDX-License-Identifier: Zlib
2+ // Copyright (c) 2023-2025 Julien Bernard
3+ #ifndef GF_Z_STRING_H
4+ #define GF_Z_STRING_H
5+
6+ #include < cassert>
7+
8+ #include < string>
9+ #include < string_view>
10+
11+ namespace gf {
12+
13+ class ZString {
14+ public:
15+ constexpr ZString () = default;
16+
17+ constexpr ZString (const char * string)
18+ : m_data(string)
19+ , m_size(string == nullptr ? 0 : std::char_traits<char >::length(string))
20+ {
21+ }
22+
23+ constexpr bool empty () const
24+ {
25+ return m_size == 0 ;
26+ }
27+
28+ constexpr std::size_t size () const
29+ {
30+ return m_size;
31+ }
32+
33+ constexpr const char * data () const
34+ {
35+ return m_data;
36+ }
37+
38+ constexpr const char * c_str () const
39+ {
40+ return m_data;
41+ }
42+
43+ constexpr const char * begin () const
44+ {
45+ return m_data;
46+ }
47+
48+ constexpr const char * end () const
49+ {
50+ return m_data + m_size;
51+ }
52+
53+ constexpr char operator [](std::size_t index) const
54+ {
55+ assert (index < m_size);
56+ return m_data[index];
57+ }
58+
59+ constexpr operator std::string_view () const
60+ {
61+ return { m_data, m_size };
62+ }
63+
64+ std::string to_string () const
65+ {
66+ return { m_data, m_size };
67+ }
68+
69+ private:
70+ const char * m_data = nullptr ;
71+ std::size_t m_size = 0 ;
72+ };
73+
74+ }
75+
76+ #endif // GF_Z_STRING_H
Original file line number Diff line number Diff line change 1+ // SPDX-License-Identifier: Zlib
2+ // Copyright (c) 2023-2025 Julien Bernard
3+
4+ #include < gf2/core/ZString.h>
You can’t perform that action at this time.
0 commit comments