xtd - Reference Guide  0.1.0
Modern c++17/20 framework to create console, GUI and unit test applications on Windows, macOS, Linux, iOS and android.
Loading...
Searching...
No Matches
emoticon.h
Go to the documentation of this file.
1
4#pragma once
5#include "../forms_export.h"
6#include <xtd/object.h>
7#include <xtd/static.h>
8#include <xtd/ustring.h>
9#include <ostream>
10#include <vector>
11
13namespace xtd {
15 namespace forms {
25 class forms_export_ emoticon : public object {
26 public:
28 static const emoticon empty();
29
33 emoticon(const xtd::ustring& name, std::initializer_list<char32_t> codepoints) : name_(name), codepoints_(codepoints) {}
34
38 emoticon(const xtd::ustring& name, const std::vector<char32_t>& codepoints) : name_(name), codepoints_(codepoints) {}
39
43 emoticon(const xtd::ustring& name, char32_t codepoint) : name_(name), codepoints_({codepoint}) {}
44
47 emoticon(std::initializer_list<char32_t> codepoints) : codepoints_(codepoints) {}
48
51 emoticon(const std::vector<char32_t>& codepoints) : codepoints_(codepoints) {}
52
55 emoticon(char32_t codepoint) : codepoints_({codepoint}) {}
56
58 template<typename type_t>
59 emoticon(const xtd::ustring& name, std::initializer_list<type_t> codepoints) : name_(name) {
60 for(auto codepoint : codepoints)
61 codepoints_.push_back(static_cast<char32_t>(codepoint));
62 }
63
64 template<typename type_t>
65 emoticon(const xtd::ustring& name, const std::vector<type_t>& codepoints) : name_(name) {
66 for(auto codepoint : codepoints)
67 codepoints_.push_back(static_cast<char32_t>(codepoint));
68 }
69
70 template<typename type_t>
71 emoticon(const xtd::ustring& name, type_t codepoint) : name_(name), codepoints_({static_cast<char32_t>(codepoint)}) {}
72
73 template<typename type_t>
74 emoticon(std::initializer_list<type_t> codepoints) {
75 for(auto codepoint : codepoints)
76 codepoints_.push_back(static_cast<char32_t>(codepoint));
77 }
78
79 template<typename type_t>
80 emoticon(const std::vector<type_t>& codepoints) {
81 for(auto codepoint : codepoints)
82 codepoints_.push_back(static_cast<char32_t>(codepoint));
83 }
84
85 template<typename type_t>
86 emoticon(type_t codepoint) : codepoints_({static_cast<char32_t>(codepoint)}) {}
87
88 emoticon() = default;
89 emoticon(const emoticon&) = default;
90 emoticon& operator=(const emoticon&) = default;
91 bool operator==(const emoticon& value) {return name_ == value.name_ && codepoints_ == value.codepoints_;}
92 bool operator!=(const emoticon& value) {return !operator==(value);}
93 friend std::ostream& operator<<(std::ostream& os, const xtd::forms::emoticon& emoticon) noexcept {
94 return os << emoticon.to_string();
95 }
97
100 const xtd::ustring& name() const {return name_;}
101
104 const std::vector<char32_t>& codepoints() const {return codepoints_;}
105
108 xtd::ustring to_string() const noexcept override {
109 std::string result;
110 for (auto codepoint : codepoints_) {
111 if (codepoint < 0x80) {
112 result.push_back(static_cast<char>(codepoint));
113 } else if (codepoint < 0x800) {
114 result.push_back(static_cast<char>((codepoint >> 6) | 0xc0));
115 result.push_back(static_cast<char>((codepoint & 0x3f) | 0x80));
116 } else if (codepoint < 0x10000) {
117 result.push_back(static_cast<char>((codepoint >> 12) | 0xe0));
118 result.push_back(static_cast<char>(((codepoint >> 6) & 0x3f) | 0x80));
119 result.push_back(static_cast<char>((codepoint & 0x3f) | 0x80));
120 } else {
121 result.push_back(static_cast<char>((codepoint >> 18) | 0xf0));
122 result.push_back(static_cast<char>(((codepoint >> 12) & 0x3f) | 0x80));
123 result.push_back(static_cast<char>(((codepoint >> 6) & 0x3f) | 0x80));
124 result.push_back(static_cast<char>((codepoint & 0x3f) | 0x80));
125 }
126 }
127 return result;
128 }
129
130 private:
131 xtd::ustring name_;
132 std::vector<char32_t> codepoints_;
133 };
134 }
135}
136
138inline xtd::ustring operator+(const xtd::forms::emoticon& value_a, const xtd::forms::emoticon& value_b) {
139 return value_a.to_string() + value_b.to_string();
140}
141
142inline xtd::ustring operator+(const xtd::forms::emoticon& value_a, const char* value_b) {
143 return value_a.to_string() + value_b;
144}
145
146inline xtd::ustring operator+(const xtd::forms::emoticon& value_a, const xtd::ustring& value_b) {
147 return value_a.to_string() + value_b;
148}
149
150inline xtd::ustring operator+(const xtd::ustring& value_a, const xtd::forms::emoticon& value_b) {
151 return value_a + value_b.to_string();
152}
153
154inline xtd::ustring operator+(const char* value_a, const xtd::forms::emoticon& value_b) {
155 return xtd::ustring(value_a) + value_b.to_string();
156}
Represent a emoticon with name and codepoints.
Definition: emoticon.h:25
const std::vector< char32_t > & codepoints() const
Gets codepoints of emoticon.
Definition: emoticon.h:104
emoticon(const xtd::ustring &name, char32_t codepoint)
Initialize a new instance of emoticon class with specified name and codepoint.
Definition: emoticon.h:43
static const emoticon empty()
Represents an empty emoticon.
emoticon(const std::vector< char32_t > &codepoints)
Initialize a new instance of emoticon class with specified codepoints.
Definition: emoticon.h:51
emoticon(char32_t codepoint)
Initialize a new instance of emoticon class with specified codepoint.
Definition: emoticon.h:55
const xtd::ustring & name() const
Gets name of emoticon.
Definition: emoticon.h:100
emoticon(const xtd::ustring &name, std::initializer_list< char32_t > codepoints)
Initialize a new instance of emoticon class with specified name and codepoints.
Definition: emoticon.h:33
emoticon(const xtd::ustring &name, const std::vector< char32_t > &codepoints)
Initialize a new instance of emoticon class with specified name and codepoints.
Definition: emoticon.h:38
emoticon(std::initializer_list< char32_t > codepoints)
Initialize a new instance of emoticon class with specified codepoints.
Definition: emoticon.h:47
xtd::ustring to_string() const noexcept override
Returns a string containing the codepoints of the emoticons.
Definition: emoticon.h:108
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes....
Definition: object.h:26
Represents text as a sequence of UTF-8 code units.
Definition: ustring.h:48
#define forms_export_
Define shared library export.
Definition: forms_export.h:13
The xtd::forms namespace contains classes for creating Windows-based applications that take full adva...
Definition: about_box.h:13
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition: system_report.h:17
Contains xtd::object class.
Contains xtd::static_object class.
Contains xtd::ustring class.