1 #ifndef _C4_STD_STRING_VIEW_HPP_
2 #define _C4_STD_STRING_VIEW_HPP_
6 #ifndef C4CORE_SINGLE_HEADER
7 #include "c4/language.hpp"
10 #if (C4_CPP >= 17 && defined(__cpp_lib_string_view)) || defined(__DOXYGEN__)
12 #ifndef C4CORE_SINGLE_HEADER
16 #include <string_view>
22 template<
class T>
struct is_string;
23 template<>
struct is_string<std::string_view> :
public std::true_type {};
29 C4_ALWAYS_INLINE c4::csubstr
to_csubstr(std::string_view s) noexcept
31 return c4::csubstr(s.data(), s.size());
37 C4_ALWAYS_INLINE
bool operator== (c4::csubstr ss, std::string_view s) {
return ss.compare(s.data(), s.size()) == 0; }
38 C4_ALWAYS_INLINE
bool operator!= (c4::csubstr ss, std::string_view s) {
return ss.compare(s.data(), s.size()) != 0; }
39 C4_ALWAYS_INLINE
bool operator>= (c4::csubstr ss, std::string_view s) {
return ss.compare(s.data(), s.size()) >= 0; }
40 C4_ALWAYS_INLINE
bool operator> (c4::csubstr ss, std::string_view s) {
return ss.compare(s.data(), s.size()) > 0; }
41 C4_ALWAYS_INLINE
bool operator<= (c4::csubstr ss, std::string_view s) {
return ss.compare(s.data(), s.size()) <= 0; }
42 C4_ALWAYS_INLINE
bool operator< (c4::csubstr ss, std::string_view s) {
return ss.compare(s.data(), s.size()) < 0; }
44 C4_ALWAYS_INLINE
bool operator== (std::string_view s, c4::csubstr ss) {
return ss.compare(s.data(), s.size()) == 0; }
45 C4_ALWAYS_INLINE
bool operator!= (std::string_view s, c4::csubstr ss) {
return ss.compare(s.data(), s.size()) != 0; }
46 C4_ALWAYS_INLINE
bool operator<= (std::string_view s, c4::csubstr ss) {
return ss.compare(s.data(), s.size()) >= 0; }
47 C4_ALWAYS_INLINE
bool operator< (std::string_view s, c4::csubstr ss) {
return ss.compare(s.data(), s.size()) > 0; }
48 C4_ALWAYS_INLINE
bool operator>= (std::string_view s, c4::csubstr ss) {
return ss.compare(s.data(), s.size()) <= 0; }
49 C4_ALWAYS_INLINE
bool operator> (std::string_view s, c4::csubstr ss) {
return ss.compare(s.data(), s.size()) < 0; }
55 inline size_t to_chars(c4::substr buf, std::string_view s)
58 size_t len = buf.len < sz ? buf.len : sz;
59 buf.copy_from(csubstr(s.data(), len));
csubstr to_csubstr(substr s) noexcept
neutral version for use in generic code
bool operator!=(const char(&s)[N], basic_substring< C > const that) noexcept
bool operator>(const char(&s)[N], basic_substring< C > const that) noexcept
bool operator>=(const char(&s)[N], basic_substring< C > const that) noexcept
bool operator<=(const char(&s)[N], basic_substring< C > const that) noexcept
bool operator==(const char(&s)[N], basic_substring< C > const that) noexcept
bool operator<(const char(&s)[N], basic_substring< C > const that) noexcept
size_t to_chars(substr buf, uint8_t v) noexcept
(Undefined by default) Use shorter error message from checks/asserts: do not show the check condition...
a traits class to mark a type as a string type (meaning c4::to_csubstr() can be used directly).