Merge branch 'release-3.29'
[kiteware-cmake.git] / Source / cm_codecvt.hxx
blobc25f9ef3e8c24adfa2a7d6f5c34e126a371296a4
1 /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
2 file Copyright.txt or https://cmake.org/licensing for details. */
3 #pragma once
5 #include "cmConfigure.h" // IWYU pragma: keep
7 #include <cwchar>
8 #include <locale>
10 enum class codecvt_Encoding;
12 class codecvt : public std::codecvt<char, char, mbstate_t>
14 public:
15 #ifndef CMAKE_BOOTSTRAP
17 codecvt(codecvt_Encoding e);
19 protected:
20 ~codecvt() override;
21 bool do_always_noconv() const noexcept override;
22 result do_out(mbstate_t& state, const char* from, const char* from_end,
23 const char*& from_next, char* to, char* to_end,
24 char*& to_next) const override;
25 result do_unshift(mbstate_t& state, char* to, char*,
26 char*& to_next) const override;
27 int do_max_length() const noexcept override;
28 int do_encoding() const noexcept override;
30 private:
31 // The mbstate_t argument to do_out and do_unshift is responsible
32 // for storing state between calls. We cannot control the type
33 // since we want to imbue on standard streams. However, we do
34 // know that it is a trivial type. Define our own type to overlay
35 // on it safely with no alignment requirements.
36 struct State
38 // Buffer bytes we have consumed from a partial codepoint.
39 char partial[3];
41 // Number of bytes we have buffered from a partial codepoint.
42 unsigned char buffered : 4;
44 // Size of the current codepoint in bytes.
45 unsigned char size : 4;
48 bool m_noconv;
49 # if defined(_WIN32)
50 unsigned int m_codepage;
51 result Decode(mbstate_t& state, int need, const char*& from_next,
52 char*& to_next, char* to_end) const;
53 result DecodePartial(mbstate_t& state, char*& to_next, char* to_end) const;
54 void BufferPartial(mbstate_t& state, int need, const char*& from_next) const;
55 # endif
57 #endif