13 #ifndef OGLPLUS_STRING_REF_TPL_1107121519_HPP
14 #define OGLPLUS_STRING_REF_TPL_1107121519_HPP
16 #include <oglplus/string/utf8.hpp>
17 #include <oglplus/config/compiler.hpp>
28 template <
typename Char,
typename Left,
typename Right>
40 bool empty(
void)
const
42 return _left.empty() && _right.empty();
45 std::size_t size(
void)
const
47 return _left.size() + _right.size();
50 void append_to(std::basic_string<Char>& dest)
const
52 _left.append_to(dest);
53 _right.append_to(dest);
56 std::basic_string<Char> str(
void)
const
58 std::basic_string<Char> result;
59 result.reserve(this->size()+1);
60 this->append_to(result);
64 OGLPLUS_EXPLICIT
operator std::basic_string<Char>(void)
const
71 template <
typename Char>
76 sizeof(Char) ==
sizeof(
char),
77 "Characters with different size that sizeof(char) "
78 "are not supported by StrCRefTpl"
82 mutable std::size_t _size;
84 static const Char* _ecs(
void)
85 OGLPLUS_NOEXCEPT(
true)
88 void _validate(
void)
const
89 OGLPLUS_NOEXCEPT(
true)
91 assert(aux::ValidUTF8(
99 OGLPLUS_NOEXCEPT(true)
106 OGLPLUS_NOEXCEPT(
true)
113 OGLPLUS_NOEXCEPT(
true)
119 template <std::
size_t N>
121 OGLPLUS_NOEXCEPT(
true)
128 OGLPLUS_NOEXCEPT(
true)
129 : _c_str(sstr.
c_str())
135 OGLPLUS_NOEXCEPT(
true)
136 : _c_str(cvec.data())
141 template <std::
size_t N>
143 OGLPLUS_NOEXCEPT(
true)
144 : _c_str(cvec.data())
150 OGLPLUS_NOEXCEPT(true)
152 if((_size == 0) && (_c_str !=
nullptr))
153 _size = std::strlen(_c_str);
159 OGLPLUS_NOEXCEPT(true)
171 OGLPLUS_NOEXCEPT(true)
173 return _c_str?_c_str:_ecs();
178 OGLPLUS_NOEXCEPT(true)
185 OGLPLUS_NOEXCEPT(true)
187 return *
end() ==
'\0';
191 std::basic_string<Char>
str(
void)
const
193 return std::basic_string<Char>(
begin(),
end());
201 OGLPLUS_NOEXCEPT(true)
213 static bool Equal(
const StrCRefTpl& a,
const Char* b)
215 if(a.is_nts())
return std::strcmp(a.c_str(), b) == 0;
217 std::size_t
size = std::strlen(b);
218 return (a.size() ==
size) &&
219 (std::strncmp(a.begin(), b, a.size()) == 0);
224 return StrCRefTpl::Equal(a, b);
227 friend bool operator == (
const StrCRefTpl& a,
const Char* b)
229 return StrCRefTpl::Equal(a, b);
232 friend bool operator == (
const Char* a,
const StrCRefTpl& b)
234 return StrCRefTpl::Equal(b, a);
239 return !StrCRefTpl::Equal(a, b);
242 friend bool operator != (
const StrCRefTpl& a,
const Char* b)
244 return !StrCRefTpl::Equal(a, b);
247 friend bool operator != (
const Char* a,
const StrCRefTpl& b)
249 return !StrCRefTpl::Equal(b, a);
253 template <
typename Char>
255 StrCRefChainTpl<Char, StrCRefTpl<Char>, StrCRefTpl<Char>>
256 operator + (StrCRefTpl<Char> left, StrCRefTpl<Char> right)
258 return StrCRefChainTpl<Char, StrCRefTpl<Char>, StrCRefTpl<Char>>(
264 template <
typename Char,
typename Left,
typename Right>
266 StrCRefChainTpl<Char, StrCRefChainTpl<Char, Left, Right>, StrCRefTpl<Char> >
267 operator + (StrCRefChainTpl<Char, Left, Right> left, StrCRefTpl<Char> right)
269 return StrCRefChainTpl<
271 StrCRefChainTpl<Char,Left,Right>,
278 #endif // include guard
const Char * c_str(void) const
Returns the null-terminated c-string.
Definition: ref_tpl.hpp:200
StrCRefTpl(const Char *cstr, std::size_t ssize)
Construction from a c-string and size.
Definition: ref_tpl.hpp:112
const_iterator end(void) const
Returns iterator past the last character.
Definition: ref_tpl.hpp:177
StrCRefTpl(const Char *cstr)
Construction from a null-terminated string.
Definition: ref_tpl.hpp:105
StrCRefTpl(void)
Default construction (reference to an empty c-string)
Definition: ref_tpl.hpp:98
const_iterator begin(void) const
Returns iterator to the first character.
Definition: ref_tpl.hpp:170
StrCRefTpl(const std::vector< Char > &cvec)
Construction from a std::vector<Char>
Definition: ref_tpl.hpp:134
std::basic_string< Char > str(void) const
Returns a String.
Definition: ref_tpl.hpp:191
StrCRefTpl(const std::array< Char, N > &cvec)
Construction from a std::array<Char, N>
Definition: ref_tpl.hpp:142
std::size_t size(void) const
Return the size (length) string.
Definition: ref_tpl.hpp:149
String const reference wrapper template.
Definition: ref_tpl.hpp:72
StrCRefTpl(const std::basic_string< Char > &sstr)
Construction from a std::basic_string<Char>
Definition: ref_tpl.hpp:127
bool empty(void) const
Returns true if the string is empty.
Definition: ref_tpl.hpp:158
iterator const_iterator
Const iterator type.
Definition: ref_tpl.hpp:167
bool is_nts(void) const
Returns true if the string is null-terminated.
Definition: ref_tpl.hpp:184
StrCRefTpl(const Char(&cary)[N])
Construction from a character array with known size.
Definition: ref_tpl.hpp:120
const Char * iterator
Iterator type.
Definition: ref_tpl.hpp:165