WebCFace 2.5.2
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 <map>
3#include <set>
4#include <string>
5#include <string_view>
6#include <memory>
7#ifdef WEBCFACE_MESON
8#include "webcface-config.h"
9#else
10#include "webcface/common/webcface-config.h"
11#endif
12
14namespace internal {
15struct SharedStringData;
16} // namespace internal
17
39
44WEBCFACE_DLL std::wstring WEBCFACE_CALL toWide(std::string_view name_ref);
49WEBCFACE_DLL std::string WEBCFACE_CALL toNarrow(std::wstring_view name_ref);
50
70 std::shared_ptr<internal::SharedStringData> data;
71
72 public:
73 SharedString() : data() {}
74 SharedString(std::nullptr_t) : data() {}
75 explicit SharedString(std::shared_ptr<internal::SharedStringData> &&data);
76
77 static SharedString WEBCFACE_CALL fromU8String(std::string_view u8s);
78 static SharedString WEBCFACE_CALL encode(std::string_view s);
80 encode(std::wstring_view ws, std::string_view s = std::string_view());
81
82 const std::string &u8String() const;
83 std::string_view u8StringView() const;
84 const std::string &decode() const;
85 const std::wstring &decodeW() const;
86
87 static const std::string &emptyStr();
88 static const std::wstring &emptyStrW();
89
90 bool empty() const;
91 bool startsWith(std::string_view str) const;
92 bool startsWith(char str) const;
93
94 bool operator==(const SharedString &other) const;
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
101 struct Hash : std::hash<std::string> {
102 Hash() = default;
103 auto operator()(const SharedString &ss) const {
104 return this->std::hash<std::string>::operator()(ss.u8String());
105 }
106 };
107};
108
109template <typename T>
110using StrMap1 = std::map<SharedString, T>;
111template <typename T>
113using StrSet1 = std::set<SharedString>;
115
116namespace [[deprecated("symbols in webcface::encoding namespace are "
117 "now directly in webcface namespace")]] encoding {
118inline bool usingUTF8() { return webcface::usingUTF8(); }
119inline void usingUTF8(bool flag) { webcface::usingUTF8(flag); }
120inline std::wstring toWide(std::string_view name_ref) {
121 return webcface::toWide(name_ref);
122}
123inline std::string toNarrow(std::wstring_view name) {
124 return webcface::toNarrow(name);
125}
126
128
129template <typename T>
131template <typename T>
135
136} // namespace encoding
137
u8stringとstringとwstringをshared_ptrで持ち共有する
Definition encoding.h:69
const std::string & u8String() const
Definition encoding.cc:104
SharedString()
Definition encoding.h:73
SharedString(std::nullptr_t)
Definition encoding.h:74
webcface::StrMap2< T > StrMap2
Definition encoding.h:132
webcface::StrSet2 StrSet2
Definition encoding.h:134
webcface::StrMap1< T > StrMap1
Definition encoding.h:130
webcface::StrSet1 StrSet1
Definition encoding.h:133
std::string toNarrow(std::wstring_view name_ref)
wstringをstringに変換する
Definition encoding.cc:126
void usingUTF8(bool flag)
webcfaceが使用するエンコーディングを設定する
Definition encoding.cc:30
bool operator==(const T &other, const InputRef &ref)
Definition text.h:566
std::wstring toWide(std::string_view name_ref)
stringをwstringに変換する
Definition encoding.cc:180
std::map< SharedString, T > StrMap1
Definition encoding.h:110
StrMap1< StrSet1 > StrSet2
Definition encoding.h:114
StrMap1< StrMap1< T > > StrMap2
Definition encoding.h:112
std::set< SharedString > StrSet1
Definition encoding.h:113
bool usingUTF8()
webcfaceが使用するエンコーディングを取得する
Definition encoding.cc:31
bool operator!=(const T &other, const InputRef &ref)
Definition text.h:572
Definition encoding.h:101
auto operator()(const SharedString &ss) const
Definition encoding.h:103
#define WEBCFACE_DLL
Definition webcface-config.h:60
#define WEBCFACE_CALL
Definition webcface-config.h:97
#define WEBCFACE_NS_END
Definition webcface-config.h:104
#define WEBCFACE_NS_BEGIN
Definition webcface-config.h:103