Welcome to mirror list, hosted at ThFree Co, Russian Federation.

wctrans.c « mingwex « mingw « winsup - cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: e129af471b0700e74954fc5b5e2d58d88e821553 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/*
   wctrans.c 
   7.25.3.2 Extensible wide-character case mapping functions

   Contributed by: Danny Smith  <dannysmith@usesr.sourcefoge.net>
   		   2005-02-24
   
  This source code is placed in the PUBLIC DOMAIN. It is modified
  from the Q8 package created by Doug Gwyn <gwyn@arl.mil>  

 */

#include <string.h>
#include <wctype.h>

/*
   This differs from the MS implementation of wctrans which
   returns 0 for tolower and 1 for toupper.  According to
   C99, a 0 return value indicates invalid input.

   These two function go in the same translation unit so that we
   can ensure that
     towctrans(wc, wctrans("tolower")) == towlower(wc) 
     towctrans(wc, wctrans("toupper")) == towupper(wc)
   It also ensures that
     towctrans(wc, wctrans("")) == wc
   which is not required by standard.
*/

static const struct {
  const char *name;
  wctrans_t val; } tmap[] = {
    {"tolower", _LOWER},
    {"toupper", _UPPER}
 };

#define	NTMAP	(sizeof tmap / sizeof tmap[0])

wctrans_t
wctrans (const char* property)
{
  int i;
  for ( i = 0; i < NTMAP; ++i )
    if (strcmp (property, tmap[i].name) == 0)
      return tmap[i].val;
   return 0;
}

wint_t towctrans (wint_t wc, wctrans_t desc)
{
  switch (desc)
    {
    case _LOWER:
      return towlower (wc);
    case _UPPER:
      return towupper (wc);
    default:
      return wc;
   }
}