robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

taofix(path): normalize path slashes on Windows #37729f130922744

master
4.7 KiB169 linesraw
1#pragma once
2
3#include <stdbool.h>
4
5#include "nvim/os/os_defs.h"
6
7#include "ascii_defs.h.inline.generated.h"
8
9// Definitions of various common control characters.
10
11#define CHAR_ORD(x)      ((uint8_t)(x) < 'a' \
12                          ? (uint8_t)(x) - 'A' \
13                          : (uint8_t)(x) - 'a')
14#define CHAR_ORD_LOW(x)   ((uint8_t)(x) - 'a')
15#define CHAR_ORD_UP(x)    ((uint8_t)(x) - 'A')
16#define ROT13(c, a)     (((((c) - (a)) + 13) % 26) + (a))
17
18#define NUL             '\000'
19#define BELL            '\007'
20#define BS              '\010'
21#define TAB             '\011'
22#define NL              '\012'
23#define NL_STR          "\012"
24#define FF              '\014'
25#define CAR             '\015'  // CR is used by Mac OS X
26#define ESC             '\033'
27#define ESC_STR         "\033"
28#define DEL             0x7f
29#define DEL_STR         "\177"
30#define CSI             0x9b    // Control Sequence Introducer
31#define CSI_STR         "\233"
32#define DCS             0x90    // Device Control String
33#define STERM           0x9c    // String Terminator
34
35#define POUND           0xA3
36
37#define CTRL_CHR(x)     (TOUPPER_ASC(x) ^ 0x40)  // '?' -> DEL, '@' -> ^@, etc.
38#define META(x)         ((x) | 0x80)
39
40#define CTRL_F_STR      "\006"
41#define CTRL_H_STR      "\010"
42#define CTRL_V_STR      "\026"
43
44#define Ctrl_AT         0   // @
45#define Ctrl_A          1
46#define Ctrl_B          2
47#define Ctrl_C          3
48#define Ctrl_D          4
49#define Ctrl_E          5
50#define Ctrl_F          6
51#define Ctrl_G          7
52#define Ctrl_H          8
53#define Ctrl_I          9
54#define Ctrl_J          10
55#define Ctrl_K          11
56#define Ctrl_L          12
57#define Ctrl_M          13
58#define Ctrl_N          14
59#define Ctrl_O          15
60#define Ctrl_P          16
61#define Ctrl_Q          17
62#define Ctrl_R          18
63#define Ctrl_S          19
64#define Ctrl_T          20
65#define Ctrl_U          21
66#define Ctrl_V          22
67#define Ctrl_W          23
68#define Ctrl_X          24
69#define Ctrl_Y          25
70#define Ctrl_Z          26
71// CTRL- [ Left Square Bracket == ESC
72#define Ctrl_BSL        28  // \ BackSLash
73#define Ctrl_RSB        29  // ] Right Square Bracket
74#define Ctrl_HAT        30  // ^
75#define Ctrl__          31
76
77// Character that separates dir names in a path.
78#define PATHSEP        '/'
79#define PATHSEPSTR     "/"
80
81/// Checks if `c` is a space or tab character.
82///
83/// @see {ascii_isdigit}
84static inline bool ascii_iswhite(int c)
85  FUNC_ATTR_CONST FUNC_ATTR_ALWAYS_INLINE
86{
87  return c == ' ' || c == '\t';
88}
89
90/// Checks if `c` is a space or tab character or NUL.
91///
92/// @see {ascii_isdigit}
93static inline bool ascii_iswhite_or_nul(int c)
94  FUNC_ATTR_CONST FUNC_ATTR_ALWAYS_INLINE
95{
96  return ascii_iswhite(c) || c == NUL;
97}
98
99/// Checks if `c` is a space or tab or newline character or NUL.
100///
101/// @see {ascii_isdigit}
102static inline bool ascii_iswhite_nl_or_nul(int c)
103  FUNC_ATTR_CONST FUNC_ATTR_ALWAYS_INLINE
104{
105  return ascii_iswhite(c) || c == '\n' || c == NUL;
106}
107
108/// Check whether character is a decimal digit.
109///
110/// Library isdigit() function is officially locale-dependent and, for
111/// example, returns true for superscript 1 (¹) in locales where encoding
112/// contains it in lower 8 bits. Also avoids crashes in case c is below
113/// 0 or above 255: library functions are officially defined as accepting
114/// only EOF and unsigned char values (otherwise it is undefined behaviour)
115/// what may be used for some optimizations (e.g. simple `return
116/// isdigit_table[c];`).
117static inline bool ascii_isdigit(int c)
118  FUNC_ATTR_CONST FUNC_ATTR_ALWAYS_INLINE
119{
120  return c >= '0' && c <= '9';
121}
122
123/// Checks if `c` is a hexadecimal digit, that is, one of 0-9, a-f, A-F.
124///
125/// @see {ascii_isdigit}
126static inline bool ascii_isxdigit(int c)
127  FUNC_ATTR_CONST FUNC_ATTR_ALWAYS_INLINE
128{
129  return (c >= '0' && c <= '9')
130         || (c >= 'a' && c <= 'f')
131         || (c >= 'A' && c <= 'F');
132}
133
134/// Checks if `c` is an “identifier” character
135///
136/// That is, whether it is alphanumeric character or underscore.
137static inline bool ascii_isident(int c)
138  FUNC_ATTR_CONST FUNC_ATTR_ALWAYS_INLINE
139{
140  return ASCII_ISALNUM(c) || c == '_';
141}
142
143/// Checks if `c` is a binary digit, that is, 0-1.
144///
145/// @see {ascii_isdigit}
146static inline bool ascii_isbdigit(int c)
147  FUNC_ATTR_CONST FUNC_ATTR_ALWAYS_INLINE
148{
149  return (c == '0' || c == '1');
150}
151
152/// Checks if `c` is an octal digit, that is, 0-7.
153///
154/// @see {ascii_isdigit}
155static inline bool ascii_isodigit(int c)
156  FUNC_ATTR_CONST FUNC_ATTR_ALWAYS_INLINE
157{
158  return (c >= '0' && c <= '7');
159}
160
161/// Checks if `c` is a white-space character, that is,
162/// one of \f, \n, \r, \t, \v.
163///
164/// @see {ascii_isdigit}
165static inline bool ascii_isspace(int c)
166  FUNC_ATTR_CONST FUNC_ATTR_ALWAYS_INLINE
167{
168  return (c >= 9 && c <= 13) || c == ' ';
169}