Echo Writes Code

transcoding.hpp

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
#ifndef CRUCIBLE_WINDOWS_TRANSCODING_HPP
#define CRUCIBLE_WINDOWS_TRANSCODING_HPP

#include "crucible/core/error_chain.inl"
#include "crucible/core/result.inl"

#include <string>

namespace crucible::windows::transcoding {
  struct MultiByteToWideCharFailed final {
    [[nodiscard]]
    auto format() const -> std::string;
  };

  struct WideCharToMultiByteFailed final {
    [[nodiscard]]
    auto format() const -> std::string;
  };

  struct OutputTruncated final {
    [[nodiscard]]
    auto format() const -> std::string;
  };

  struct TranscodingErrorDescription final {
    [[nodiscard]]
    auto format() const -> std::string;
  };

  using TranscodingError = core::error_chain::ErrorChain<TranscodingErrorDescription, MultiByteToWideCharFailed, WideCharToMultiByteFailed, OutputTruncated>;

  template<typename T>
  using TranscodingResult = core::result::Result<TranscodingError, T>;

  [[nodiscard]]
  auto transcode_utf8_to_utf16(std::string const &utf8) -> TranscodingResult<std::wstring>;

  [[nodiscard]]
  auto transcode_utf16_to_utf8(std::wstring const &utf16) -> TranscodingResult<std::string>;
}

#endif // CRUCIBLE_WINDOWS_TRANSCODING_HPP