• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * This file has no copyright assigned and is placed in the Public Domain.
3  * This file is part of the mingw-w64 runtime package.
4  * No warranty is given; refer to the file DISCLAIMER.PD within this package.
5  */
6 /*
7    wctrans.c
8    7.25.3.2 Extensible wide-character case mapping functions
9 
10    Contributed by: Danny Smith  <dannysmith@usesr.sourcefoge.net>
11    		   2005-02-24
12 
13   This source code is placed in the PUBLIC DOMAIN. It is modified
14   from the Q8 package created by Doug Gwyn <gwyn@arl.mil>
15 
16  */
17 
18 #include <string.h>
19 #include <wctype.h>
20 
21 /*
22    This differs from the MS implementation of wctrans which
23    returns 0 for tolower and 1 for toupper.  According to
24    C99, a 0 return value indicates invalid input.
25 
26    These two function go in the same translation unit so that we
27    can ensure that
28      towctrans(wc, wctrans("tolower")) == towlower(wc)
29      towctrans(wc, wctrans("toupper")) == towupper(wc)
30    It also ensures that
31      towctrans(wc, wctrans("")) == wc
32    which is not required by standard.
33 */
34 
35 static const struct {
36   const char *name;
37   wctrans_t val; } tmap[] = {
38     {"tolower", _LOWER},
39     {"toupper", _UPPER}
40  };
41 
42 #define	NTMAP	(sizeof tmap / sizeof tmap[0])
43 
44 wctrans_t
wctrans(const char * property)45 wctrans (const char* property)
46 {
47   int i;
48   for ( i = 0; i < (int) NTMAP; ++i )
49     if (strcmp (property, tmap[i].name) == 0)
50       return tmap[i].val;
51    return 0;
52 }
53 
towctrans(wint_t wc,wctrans_t desc)54 wint_t towctrans (wint_t wc, wctrans_t desc)
55 {
56   switch (desc)
57     {
58     case _LOWER:
59       return towlower (wc);
60     case _UPPER:
61       return towupper (wc);
62     default:
63       return wc;
64    }
65 }
66