8#include "webcface/common/webcface-config.h"
13struct SharedStringData;
59template <
typename CharT>
61 std::shared_ptr<const internal::SharedStringData> s_data;
63 static inline CharT empty_buf[1] = {0};
66 TStringView() : std::basic_string_view<CharT>(empty_buf, 0) {}
69 std::shared_ptr<const internal::SharedStringData> s_data)
70 : std::basic_string_view<CharT>(data, size), s_data(std::move(s_data)) {
76 const CharT *
c_str()
const {
return this->data(); }
78 operator const CharT *()
const {
return this->data(); }
82 std::is_convertible_v<T, std::basic_string_view<CharT>>,
83 std::nullptr_t> =
nullptr>
85 return static_cast<std::basic_string_view<CharT>
>(*this) ==
86 std::basic_string_view<CharT>(other);
90 std::is_convertible_v<T, std::basic_string_view<CharT>>,
91 std::nullptr_t> =
nullptr>
93 return static_cast<std::basic_string_view<CharT>
>(*this) !=
94 std::basic_string_view<CharT>(other);
98 std::is_convertible_v<T, std::basic_string_view<CharT>>,
99 std::nullptr_t> =
nullptr>
101 return static_cast<std::basic_string_view<CharT>
>(*this) <=
102 std::basic_string_view<CharT>(other);
104 template <
typename T,
106 std::is_convertible_v<T, std::basic_string_view<CharT>>,
107 std::nullptr_t> =
nullptr>
109 return static_cast<std::basic_string_view<CharT>
>(*this) >=
110 std::basic_string_view<CharT>(other);
112 template <
typename T,
114 std::is_convertible_v<T, std::basic_string_view<CharT>>,
115 std::nullptr_t> =
nullptr>
117 return static_cast<std::basic_string_view<CharT>
>(*this) <
118 std::basic_string_view<CharT>(other);
120 template <
typename T,
122 std::is_convertible_v<T, std::basic_string_view<CharT>>,
123 std::nullptr_t> =
nullptr>
125 return static_cast<std::basic_string_view<CharT>
>(*this) >
126 std::basic_string_view<CharT>(other);
160 std::shared_ptr<internal::SharedStringData> data;
165 explicit SharedString(std::shared_ptr<internal::SharedStringData> data);
174 std::string_view u8StringView()
const;
176 std::string_view decode()
const;
178 std::wstring_view decodeW()
const;
181 static const std::string &emptyStr();
182 static const std::wstring &emptyStrW();
185 bool startsWith(std::string_view str)
const;
186 bool startsWith(
char str)
const;
188 std::size_t len = std::string::npos)
const;
189 std::size_t find(
char c, std::size_t pos = 0)
const;
195 return !(*
this == other);
198 return !(*
this >= other);
201 return !(*
this <= other);
224 template <
typename T,
225 typename std::enable_if_t<
226 std::conjunction_v<std::negation<std::is_void<T>>,
227 std::is_constructible<std::string, T>>,
228 std::nullptr_t> =
nullptr>
231 template <
typename T,
232 typename std::enable_if_t<
234 std::negation<std::is_void<T>>,
235 std::negation<std::is_constructible<std::string, T>>,
236 std::is_constructible<std::wstring, T>>,
237 std::nullptr_t> =
nullptr>
241 template <std::
size_t N>
244 SharedString::encodeStatic(std::string_view(static_str, N - 1))) {
246 template <std::
size_t N>
249 std::wstring_view(static_str, N - 1))) {}
260template <
typename CharT,
typename... Args>
261std::basic_string<CharT>
strJoin(std::basic_string_view<CharT> first_str,
263 std::basic_string<CharT> str;
264 str.reserve(first_str.size() +
265 (std::basic_string_view<CharT>(args).size() + ...));
266 str.append(first_str);
267 (str.append(std::basic_string_view<CharT>(args)), ...);
271namespace [[deprecated(
"symbols in webcface::encoding namespace are "
272 "now directly in webcface namespace")]] encoding {
275inline std::wstring
toWide(std::string_view name_ref) {
278inline std::string
toNarrow(std::wstring_view name) {
u8stringとstringとwstringをshared_ptrで持ち共有する
Definition encoding.h:159
bool operator!=(const SharedString &other) const
Definition encoding.h:194
bool operator<(const SharedString &other) const
Definition encoding.h:197
SharedString()
Definition encoding.h:163
SharedString(std::nullptr_t)
Definition encoding.h:164
bool operator>(const SharedString &other) const
Definition encoding.h:200
SharedString のpublicなコンストラクタインタフェース (入力専用)
Definition encoding.h:215
StringInitializer(const wchar_t(&static_str)[N])
Definition encoding.h:247
StringInitializer(const char(&static_str)[N])
Definition encoding.h:242
StringInitializer(const T &s)
Definition encoding.h:229
StringInitializer(std::wstring &&s)
Definition encoding.h:221
StringInitializer()
Definition encoding.h:217
StringInitializer(std::string &&s)
Definition encoding.h:219
webcfaceで管理されている文字列を参照するstring_view
Definition encoding.h:60
bool operator==(const T &other) const
Definition encoding.h:84
bool operator!=(const T &other) const
Definition encoding.h:92
bool operator>(const T &other) const
Definition encoding.h:124
bool operator<=(const T &other) const
Definition encoding.h:100
TStringView(const CharT *data, std::size_t size, std::shared_ptr< const internal::SharedStringData > s_data)
Definition encoding.h:68
const CharT * c_str() const
null終端の文字列ポインタを返す
Definition encoding.h:76
bool operator<(const T &other) const
Definition encoding.h:116
TStringView()
Definition encoding.h:66
bool operator>=(const T &other) const
Definition encoding.h:108
std::string toNarrow(std::wstring_view name_ref)
wstringをstringに変換する
Definition encoding.cc:256
std::basic_string< CharT > strJoin(std::basic_string_view< CharT > first_str, Args &&...args)
string_viewやconst char*同士を連結しstringを返す
Definition encoding.h:261
void usingUTF8(bool flag)
webcfaceが使用するエンコーディングを設定する
Definition encoding.cc:51
bool operator==(const T &other, const InputRef &ref)
Definition text.h:641
std::wstring toWide(std::string_view name_ref)
stringをwstringに変換する
Definition encoding.cc:341
bool usingUTF8()
webcfaceが使用するエンコーディングを取得する
Definition encoding.cc:52
#define WEBCFACE_DLL
Definition webcface-config.h:69
#define WEBCFACE_CALL
Definition webcface-config.h:106
#define WEBCFACE_NS_END
Definition webcface-config.h:118
#define WEBCFACE_NS_BEGIN
Definition webcface-config.h:117