util.cc (796B)
1 #include "util.hh" 2 3 #include <QString> 4 #include <QUrl> 5 6 #include <vector> 7 #include <string> 8 9 char* 10 convert_new(const std::string& s) 11 { 12 char* raw = new char[s.size() + 1]; 13 std::strcpy(raw, s.c_str()); 14 return raw; 15 } 16 17 const char* 18 convert(const std::string& s) 19 { 20 return s.c_str(); 21 } 22 23 QString 24 safe_displaystring(QUrl url) 25 { 26 auto host = url.host(QUrl::FullyEncoded); 27 std::string host_str = host.toStdString(); 28 29 auto pos = 0u; 30 auto end = host_str.find("."); 31 32 while (end != std::string::npos) { 33 if (!host_str.substr(pos, end - pos).rfind("xn--", pos) && host.compare(url.host(QUrl::FullyDecoded))) 34 return "(" + host + ") " + url.toDisplayString(); 35 pos = end + 1; 36 end = host_str.find("."); 37 } 38 39 return url.toDisplayString(); 40 }