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.
emoticon.h
1 #pragma once
2 #include "component.h"
3 #include <xtd/static.h>
4 #include <ostream>
5 #include <string>
6 #include <vector>
7 
9 namespace xtd {
11  namespace forms {
12  class forms_export_ emoticon : public component {
13  public:
14  static const emoticon empty();
15 
16  emoticon(const std::string& name, std::initializer_list<char32_t> codepoints) : name_(name), codepoints_(codepoints) {}
17 
18  emoticon(const std::string& name, const std::vector<char32_t>& codepoints) : name_(name), codepoints_(codepoints) {}
19 
20  emoticon(const std::string& name, char32_t codepoint) : name_(name), codepoints_({codepoint}) {}
21 
22  emoticon(std::initializer_list<char32_t> codepoints) : codepoints_(codepoints) {}
23 
24  emoticon(const std::vector<char32_t>& codepoints) : codepoints_(codepoints) {}
25 
26  emoticon(char32_t codepoint) : codepoints_({codepoint}) {}
27 
28  template<typename type_t>
29  emoticon(const std::string& name, std::initializer_list<type_t> codepoints) : name_(name) {
30  for(auto codepoint : codepoints)
31  codepoints_.push_back(static_cast<char32_t>(codepoint));
32  }
33 
34  template<typename type_t>
35  emoticon(const std::string& name, const std::vector<type_t>& codepoints) : name_(name) {
36  for(auto codepoint : codepoints)
37  codepoints_.push_back(static_cast<char32_t>(codepoint));
38  }
39 
40  template<typename type_t>
41  emoticon(const std::string& name, type_t codepoint) : name_(name), codepoints_({static_cast<char32_t>(codepoint)}) {}
42 
43  template<typename type_t>
44  emoticon(std::initializer_list<type_t> codepoints) {
45  for(auto codepoint : codepoints)
46  codepoints_.push_back(static_cast<char32_t>(codepoint));
47  }
48 
49  template<typename type_t>
50  emoticon(const std::vector<type_t>& codepoints) {
51  for(auto codepoint : codepoints)
52  codepoints_.push_back(static_cast<char32_t>(codepoint));
53  }
54 
55  template<typename type_t>
56  emoticon(type_t codepoint) : codepoints_({static_cast<char32_t>(codepoint)}) {}
57 
59  emoticon() = default;
60  emoticon(const emoticon&) = default;
61  emoticon& operator=(const emoticon&) = default;
62  bool operator==(const emoticon& value) {return name_ == value.name_ && codepoints_ == value.codepoints_;}
63  bool operator!=(const emoticon& value) {return !operator==(value);}
64  friend std::ostream& operator<<(std::ostream& os, const xtd::forms::emoticon& emoticon) noexcept {
65  return os << emoticon.to_string();
66  }
68 
69  const std::string& name() const {return name_;}
70 
71  const std::vector<char32_t>& codepoints() const {return codepoints_;}
72 
73  std::string to_string() const {
74  std::string result;
75  for (auto codepoint : codepoints_) {
76  if (codepoint < 0x80) {
77  result.push_back(static_cast<char>(codepoint));
78  } else if (codepoint < 0x800) {
79  result.push_back(static_cast<char>((codepoint >> 6) | 0xc0));
80  result.push_back(static_cast<char>((codepoint & 0x3f) | 0x80));
81  } else if (codepoint < 0x10000) {
82  result.push_back(static_cast<char>((codepoint >> 12) | 0xe0));
83  result.push_back(static_cast<char>(((codepoint >> 6) & 0x3f) | 0x80));
84  result.push_back(static_cast<char>((codepoint & 0x3f) | 0x80));
85  } else {
86  result.push_back(static_cast<char>((codepoint >> 18) | 0xf0));
87  result.push_back(static_cast<char>(((codepoint >> 12) & 0x3f) | 0x80));
88  result.push_back(static_cast<char>(((codepoint >> 6) & 0x3f) | 0x80));
89  result.push_back(static_cast<char>((codepoint & 0x3f) | 0x80));
90  }
91  }
92  return result;
93  }
94 
95  private:
96  std::string name_;
97  std::vector<char32_t> codepoints_;
98  };
99  }
100 }
101 
103 inline std::string operator+(const xtd::forms::emoticon& value_a, const xtd::forms::emoticon& value_b) {
104  return value_a.to_string() + value_b.to_string();
105 }
106 
107 inline std::string operator+(const xtd::forms::emoticon& value_a, const char* value_b) {
108  return value_a.to_string() + value_b;
109 }
110 
111 inline std::string operator+(const xtd::forms::emoticon& value_a, const std::string& value_b) {
112  return value_a.to_string() + value_b;
113 }
114 
115 inline std::string operator+(const std::string& value_a, const xtd::forms::emoticon& value_b) {
116  return value_a + value_b.to_string();
117 }
118 
119 inline std::string operator+(const char* value_a, const xtd::forms::emoticon& value_b) {
120  return value_a + value_b.to_string();
121 }
The xtd namespace contains all fundamental classes to access Hardware, Os, System, and more.
Definition: system_report.h:15
Definition: emoticon.h:12
Provides the base implementation and enables object sharing between applications. ...
Definition: component.h:11