xref: /netbsd/lib/libc/locale/__wctoint.h (revision bf9ec67e)
1 /* $NetBSD: __wctoint.h,v 1.1 2001/09/28 11:25:37 yamt Exp $ */
2 
3 /*-
4  * Copyright (c)2001 Citrus Project,
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26  * SUCH DAMAGE.
27  *
28  *	$Citrus: xpg4dl/FreeBSD/lib/libc/locale/__wctoint.h,v 1.1 2001/09/21 13:52:32 yamt Exp $
29  */
30 
31 
32 __inline static int
33 __wctoint(wchar_t wc)
34 {
35 	int n;
36 
37 	/* XXX I expect compiler to optimize this. :D */
38 	switch (wc) {
39 	case L'0': n = 0; break;
40 	case L'1': n = 1; break;
41 	case L'2': n = 2; break;
42 	case L'3': n = 3; break;
43 	case L'4': n = 4; break;
44 	case L'5': n = 5; break;
45 	case L'6': n = 6; break;
46 	case L'7': n = 7; break;
47 	case L'8': n = 8; break;
48 	case L'9': n = 9; break;
49 	case L'A': case L'a': n = 10; break;
50 	case L'B': case L'b': n = 11; break;
51 	case L'C': case L'c': n = 12; break;
52 	case L'D': case L'd': n = 13; break;
53 	case L'E': case L'e': n = 14; break;
54 	case L'F': case L'f': n = 15; break;
55 	case L'G': case L'g': n = 16; break;
56 	case L'H': case L'h': n = 17; break;
57 	case L'I': case L'i': n = 18; break;
58 	case L'J': case L'j': n = 19; break;
59 	case L'K': case L'k': n = 20; break;
60 	case L'L': case L'l': n = 21; break;
61 	case L'M': case L'm': n = 22; break;
62 	case L'N': case L'n': n = 23; break;
63 	case L'O': case L'o': n = 24; break;
64 	case L'P': case L'p': n = 25; break;
65 	case L'Q': case L'q': n = 26; break;
66 	case L'R': case L'r': n = 27; break;
67 	case L'S': case L's': n = 28; break;
68 	case L'T': case L't': n = 29; break;
69 	case L'U': case L'u': n = 30; break;
70 	case L'V': case L'v': n = 31; break;
71 	case L'W': case L'w': n = 32; break;
72 	case L'X': case L'x': n = 33; break;
73 	case L'Y': case L'y': n = 34; break;
74 	case L'Z': case L'z': n = 35; break;
75 	default: n = -1; break; /* error */
76 	}
77 
78 	return n;
79 }
80