2022-12-18 13:04:40 +01:00

38 lines
675 B
C++

#pragma once
#include <luna/Result.h>
#include <luna/Types.h>
#include <stddef.h>
class Utf8StringDecoder
{
public:
Utf8StringDecoder(const char* str);
usize byte_length() const
{
return m_byte_length;
}
Result<usize> code_points() const;
// The caller must ensure that 'buf' is at least wide_length() + a NULL wide.
Result<void> decode(wchar_t* buf) const;
private:
const char* m_str;
usize m_byte_length;
};
class Utf8StateDecoder
{
public:
Utf8StateDecoder();
Result<Option<wchar_t>> feed(char c);
void reset();
private:
char m_state[4];
usize m_state_len = 0;
usize m_state_index = 0;
};