1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
|
#include<iostream>
#include <map>
#include <string>
using namespace std;
namespace specialchar {
static std::map<std::string, std::string> SPECCHAR = {
{":grinning face:" , u8"\U0001F600"},
{":grinning face with big eyes:" , u8"\U0001F603"},
{":grinning face with smiling eyes:" , u8"\U0001F604"},
{":beaming face with smiling eyes:" , u8"\U0001F601"},
{":grinning squinting face:" , u8"\U0001F606"},
{":grinning face with sweat:" , u8"\U0001F605"},
{":rolling on the floor laughing:" , u8"\U0001F923"},
{":face with tears of joy:" , u8"\U0001F602"},
{":slightly smiling face:" , u8"\U0001F642"},
{":upside-down face:" , u8"\U0001F643"},
{":winking face:" , u8"\U0001F609 "},
{":smiling face with smiling eyes:" , u8"\U0001F60A "},
{":smiling face with halo:" , u8"\U0001F607"}
};
std::string specialch(std::string s, bool esc=true) {
int val = -1;
int len = s.size();
for (int i = 0; i < len; i++) {
if (s[i] == *L":") {
if(esc && i!=0 && s[i-1]=='\\')
continue;
if (val == -1) {
val = i;
}
else {
if (i - val ==1) {
val = i;
continue;
}
std::map<std::string, std::string>::iterator it;
it = SPECCHAR.find(s.substr(val, i - val + 1));
if (it == SPECCHAR.end()) {
val = i;
continue;
}
std::string spe = it->second;
std::cout << s.substr(val, i - val + 1) << std::endl;
s.replace(val, i - val + 1 , spe);
int return = i - val + 1 - spe.size();
len -= return;
i -= return;
val = -1;
}
}
}
return s;
}
}
int main() {
std::cout << specialchar::specialch("\n\n\n\nHappy for c++ :+1:") << std::endl;
return 0;
}
//Got below errors, I am not sure what went wrong here.
main.cpp:9:47: error: no matching constructor for initialization of 'std::map<std::string, std::string>' (aka 'map<basic_string<char, char_traits<char>, allocator<char>>, basic_string<char, char_traits<char>, allocator<char>>>')
static std::map<std::string, std::string> SPECCHAR = {
^ ~
/root/emsdk/upstream/emscripten/cache/sysroot/include/c++/v1/map:1052:9: note: candidate constructor template not viable: requires 4 arguments, but 13 were provided
map(_InputIterator __f, _InputIterator __l,
^
/root/emsdk/upstream/emscripten/cache/sysroot/include/c++/v1/map:1043:9: note: candidate constructor template not viable: requires at most 3 arguments, but 13 were provided
map(_InputIterator __f, _InputIterator __l,
^
/root/emsdk/upstream/emscripten/cache/sysroot/include/c++/v1/map:1062:5: note: candidate constructor template not viable: requires 3 arguments, but 13 were provided
map(_InputIterator __f, _InputIterator __l, const allocator_type& __a)
^
/root/emsdk/upstream/emscripten/cache/sysroot/include/c++/v1/map:1116:5: note: candidate constructor not viable: requires 3 arguments, but 13 were provided
map(initializer_list<value_type> __il, const key_compare& __comp, const allocator_type& __a)
^
/root/emsdk/upstream/emscripten/cache/sysroot/include/c++/v1/map:1038:14: note: candidate constructor not viable: requires 2 arguments, but 13 were provided
explicit map(const key_compare& __comp, const allocator_type& __a)
^
/root/emsdk/upstream/emscripten/cache/sysroot/include/c++/v1/map:1098:5: note: candidate constructor not viable: requires 2 arguments, but 13 were provided
map(map&& __m, const allocator_type& __a);
^
/root/emsdk/upstream/emscripten/cache/sysroot/include/c++/v1/map:1109:5: note: candidate constructor not viable: requires at most 2 arguments, but 13 were provided
map(initializer_list<value_type> __il, const key_compare& __comp = key_compare())
^
/root/emsdk/upstream/emscripten/cache/sysroot/include/c++/v1/map:1124:5: note: candidate constructor not viable: requires 2 arguments, but 13 were provided
map(initializer_list<value_type> __il, const allocator_type& __a)
^
/root/emsdk/upstream/emscripten/cache/sysroot/include/c++/v1/map:1144:5: note: candidate constructor not viable: requires 2 arguments, but 13 were provided
map(const map& __m, const allocator_type& __a)
^
/root/emsdk/upstream/emscripten/cache/sysroot/include/c++/v1/map:1031:14: note: candidate constructor not viable: requires single argument '__comp', but 13 arguments were provided
explicit map(const key_compare& __comp)
^
/root/emsdk/upstream/emscripten/cache/sysroot/include/c++/v1/map:1067:5: note: candidate constructor not viable: requires single argument '__m', but 13 arguments were provided
map(const map& __m)
^
/root/emsdk/upstream/emscripten/cache/sysroot/include/c++/v1/map:1092:5: note: candidate constructor not viable: requires single argument '__m', but 13 arguments were provided
map(map&& __m)
^
/root/emsdk/upstream/emscripten/cache/sysroot/include/c++/v1/map:1138:14: note: candidate constructor not viable: requires single argument '__a', but 13 arguments were provided
explicit map(const allocator_type& __a)
^
/root/emsdk/upstream/emscripten/cache/sysroot/include/c++/v1/map:1023:5: note: candidate constructor not viable: requires 0 arguments, but 13 were provided
map()
^
main.cpp:50:25: error: expected unqualified-id
int return = i - val + 1 - spe.size();
^
main.cpp:51:28: error: expected expression
len -= return;
^
main.cpp:52:26: error: expected expression
i -= return;
^
4 errors generated.
|