Embedded Artistry libc
C Standard Library Support for Bare-metal Systems
towccase.c File Reference
#include "_towcase.h"
Include dependency graph for towccase.c:

Go to the source code of this file.

Macros

#define CASEMAP(u1, u2, l)
 
#define CASELACE(u1, u2)   CASEMAP((u1), (u2), (u1) + 1)
 

Functions

wchar_t __towcase (wchar_t wc, int lower)
 

Variables

struct {
unsigned short upper
 
signed char lower
 
unsigned char len
 
casemaps []
 
static const unsigned short pairs [][2]
 

Macro Definition Documentation

◆ CASELACE

#define CASELACE (   u1,
  u2 
)    CASEMAP((u1), (u2), (u1) + 1)

Definition at line 7 of file towccase.c.

◆ CASEMAP

#define CASEMAP (   u1,
  u2,
 
)
Value:
{ \
(u1), (l) - (u1), (u2) - (u1) + 1 \
}

Definition at line 3 of file towccase.c.

Function Documentation

◆ __towcase()

wchar_t __towcase ( wchar_t  wc,
int  lower 
)

Definition at line 218 of file towccase.c.

219 {
220  int i;
221  int lmul = 2 * lower - 1;
222  int lmask = lower - 1;
223  /* no letters with case in these large ranges */
224  if(!iswalpha((wint_t)wc) || (unsigned)wc - 0x0600 <= 0x0fff - 0x0600 ||
225  (unsigned)wc - 0x2e00 <= 0xa63f - 0x2e00 || (unsigned)wc - 0xa800 <= 0xab52 - 0xa800 ||
226  (unsigned)wc - 0xabc0 <= 0xfeff - 0xabc0)
227  {
228  return wc;
229  }
230 
231  /* special case because the diff between upper/lower is too big */
232  if(lower && (unsigned)wc - 0x10a0 < 0x2e)
233  {
234  if(wc > 0x10c5 && wc != 0x10c7 && wc != 0x10cd)
235  {
236  return wc;
237  }
238 
239  return wc + 0x2d00 - 0x10a0;
240  }
241 
242  if(!lower && (unsigned)wc - 0x2d00 < 0x26)
243  {
244  if(wc > 0x2d25 && wc != 0x2d27 && wc != 0x2d2d)
245  {
246  return wc;
247  }
248 
249  return wc + 0x10a0 - 0x2d00;
250  }
251 
252  if(lower && (unsigned)wc - 0x13a0 < 0x50)
253  {
254  return wc + 0xab70 - 0x13a0;
255  }
256 
257  if(!lower && (unsigned)wc - 0xab70 < 0x50)
258  {
259  return wc + 0x13a0 - 0xab70;
260  }
261 
262  for(i = 0; casemaps[i].len; i++)
263  {
264  int base = casemaps[i].upper + (lmask & casemaps[i].lower);
265  if(wc - base < casemaps[i].len)
266  {
267  if(casemaps[i].lower == 1)
268  {
269  return wc + lower - ((wc - casemaps[i].upper) & 1);
270  }
271  return wc + lmul * casemaps[i].lower;
272  }
273  }
274 
275  for(i = 0; pairs[i][1 - lower]; i++)
276  {
277  if(pairs[i][1 - lower] == wc)
278  {
279  return pairs[i][lower];
280  }
281  }
282 
283  if(wc - (0x10428 - 0x28 * lower) < 0x28)
284  {
285  return wc - 0x28 + 0x50 * lower;
286  }
287 
288  if(wc - (0x104d8 - 0x28 * lower) < 0x24)
289  {
290  return wc - 0x28 + 0x50 * lower;
291  }
292 
293  if(wc - (0x10cc0 - 0x40 * lower) < 0x33)
294  {
295  return wc - 0x40 + 0x80 * lower;
296  }
297 
298  if(wc - (0x118c0 - 0x20 * lower) < 0x20)
299  {
300  return wc - 0x20 + 0x40 * lower;
301  }
302 
303  if(wc - (0x1e922 - 0x22 * lower) < 0x22)
304  {
305  return wc - 0x22 + 0x44 * lower;
306  }
307 
308  return wc;
309 }
unsigned wint_t
Definition: wctype.h:11
static const unsigned short pairs[][2]
Definition: towccase.c:67
static const struct @2 casemaps[]
int iswalpha(wint_t)
Definition: iswalpha.c:7

References casemaps, iswalpha(), and pairs.

Referenced by towlower(), and towupper().

Here is the caller graph for this function:

Variable Documentation

◆ casemaps

const { ... } casemaps[]

Referenced by __towcase().

◆ pairs

const unsigned short pairs[][2]
static

Definition at line 67 of file towccase.c.

Referenced by __towcase().