You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by jo...@apache.org on 2017/07/11 01:38:49 UTC

[03/50] mesos git commit: Windows: Added a `wstring wide_stringify(string)` helper.

Windows: Added a `wstring wide_stringify(string)` helper.

When dealing with Windows APIs, often `string` -> `wstring` conversions
are required. This addition makes the process cleaner.

Also added explicit errors messages, which are written to the buffer
instead of throwing an exception if an error occurs.

Review: https://reviews.apache.org/r/60292/


Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/0f6c2120
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/0f6c2120
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/0f6c2120

Branch: refs/heads/master
Commit: 0f6c21201bf4180fa049bc53f49cc67bdd66533d
Parents: edd8453
Author: Andrew Schwartzmeyer <an...@schwartzmeyer.com>
Authored: Tue Jun 27 13:34:39 2017 -0700
Committer: Joseph Wu <jo...@apache.org>
Committed: Mon Jul 10 15:55:09 2017 -0700

----------------------------------------------------------------------
 3rdparty/stout/include/stout/stringify.hpp | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/0f6c2120/3rdparty/stout/include/stout/stringify.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/stout/stringify.hpp b/3rdparty/stout/include/stout/stringify.hpp
index 44da506..49bf684 100644
--- a/3rdparty/stout/include/stout/stringify.hpp
+++ b/3rdparty/stout/include/stout/stringify.hpp
@@ -57,9 +57,25 @@ inline std::string stringify(const std::string& str)
 inline std::string stringify(const std::wstring& str)
 {
   // Convert UTF-16 `wstring` to UTF-8 `string`.
-  std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>, wchar_t> converter;
+  static std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>, wchar_t>
+    converter(
+        "UTF-16 to UTF-8 conversion failed",
+        L"UTF-16 to UTF-8 conversion failed");
+
   return converter.to_bytes(str);
 }
+
+
+inline std::wstring wide_stringify(const std::string& str)
+{
+  // Convert UTF-8 `string` to UTF-16 `wstring`.
+  static std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>, wchar_t>
+    converter(
+        "UTF-8 to UTF-16 conversion failed",
+        L"UTF-8 to UTF-16 conversion failed");
+
+  return converter.from_bytes(str);
+}
 #endif // __WINDOWS__