Embedded Artistry libc
C Standard Library Support for Bare-metal Systems
wcwidth.c
Go to the documentation of this file.
1 #include <wchar.h>
2 
3 static const unsigned char table[] = {
4 #include "nonspacing.h"
5 };
6 
7 static const unsigned char wtable[] = {
8 #include "wide.h"
9 };
10 
11 int wcwidth(wchar_t wc)
12 {
13  if(wc < (wchar_t)0xffU)
14  {
15  return (wc + 1 & 0x7f) >= 0x21 ? 1 : wc ? -1 : 0;
16  }
17 
18  if((wc & (wchar_t)0xfffeffffU) < 0xfffe)
19  {
20  if((table[table[wc >> 8] * 32 + ((wc & 255) >> 3)] >> (wc & 7)) & 1)
21  {
22  return 0;
23  }
24 
25  if((wtable[wtable[wc >> 8] * 32 + ((wc & 255) >> 3)] >> (wc & 7)) & 1)
26  {
27  return 2;
28  }
29 
30  return 1;
31  }
32 
33  if((wc & 0xfffe) == 0xfffe)
34  {
35  return -1;
36  }
37 
38  if(wc - (wchar_t)0x20000U < 0x20000)
39  {
40  return 2;
41  }
42 
43  if(wc == 0xe0001 || wc - (wchar_t)0xe0020U < 0x5f || wc - 0xe0100 < 0xef)
44  {
45  return 0;
46  }
47 
48  return 1;
49 }
int wcwidth(wchar_t wc)
Definition: wcwidth.c:11
static const unsigned char wtable[]
Definition: wcwidth.c:7
static const unsigned char table[]
Definition: wcwidth.c:3