Team Ai
Apppublic

KBaba7/llama.cpp

sourceHugging Faceapache-2.0updated 2y agoView on Hugging Face
0likes
unicode.h67 linesDownload Raw Back to src
1#pragma once2 3#include <cstdint>4#include <string>5#include <vector>6 7struct unicode_cpt_flags {8    enum {9        UNDEFINED       = 0x0001,10        NUMBER          = 0x0002,  // regex: \p{N}11        LETTER          = 0x0004,  // regex: \p{L}12        SEPARATOR       = 0x0008,  // regex: \p{Z}13        ACCENT_MARK     = 0x0010,  // regex: \p{M}14        PUNCTUATION     = 0x0020,  // regex: \p{P}15        SYMBOL          = 0x0040,  // regex: \p{S}16        CONTROL         = 0x0080,  // regex: \p{C}17        MASK_CATEGORIES = 0x00FF,18    };19 20    // codepoint type21    uint16_t is_undefined   : 1;22    uint16_t is_number      : 1;  // regex: \p{N}23    uint16_t is_letter      : 1;  // regex: \p{L}24    uint16_t is_separator   : 1;  // regex: \p{Z}25    uint16_t is_accent_mark : 1;  // regex: \p{M}26    uint16_t is_punctuation : 1;  // regex: \p{P}27    uint16_t is_symbol      : 1;  // regex: \p{S}28    uint16_t is_control     : 1;  // regex: \p{C}29    // helper flags30    uint16_t is_whitespace  : 1;  // regex: \s31    uint16_t is_lowercase   : 1;32    uint16_t is_uppercase   : 1;33    uint16_t is_nfd         : 1;34 35    // decode from uint1636    inline unicode_cpt_flags(const uint16_t flags = 0) {37        *reinterpret_cast<uint16_t*>(this) = flags;38    }39 40    inline uint16_t as_uint() const {41        return *reinterpret_cast<const uint16_t*>(this);42    }43 44    inline uint16_t category_flag() const {45        return this->as_uint() & MASK_CATEGORIES;46    }47};48 49size_t unicode_len_utf8(char src);50 51std::string unicode_cpt_to_utf8  (uint32_t cpt);52uint32_t    unicode_cpt_from_utf8(const std::string & utf8, size_t & offset);53 54std::vector<uint32_t> unicode_cpts_from_utf8(const std::string & utf8);55 56std::vector<uint32_t> unicode_cpts_normalize_nfd(const std::vector<uint32_t> & cpts);57 58unicode_cpt_flags unicode_cpt_flags_from_cpt (uint32_t cpt);59unicode_cpt_flags unicode_cpt_flags_from_utf8(const std::string & utf8);60 61std::string unicode_byte_to_utf8(uint8_t byte);62uint8_t     unicode_utf8_to_byte(const std::string & utf8);63 64uint32_t unicode_tolower(uint32_t cpt);65 66std::vector<std::string> unicode_regex_split(const std::string & text, const std::vector<std::string> & regex_exprs);67