xtd - Reference Guide  0.2.0
Modern c++17/20 framework to create console, GUI and unit test applications on Windows, macOS, Linux, iOS and android.
emoticon.h
Go to the documentation of this file.
1 #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 
13 namespace 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 
138 inline 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 
142 inline xtd::ustring operator+(const xtd::forms::emoticon& value_a, const char* value_b) {
143  return value_a.to_string() + value_b;
144 }
145 
146 inline xtd::ustring operator+(const xtd::forms::emoticon& value_a, const xtd::ustring& value_b) {
147  return value_a.to_string() + value_b;
148 }
149 
150 inline xtd::ustring operator+(const xtd::ustring& value_a, const xtd::forms::emoticon& value_b) {
151  return value_a + value_b.to_string();
152 }
153 
154 inline xtd::ustring operator+(const char* value_a, const xtd::forms::emoticon& value_b) {
155  return xtd::ustring(value_a) + value_b.to_string();
156 }
emoticon(const xtd::ustring &name, char32_t codepoint)
Initialize a new instance of emoticon class with specified name and codepoint.
Definition: emoticon.h:43
Contains xtd::static_object class.
emoticon(char32_t codepoint)
Initialize a new instance of emoticon class with specified codepoint.
Definition: emoticon.h:55
const std::vector< char32_t > & codepoints() const
Gets codepoints of emoticon.
Definition: emoticon.h:104
The xtd namespace contains all fundamental classes to access Hardware, Os, System, and more.
Definition: system_report.h:17
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(const std::vector< char32_t > &codepoints)
Initialize a new instance of emoticon class with specified codepoints.
Definition: emoticon.h:51
Represents text as a sequence of UTF-8 code units.
Definition: ustring.h:48
xtd::ustring to_string() const noexcept override
Returns a string containing the codepoints of the emoticons.
Definition: emoticon.h:108
emoticon(std::initializer_list< char32_t > codepoints)
Initialize a new instance of emoticon class with specified codepoints.
Definition: emoticon.h:47
Contains xtd::ustring class.
Contains xtd::object class.
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes...
Definition: object.h:27
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
The xtd::forms namespace contains classes for creating Windows-based applications that take full adva...
Definition: about_box.h:13
const xtd::ustring & name() const
Gets name of emoticon.
Definition: emoticon.h:100
Represent a emoticon with name and codepoints.
Definition: emoticon.h:25