]> git.ozlabs.org Git - ccan/blob - ccan/ccan_tokenizer/charflag.h
ilog: credit Tim Terriberry as author in ccan/ilog/_info
[ccan] / ccan / ccan_tokenizer / charflag.h
1 #ifndef CCAN_CHARFLAG_H
2 #define CCAN_CHARFLAG_H
3
4 //All of these macros evaluate the argument exactly once
5
6 #define ccontrol(c)  (charflag(c) & CF_CONTROL) //Weird characters that shouldn't be in text
7 #define cspace(c)    (charflag(c) & CF_SPACE)   //Space, tab, vertical tab, form feed
8 #define creturn(c)   (charflag(c) & CF_RETURN)  //Newline
9 #define cwhite(c)    (charflag(c) & CF_WHITE)   //cspace or creturn
10 #define cdigit(c)    (charflag(c) & CF_DIGIT)   //0-9
11 #define cletter(c)   (charflag(c) & CF_LETTER)  //A-Za-z
12 #define chex(c)      (charflag(c) & CF_HEX)     //0-9A-Fa-f
13 #define csymbol(c)   (charflag(c) & CF_SYMBOL)
14         // !"#$%&'()*+,-./:;<=>?@[\]^_`{|}~
15         //If it's ASCII, prints a non-blank character, and is not a digit or letter, it's a symbol
16 #define cextended(c) (charflag(c) == 0)         //Characters >= 128
17
18 /* To test:
19
20 All charflag macros should evaluate exactly once
21
22 */
23
24 extern unsigned char charflag[256];
25 #define charflag(c) (charflag[(unsigned int)(unsigned char)(c)])
26
27 #define CF_CONTROL ((unsigned char)  1)
28 #define CF_SPACE   ((unsigned char)  2)
29 #define CF_RETURN  ((unsigned char)  4)
30 #define CF_DIGIT   ((unsigned char)  8)
31 #define CF_LETTER  ((unsigned char) 16)
32 #define CF_HEX     ((unsigned char) 32)
33 #define CF_SYMBOL  ((unsigned char) 64)
34
35 #define CF_WHITE (CF_SPACE|CF_RETURN)
36
37 #endif