robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
aa1d8a2702
master
1#pragma once 2 3#include <stdbool.h> 4#include <stdint.h> 5#include <utf8proc.h> 6 7#include "nvim/iconv_defs.h" 8 9enum { 10/// Maximum number of bytes in the multi-byte character of one screen cell. 11/// It can be one character of up to six bytes, plus MAX_MCO following composing 12/// characters of up to four bytes each. 13MB_MAXBYTES = 30 , 14/// Maximum length of a Unicode character, excluding composing characters. 15MB_MAXCHAR = 6 , 16}; 17 18/// properties used in enc_canon_table[] (first three mutually exclusive) 19enum { 20ENC_8BIT = 0x01 , 21ENC_DBCS = 0x02 , 22ENC_UNICODE = 0x04 , 23 24ENC_ENDIAN_B = 0x10 ,///< Unicode: Big endian 25ENC_ENDIAN_L = 0x20 ,///< Unicode: Little endian 26 27ENC_2BYTE = 0x40 ,///< Unicode: UCS-2 28ENC_4BYTE = 0x80 ,///< Unicode: UCS-4 29ENC_2WORD = 0x100 ,///< Unicode: UTF-16 30 31ENC_LATIN1 = 0x200 ,///< Latin1 32ENC_LATIN9 = 0x400 ,///< Latin9 33ENC_MACROMAN = 0x800 ,///< Mac Roman (not Macro Man! :-) 34}; 35 36/// Flags for vimconv_T 37typedef enum { 38CONV_NONE = 0 , 39CONV_TO_UTF8 = 1 , 40CONV_9_TO_UTF8 = 2 , 41CONV_TO_LATIN1 = 3 , 42CONV_TO_LATIN9 = 4 , 43CONV_ICONV = 5 , 44}ConvFlags ; 45 46#define MBYTE_NONE_CONV { \ 47 .vc_type = CONV_NONE, \ 48 .vc_factor = 1, \ 49 .vc_fail = false, \ 50} 51 52/// Structure used for string conversions 53typedef struct { 54int vc_type ;///< Zero or more ConvFlags. 55int vc_factor ;///< Maximal expansion factor. 56iconv_t vc_fd ;///< Value for CONV_ICONV. 57bool vc_fail ;///< What to do with invalid characters: if true, fail, 58///< otherwise use '?'. 59}vimconv_T ; 60 61typedef struct { 62int32_t value ;///< Code point. 63int len ;///< Length in bytes. 64}CharInfo ; 65 66typedef struct { 67char * ptr ;///< Pointer to the first byte of the character. 68CharInfo chr ;///< Information about the character. 69}StrCharInfo ; 70 71typedef struct { 72StrCharInfo next ;///< char after cluster 73int cells ;///< cell width of cluster 74}ClusterInfo ; 75 76typedef struct { 77int8_t begin_off ;///< Offset to the first byte of the codepoint. 78int8_t end_off ;///< Offset to one past the end byte of the codepoint. 79}CharBoundsOff ; 80 81typedef utf8proc_int32_t GraphemeState ; 82 83enum {UNICODE_INVALID = 0xFFFD , };