| 1 | //===-- Definition of a class for mbstate_t and conversion -----*-- C++ -*-===// |
| 2 | // |
| 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | #ifndef LLVM_LIBC_SRC___SUPPORT_CHARACTER_CONVERTER_H |
| 10 | #define LLVM_LIBC_SRC___SUPPORT_CHARACTER_CONVERTER_H |
| 11 | |
| 12 | #include "hdr/types/char32_t.h" |
| 13 | #include "hdr/types/char8_t.h" |
| 14 | #include "hdr/types/size_t.h" |
| 15 | #include "src/__support/common.h" |
| 16 | #include "src/__support/error_or.h" |
| 17 | #include "src/__support/wchar/mbstate.h" |
| 18 | |
| 19 | namespace LIBC_NAMESPACE_DECL { |
| 20 | namespace internal { |
| 21 | |
| 22 | class CharacterConverter { |
| 23 | private: |
| 24 | mbstate *state; |
| 25 | |
| 26 | public: |
| 27 | CharacterConverter(mbstate *mbstate); |
| 28 | |
| 29 | void clear(); |
| 30 | bool isFull(); |
| 31 | bool isEmpty(); |
| 32 | bool isValidState(); |
| 33 | |
| 34 | size_t sizeAsUTF32(); |
| 35 | size_t sizeAsUTF8(); |
| 36 | |
| 37 | int push(char8_t utf8_byte); |
| 38 | int push(char32_t utf32); |
| 39 | |
| 40 | ErrorOr<char8_t> pop_utf8(); |
| 41 | ErrorOr<char32_t> pop_utf32(); |
| 42 | }; |
| 43 | |
| 44 | } // namespace internal |
| 45 | } // namespace LIBC_NAMESPACE_DECL |
| 46 | |
| 47 | #endif // LLVM_LIBC_SRC___SUPPORT_CHARACTER_CONVERTER_H |
| 48 | |