85 lines
2.7 KiB
C++
85 lines
2.7 KiB
C++
#pragma once
|
|
|
|
#include <cstdint>
|
|
#include <string_view>
|
|
|
|
namespace xicu {
|
|
|
|
class PropTable {
|
|
public:
|
|
PropTable() = default;
|
|
explicit PropTable(const char* path);
|
|
~PropTable();
|
|
|
|
PropTable(const PropTable&) = delete;
|
|
PropTable& operator=(const PropTable&) = delete;
|
|
PropTable(PropTable&& other) noexcept;
|
|
PropTable& operator=(PropTable&& other) noexcept;
|
|
|
|
bool load(const char* path);
|
|
bool isLoaded() const { return data_ != nullptr; }
|
|
std::string_view getName(uint32_t cp) const;
|
|
bool getPunctuation(uint32_t cp) const;
|
|
bool getLetter(uint32_t cp) const;
|
|
int32_t getUppercase_map(uint32_t cp) const;
|
|
int32_t getLowercase_map(uint32_t cp) const;
|
|
bool getWhitespace(uint32_t cp) const;
|
|
bool getSpace(uint32_t cp) const;
|
|
bool getDecimal(uint32_t cp) const;
|
|
int32_t getDecimal_val(uint32_t cp) const;
|
|
|
|
private:
|
|
const uint8_t* data_ = nullptr;
|
|
size_t data_size_ = 0;
|
|
bool owns_data_ = false;
|
|
|
|
static uint32_t readVarint(const uint8_t*& ptr);
|
|
const uint8_t* findFieldData(const char* name, uint8_t& out_type, uint8_t& out_strat) const;
|
|
const uint8_t* findStringField(const char* name) const;
|
|
|
|
// Decoders
|
|
bool decodeBitmap(const uint8_t* data, uint32_t cp) const;
|
|
bool decodeDeltaRangesBool(const uint8_t* data, const uint8_t* data_end, uint32_t cp) const;
|
|
int32_t decodeDeltaRangesInt(const uint8_t* data, const uint8_t* data_end, uint32_t cp) const;
|
|
bool decodeSparseMapBool(const uint8_t* data, const uint8_t* data_end, uint32_t cp) const;
|
|
int32_t decodeSparseMapInt(const uint8_t* data, const uint8_t* data_end, uint32_t cp) const;
|
|
};
|
|
|
|
inline std::string_view getName(uint32_t cp) {
|
|
static PropTable table("../out/xicu.bin");
|
|
return table.getName(cp);
|
|
}
|
|
inline bool isPunctuation(uint32_t cp) {
|
|
static PropTable table("../out/xicu.bin");
|
|
return table.getPunctuation(cp);
|
|
}
|
|
inline bool isLetter(uint32_t cp) {
|
|
static PropTable table("../out/xicu.bin");
|
|
return table.getLetter(cp);
|
|
}
|
|
inline int32_t getUppercase_map(uint32_t cp) {
|
|
static PropTable table("../out/xicu.bin");
|
|
return table.getUppercase_map(cp);
|
|
}
|
|
inline int32_t getLowercase_map(uint32_t cp) {
|
|
static PropTable table("../out/xicu.bin");
|
|
return table.getLowercase_map(cp);
|
|
}
|
|
inline bool isWhitespace(uint32_t cp) {
|
|
static PropTable table("../out/xicu.bin");
|
|
return table.getWhitespace(cp);
|
|
}
|
|
inline bool isSpace(uint32_t cp) {
|
|
static PropTable table("../out/xicu.bin");
|
|
return table.getSpace(cp);
|
|
}
|
|
inline bool isDecimal(uint32_t cp) {
|
|
static PropTable table("../out/xicu.bin");
|
|
return table.getDecimal(cp);
|
|
}
|
|
inline int32_t getDecimal_val(uint32_t cp) {
|
|
static PropTable table("../out/xicu.bin");
|
|
return table.getDecimal_val(cp);
|
|
}
|
|
|
|
} // namespace xicu
|