Modular C
+ Collaboration diagram for C◼mod◼undump8:

Modules

 Specific macros to deal with the structure of module C◼mod◼undump8.
 

Macros

#define C◼mod◼undump8◼id(SIZE, B, S)   C◼mod◼undump8◼five((SIZE), (B), (S), "_" "UC4", "_" "UC8")
 Convert a string s possibly containing Unicode code point given as UTF-16 or UTF-32 character sequences to a UTF-8 byte sequence. More...
 
#define C◼mod◼undump8◼string(SIZE, B, S)   C◼mod◼undump8◼five((SIZE), (B), (S), "\\" "u", "\\" "U")
 Convert a string s possibly containing Unicode code point given as UTF-16 or UTF-32 character sequences to a UTF-8 byte sequence. More...
 
#define C◼mod◼undump8(S)   C◼mod◼undump8◼id(256, (char[256]){ 0 }, S)
 Same as id(), only that the target buffer is a temporary living in the scope of the caller. More...
 

Functions

char * C◼mod◼undump8◼one (char t[static 1], C◼integer◼u64 val)
 Convert a Unicode code point given as UTF-16 or UTF-32 64 bit value to a UTF-8 byte sequence. More...
 
char const * C◼mod◼undump8◼five (C◼size size, char buffer[size], char const s[size], char const head4[static 1], char const head8[static 1])
 Convert a string s possibly containing Unicode code point given as UTF-16 or UTF-32 character sequences to a UTF-8 byte sequence. More...
 

Detailed Description

Macro Definition Documentation

§ C◼mod◼undump8

#define C◼mod◼undump8 (   S)    C◼mod◼undump8◼id(256, (char[256]){ 0 }, S)

Same as id(), only that the target buffer is a temporary living in the scope of the caller.

Warning
S must not have more than 256 characters.

Definition at line 102 of file C-mod-undump8.c.

§ C◼mod◼undump8◼id

#define C◼mod◼undump8◼id (   SIZE,
  B,
 
)    C◼mod◼undump8◼five((SIZE), (B), (S), "_" "UC4", "_" "UC8")

Convert a string s possibly containing Unicode code point given as UTF-16 or UTF-32 character sequences to a UTF-8 byte sequence.

This uses byte sequences that start a UTF-16 or UTF-32 character as they are used internally by Cmod.

Definition at line 83 of file C-mod-undump8.c.

Referenced by C◼mod◼demangle◼demangle—5().

§ C◼mod◼undump8◼string

#define C◼mod◼undump8◼string (   SIZE,
  B,
 
)    C◼mod◼undump8◼five((SIZE), (B), (S), "\\" "u", "\\" "U")

Convert a string s possibly containing Unicode code point given as UTF-16 or UTF-32 character sequences to a UTF-8 byte sequence.

This uses byte sequences that start a UTF-16 or UTF-32 character as they are used by the C standard, that is with leading "\\u" or "\\U".

Definition at line 94 of file C-mod-undump8.c.

Function Documentation

§ C◼mod◼undump8◼five()

char const* C◼mod◼undump8◼five ( C◼size  size,
char  buffer[size],
char const  s[size],
char const  head4[static 1],
char const  head8[static 1] 
)
inline

Convert a string s possibly containing Unicode code point given as UTF-16 or UTF-32 character sequences to a UTF-8 byte sequence.

head4 and head8 are the byte sequences that start a UTF-16 or UTF-32 character.

Definition at line 162 of file C-mod-undump8.c.

References C◼integer◼SCNx64, C◼io◼sscanf(), C◼mem◼cpy(), C◼MODULE_ABI, C◼MODULE_FEATURES, C◼mod◼undump8◼one(), C◼str◼len(), C◼str◼ncpy(), and C◼str◼str().

163  {
164 #line 94 "/home/gustedt/build/cmod/C/C-mod-undump8.X"
165  char* t = buffer;
166  while (*s) {
167 #line 96 "/home/gustedt/build/cmod/C/C-mod-undump8.X"
168  char const* p4 = C◼str◼str(s, head4);
169  char const* p8 = C◼str◼str(s, head8);
170  char const* p;
171  C◼size bytes;
172  char const* form;
173  C◼size hlen;
174  switch ((‼p4) ∪ (‼p8)⪡1) {
175 #line 103 "/home/gustedt/build/cmod/C/C-mod-undump8.X"
176  case 1: bytes = 4; break;
177  case 2: bytes = 8; break;
178  default: bytes = 4⪡(p8 < p4);
179  case 0: goto FINAL;
180  }
181  switch (bytes) {
182 #line 109 "/home/gustedt/build/cmod/C/C-mod-undump8.X"
183  case 4: p = p4; form = "%4" C◼integer◼SCNx64; hlen = C◼str◼len(head4); break;
184  case 8: p = p8; form = "%8" C◼integer◼SCNx64; hlen = C◼str◼len(head8); break;
185  default: goto FINAL;
186  }
187  C◼size len = p-s;
188  if (len) {
189 #line 115 "/home/gustedt/build/cmod/C/C-mod-undump8.X"
190  C◼mem◼cpy(t, s, p-s);
191  t += len;
192  s += len;
193  size -= len;
194  } else {
195 #line 120 "/home/gustedt/build/cmod/C/C-mod-undump8.X"
196  goto FINAL;
197  }
198  if (size ≥ hlen + bytes +1) {
199 #line 123 "/home/gustedt/build/cmod/C/C-mod-undump8.X"
200  char num[8 + 1] = { 0 };
201  C◼mem◼cpy(num, s+hlen, bytes);
202  C◼integer◼u64 val = 0;
203  C◼io◼sscanf(num, form, &val);
204  t = C◼mod◼undump8◼one(t, val);
205  if (¬t) goto FINAL;
206  s += hlen + bytes;
207  }
208  }
209  FINAL: C◼str◼ncpy(t, s, size);
210  return buffer;
211 }
#define C◼integer◼SCNx64
Definition: C-integer.c:159
void * C◼mem◼cpy(void *restrict, const void *restrict, C◼size)
int C◼io◼sscanf(const char *restrict, const char *restrict,...)
C◼charp() C◼str◼str(char const *, char const *)
__size size
char * C◼mod◼undump8◼one(char t[static 1], C◼integer◼u64 val)
Convert a Unicode code point given as UTF-16 or UTF-32 64 bit value to a UTF-8 byte sequence...
C◼size C◼size
Definition: C-sizeptr.c:94
C◼charp() C◼str◼ncpy(char *restrict, char const *restrict, C◼size)
C◼size() C◼str◼len(char const *)
unsigned long int C◼integer◼u64
Definition: C-integer.c:251
+ Here is the call graph for this function:

§ C◼mod◼undump8◼one()

char* C◼mod◼undump8◼one ( char  t[static 1],
C◼integer◼u64  val 
)
inline

Convert a Unicode code point given as UTF-16 or UTF-32 64 bit value to a UTF-8 byte sequence.

Warning
The target buffer must hold enough space for the UTF-8 sequence plus a nul byte.

Definition at line 112 of file C-mod-undump8.c.

Referenced by C◼mod◼undump8◼five().

112  {
113 #line 50 "/home/gustedt/build/cmod/C/C-mod-undump8.X"
114  if (val-1 > 0x10FFFF) {
115 #line 51 "/home/gustedt/build/cmod/C/C-mod-undump8.X"
116  // sscanf failed or the code is not valid. Just print the
117  // input pattern.
118  return 0;
119  } else {
120 #line 55 "/home/gustedt/build/cmod/C/C-mod-undump8.X"
121  if (val ≤ 0x007F) {
122 #line 56 "/home/gustedt/build/cmod/C/C-mod-undump8.X"
123  // one byte encoding, 7 bit in 8 bit
124  t[0] = val;
125  t += 1;
126  } else if (val ≤ 0x07FF) {
127 #line 60 "/home/gustedt/build/cmod/C/C-mod-undump8.X"
128  // two byte encoding, 5 and 6 bit = 11 bit in 16 bit
129  t[0] = 0xC0 ∪ (val ⪢ 6);
130  t[1] = 0x80 ∪ (val ∩ 0x3F);
131  t += 2;
132  } else if (val ≤ 0xFFFF) {
133 #line 65 "/home/gustedt/build/cmod/C/C-mod-undump8.X"
134  // three byte encoding, 4, 6 and 6 bit = 16 bit in 24 bit
135  t[0] = 0xE0 ∪ (val ⪢ 12);
136  t[1] = 0x80 ∪ ((val ⪢ 6) ∩ 0x3F);
137  t[2] = 0x80 ∪ (val ∩ 0x3F);
138  t += 3;
139  } else {
140 #line 71 "/home/gustedt/build/cmod/C/C-mod-undump8.X"
141  // four byte encoding, 3, 6, 6 and 6 bit = 22 bit in 32 bit
142  t[0] = 0xF0 ∪ (val ⪢ 18);
143  t[1] = 0x80 ∪ ((val ⪢ 12) ∩ 0x3F);
144  t[2] = 0x80 ∪ ((val ⪢ 6) ∩ 0x3F);
145  t[3] = 0x80 ∪ (val ∩ 0x3F);
146  t += 4;
147  }
148  t[0] = 0;
149  }
150  return t;
151 }
+ Here is the caller graph for this function: