From e415d59c16fd477621332fd7e3089c170b477485 Mon Sep 17 00:00:00 2001 From: Daniel Wolf Date: Tue, 20 Dec 2016 20:04:43 +0100 Subject: [PATCH] Added toAscii overload --- src/tools/stringTools.cpp | 9 +++++++++ src/tools/stringTools.h | 2 ++ 2 files changed, 11 insertions(+) diff --git a/src/tools/stringTools.cpp b/src/tools/stringTools.cpp index a95701a..ab0b9e6 100644 --- a/src/tools/stringTools.cpp +++ b/src/tools/stringTools.cpp @@ -108,6 +108,15 @@ string toAscii(const u32string& s) { return result; } +string toAscii(const wstring& s) { + string result; + for (wchar_t ch : s) { + optional ascii = toAscii(ch); + if (ascii) result.append(1, *ascii); + } + return result; +} + u32string utf8ToUtf32(const string& s) { #if defined(_MSC_VER) && _MSC_VER <= 1900 // Workaround for Visual Studio 2015 diff --git a/src/tools/stringTools.h b/src/tools/stringTools.h index 71363c8..bab3854 100644 --- a/src/tools/stringTools.h +++ b/src/tools/stringTools.h @@ -16,6 +16,8 @@ boost::optional toAscii(char32_t ch); std::string toAscii(const std::u32string& s); +std::string toAscii(const std::wstring& s); + std::u32string utf8ToUtf32(const std::string& s); template