meta: add c++ wrapper of core module
This commit is contained in:
106
core-mm/include/blue/core/encoding.hpp
Normal file
106
core-mm/include/blue/core/encoding.hpp
Normal file
@@ -0,0 +1,106 @@
|
||||
#ifndef BLUE_CORE_ENCODING_HPP_
|
||||
#define BLUE_CORE_ENCODING_HPP_
|
||||
|
||||
#include <blue/core/encoding.h>
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
|
||||
namespace blue::core
|
||||
{
|
||||
class wchar
|
||||
{
|
||||
public:
|
||||
static const int32_t INVALID = B_WCHAR_INVALID;
|
||||
|
||||
wchar();
|
||||
wchar(std::int32_t v)
|
||||
: val_(v)
|
||||
{
|
||||
}
|
||||
static wchar decode(const char *s);
|
||||
|
||||
operator int32_t() const
|
||||
{
|
||||
return val_;
|
||||
}
|
||||
|
||||
bool is_alpha(void) const
|
||||
{
|
||||
return b_wchar_is_alpha(val_);
|
||||
}
|
||||
bool is_number(void) const
|
||||
{
|
||||
return b_wchar_is_number(val_);
|
||||
}
|
||||
bool is_bin_digit(void) const
|
||||
{
|
||||
return b_wchar_is_bin_digit(val_);
|
||||
}
|
||||
bool is_oct_digit(void) const
|
||||
{
|
||||
return b_wchar_is_oct_digit(val_);
|
||||
}
|
||||
bool is_hex_digit(void) const
|
||||
{
|
||||
return b_wchar_is_hex_digit(val_);
|
||||
}
|
||||
bool is_space(void) const
|
||||
{
|
||||
return b_wchar_is_space(val_);
|
||||
}
|
||||
bool is_alnum(void) const
|
||||
{
|
||||
return b_wchar_is_alnum(val_);
|
||||
}
|
||||
bool is_punct(void) const
|
||||
{
|
||||
return b_wchar_is_punct(val_);
|
||||
}
|
||||
|
||||
bool is_valid_utf8_scalar(void) const
|
||||
{
|
||||
return b_wchar_utf8_is_valid_scalar(val_);
|
||||
}
|
||||
unsigned int get_utf8_codepoint_size(void) const
|
||||
{
|
||||
return b_wchar_utf8_codepoint_size(val_);
|
||||
}
|
||||
|
||||
unsigned int encode_utf8(char s[4]) const
|
||||
{
|
||||
return b_wchar_utf8_codepoint_encode(val_, s);
|
||||
}
|
||||
|
||||
private:
|
||||
int32_t val_ = B_WCHAR_INVALID;
|
||||
};
|
||||
|
||||
class utf8
|
||||
{
|
||||
public:
|
||||
static unsigned int decode_header(char c)
|
||||
{
|
||||
return b_wchar_utf8_header_decode(c);
|
||||
}
|
||||
static unsigned int get_codepoint_stride(const char *s)
|
||||
{
|
||||
return b_wchar_utf8_codepoint_stride(s);
|
||||
}
|
||||
static std::size_t get_codepoint_count(const char *s, std::size_t nr_bytes)
|
||||
{
|
||||
return b_wchar_utf8_codepoint_count(s, nr_bytes);
|
||||
}
|
||||
static std::size_t get_string_encoded_size(
|
||||
const wchar *s, std::size_t nr_codepoints)
|
||||
{
|
||||
return b_wchar_utf8_string_encoded_size(
|
||||
reinterpret_cast<const b_wchar *>(s), nr_codepoints);
|
||||
}
|
||||
|
||||
private:
|
||||
utf8() = delete;
|
||||
~utf8() = delete;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user