Inexor
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
cube_unicode.hpp
Go to the documentation of this file.
1 #pragma once
5 
6 #include <stddef.h> // for size_t
7 
8 #include "inexor/shared/cube_types.hpp" // for uchar, uint
9 
11 extern size_t decodeutf8(uchar *dst, size_t dstlen, const uchar *src, size_t srclen, size_t *carry = nullptr);
12 extern size_t encodeutf8(uchar *dstbuf, size_t dstlen, const uchar *srcbuf, size_t srclen, size_t *carry = nullptr);
13 
14 
15 enum
16 {
17  CT_PRINT = 1<<0,
18  CT_SPACE = 1<<1,
19  CT_DIGIT = 1<<2,
20  CT_ALPHA = 1<<3,
21  CT_LOWER = 1<<4,
22  CT_UPPER = 1<<5,
23  CT_UNICODE = 1<<6
24 };
25 
26 
27 extern const uchar cubectype[256];
28 static inline int iscubeprint(uchar c) { return cubectype[c]&CT_PRINT; }
29 static inline int iscubespace(uchar c) { return cubectype[c]&CT_SPACE; }
30 static inline int iscubealpha(uchar c) { return cubectype[c]&CT_ALPHA; }
31 static inline int iscubealnum(uchar c) { return cubectype[c]&(CT_ALPHA|CT_DIGIT); }
32 static inline int iscubelower(uchar c) { return cubectype[c]&CT_LOWER; }
33 static inline int iscubeupper(uchar c) { return cubectype[c]&CT_UPPER; }
34 static inline int cube2uni(uchar c)
35 {
36  extern const int cube2unichars[256];
37  return cube2unichars[c];
38 }
39 static inline uchar uni2cube(int c)
40 {
41  extern const int uni2cubeoffsets[8];
42  extern const uchar uni2cubechars[];
43  return uint(c) <= 0x7FF ? uni2cubechars[uni2cubeoffsets[c>>8] + (c&0xFF)] : 0;
44 }
45 static inline uchar cubelower(uchar c)
46 {
47  extern const uchar cubelowerchars[256];
48  return cubelowerchars[c];
49 }
50 static inline uchar cubeupper(uchar c)
51 {
52  extern const uchar cubeupperchars[256];
53  return cubeupperchars[c];
54 }
55 
Definition: cube_unicode.hpp:17
unsigned int uint
Definition: cube_types.hpp:9
Definition: cube_unicode.hpp:22
static int iscubealnum(uchar c)
Definition: cube_unicode.hpp:31
const int cube2unichars[256]
const uchar cubelowerchars[256]
static int iscubeupper(uchar c)
Definition: cube_unicode.hpp:33
const uchar cubectype[256]
Definition: cube_unicode.hpp:23
const uchar uni2cubechars[878]
const int uni2cubeoffsets[8]
Definition: cube_unicode.hpp:20
static int iscubealpha(uchar c)
Definition: cube_unicode.hpp:30
Definition: cube_unicode.hpp:21
static uchar cubeupper(uchar c)
Definition: cube_unicode.hpp:50
static uchar cubelower(uchar c)
Definition: cube_unicode.hpp:45
unsigned char uchar
Basic type definitions.
Definition: cube_types.hpp:7
static int iscubespace(uchar c)
Definition: cube_unicode.hpp:29
static int cube2uni(uchar c)
Definition: cube_unicode.hpp:34
Definition: cube_unicode.hpp:19
size_t decodeutf8(uchar *dst, size_t dstlen, const uchar *src, size_t srclen, size_t *carry=nullptr)
Legacy file for UTF8 support.
Definition: cube_unicode.cpp:128
Definition: cube_unicode.hpp:18
const uchar cubeupperchars[256]
size_t encodeutf8(uchar *dstbuf, size_t dstlen, const uchar *srcbuf, size_t srclen, size_t *carry=nullptr)
Definition: cube_unicode.cpp:182
static int iscubelower(uchar c)
Definition: cube_unicode.hpp:32
static int iscubeprint(uchar c)
Definition: cube_unicode.hpp:28
static uchar uni2cube(int c)
Definition: cube_unicode.hpp:39