WebCFace 2.9.0
Web-based Communication Framework & Dashboard-like UI
Loading...
Searching...
No Matches
encoding.h
Go to the documentation of this file.
1#pragma once
2#include <string>
3#include <string_view>
4#include <memory>
5#ifdef WEBCFACE_MESON
6#include "webcface-config.h"
7#else
8#include "webcface/common/webcface-config.h"
9#endif
10
12namespace internal {
13struct SharedStringData;
14} // namespace internal
15
37
42WEBCFACE_DLL std::wstring WEBCFACE_CALL toWide(std::string_view name_ref);
47WEBCFACE_DLL std::string WEBCFACE_CALL toNarrow(std::wstring_view name_ref);
48
68 std::shared_ptr<internal::SharedStringData> data;
69
70 public:
71 SharedString() : data() {}
72 SharedString(std::nullptr_t) : data() {}
73 explicit SharedString(std::shared_ptr<internal::SharedStringData> &&data);
74
75 static SharedString WEBCFACE_CALL fromU8String(std::string_view u8s);
76 static SharedString WEBCFACE_CALL encode(std::string_view s);
78 encode(std::wstring_view ws, std::string_view s = std::string_view());
79
80 const std::string &u8String() const;
81 std::string_view u8StringView() const;
82 const std::string &decode() const;
83 const std::wstring &decodeW() const;
84
85 static const std::string &emptyStr();
86 static const std::wstring &emptyStrW();
87
88 bool empty() const;
89 bool startsWith(std::string_view str) const;
90 bool startsWith(char str) const;
91 SharedString substr(std::size_t pos,
92 std::size_t len = std::string::npos) const;
93 std::size_t find(char c, std::size_t pos = 0) const;
94
95 bool operator==(const SharedString &other) const;
96 bool operator<=(const SharedString &other) const;
97 bool operator>=(const SharedString &other) const;
98 bool operator!=(const SharedString &other) const;
99 bool operator<(const SharedString &other) const;
100 bool operator>(const SharedString &other) const;
101
102 struct Hash : std::hash<std::string> {
103 Hash() = default;
104 auto operator()(const SharedString &ss) const {
105 return this->std::hash<std::string>::operator()(ss.u8String());
106 }
107 };
108};
109
110namespace [[deprecated("symbols in webcface::encoding namespace are "
111 "now directly in webcface namespace")]] encoding {
112inline bool usingUTF8() { return webcface::usingUTF8(); }
113inline void usingUTF8(bool flag) { webcface::usingUTF8(flag); }
114inline std::wstring toWide(std::string_view name_ref) {
115 return webcface::toWide(name_ref);
116}
117inline std::string toNarrow(std::wstring_view name) {
118 return webcface::toNarrow(name);
119}
120
122
123} // namespace encoding
124
u8stringとstringとwstringをshared_ptrで持ち共有する
Definition encoding.h:67
const std::string & u8String() const
Definition encoding.cc:104
SharedString()
Definition encoding.h:71
SharedString(std::nullptr_t)
Definition encoding.h:72
std::string toNarrow(std::wstring_view name_ref)
wstringをstringに変換する
Definition encoding.cc:140
void usingUTF8(bool flag)
webcfaceが使用するエンコーディングを設定する
Definition encoding.cc:30
bool operator==(const T &other, const InputRef &ref)
Definition text.h:574
std::wstring toWide(std::string_view name_ref)
stringをwstringに変換する
Definition encoding.cc:194
bool usingUTF8()
webcfaceが使用するエンコーディングを取得する
Definition encoding.cc:31
bool operator!=(const T &other, const InputRef &ref)
Definition text.h:580
Definition encoding.h:102
auto operator()(const SharedString &ss) const
Definition encoding.h:104
#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