src: use wstring for showing text in QtTextEditDialog
This commit is contained in:
+19
-12
@@ -72,6 +72,11 @@ namespace utility
|
||||
template<>
|
||||
std::vector<std::string> toStrings(const std::vector<FilePath>& d);
|
||||
|
||||
template<typename T>
|
||||
std::vector<std::wstring> toWStrings(const std::vector<T>& d);
|
||||
template<>
|
||||
std::vector<std::wstring> toWStrings(const std::vector<FilePath>& d);
|
||||
|
||||
template<typename T>
|
||||
bool isPermutation(const std::vector<T>& a, const std::vector<T>& b)
|
||||
{
|
||||
@@ -237,23 +242,25 @@ std::vector<TargetType> utility::convert(const std::vector<SourceType>& sourceCo
|
||||
template<typename T>
|
||||
std::vector<std::string> utility::toStrings(const std::vector<T>& d)
|
||||
{
|
||||
std::vector<std::string> v;
|
||||
for (const T& t : d)
|
||||
{
|
||||
v.push_back(std::to_string(t));
|
||||
}
|
||||
return v;
|
||||
return convert<T, std::string>(d, [](T t) { return std::to_string(t); });
|
||||
}
|
||||
|
||||
template<>
|
||||
inline std::vector<std::string> utility::toStrings<FilePath>(const std::vector<FilePath>& d)
|
||||
{
|
||||
std::vector<std::string> v;
|
||||
for (const FilePath& t : d)
|
||||
{
|
||||
v.push_back(utility::encodeToUtf8(t.wstr()));
|
||||
}
|
||||
return v;
|
||||
return convert<FilePath, std::string>(d, [](const FilePath& fp) { return utility::encodeToUtf8(fp.wstr()); });
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
std::vector<std::wstring> utility::toWStrings(const std::vector<T>& d)
|
||||
{
|
||||
return convert(d, [](T t) { return std::to_wstring(t); });
|
||||
}
|
||||
|
||||
template<>
|
||||
inline std::vector<std::wstring> utility::toWStrings<FilePath>(const std::vector<FilePath>& d)
|
||||
{
|
||||
return convert<FilePath, std::wstring>(d, [](const FilePath& fp) { return fp.wstr(); });
|
||||
}
|
||||
|
||||
#endif // UTILITY_H
|
||||
|
||||
@@ -449,11 +449,18 @@ namespace utility
|
||||
|
||||
std::string trim(const std::string &str)
|
||||
{
|
||||
auto wsfront = std::find_if_not(str.begin(), str.end(), [](int c){ return std::isspace(c); });
|
||||
auto wsback = std::find_if_not(str.rbegin(), str.rend(), [](int c){ return std::isspace(c); }).base();
|
||||
auto wsfront = std::find_if_not(str.begin(), str.end(), [](int c) { return std::isspace(c); });
|
||||
auto wsback = std::find_if_not(str.rbegin(), str.rend(), [](int c) { return std::isspace(c); }).base();
|
||||
return (wsback <= wsfront ? std::string() : std::string(wsfront, wsback));
|
||||
}
|
||||
|
||||
std::wstring trim(const std::wstring &str)
|
||||
{
|
||||
auto wsfront = std::find_if_not(str.begin(), str.end(), [](int c) { return std::isspace(c); });
|
||||
auto wsback = std::find_if_not(str.rbegin(), str.rend(), [](int c) { return std::isspace(c); }).base();
|
||||
return (wsback <= wsfront ? std::wstring() : std::wstring(wsfront, wsback));
|
||||
}
|
||||
|
||||
std::string elide(const std::string& str, ElideMode mode, size_t size)
|
||||
{
|
||||
if (str.size() <= size || str.size() <= 3)
|
||||
|
||||
@@ -27,6 +27,9 @@ namespace utility
|
||||
template <typename ContainerType>
|
||||
std::string join(const ContainerType& list, const std::string& delimiter);
|
||||
|
||||
template <typename ContainerType>
|
||||
std::wstring join(const ContainerType& list, const std::wstring& delimiter);
|
||||
|
||||
std::string join(const std::deque<std::string>& list, char delimiter);
|
||||
std::string join(const std::deque<std::string>& list, const std::string& delimiter);
|
||||
std::string join(const std::vector<std::string>& list, char delimiter);
|
||||
@@ -65,6 +68,7 @@ namespace utility
|
||||
size_t maxLineLength, size_t tabWidth);
|
||||
|
||||
std::string trim(const std::string &str);
|
||||
std::wstring trim(const std::wstring &str);
|
||||
|
||||
enum ElideMode
|
||||
{
|
||||
@@ -127,6 +131,24 @@ namespace utility
|
||||
}
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
template <typename ContainerType>
|
||||
std::wstring join(const ContainerType& list, const std::wstring& delimiter)
|
||||
{
|
||||
std::wstringstream ss;
|
||||
bool first = true;
|
||||
for (const std::wstring& str : list)
|
||||
{
|
||||
if (!first)
|
||||
{
|
||||
ss << delimiter;
|
||||
}
|
||||
first = false;
|
||||
|
||||
ss << str;
|
||||
}
|
||||
return ss.str();
|
||||
}
|
||||
}
|
||||
|
||||
#endif // UTILITY_STRING_H
|
||||
|
||||
Reference in New Issue
Block a user