ReactOS 0.4.15-dev-7918-g2a2556c
hanzen.c
Go to the documentation of this file.
1/*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS system libraries
4 * FILE: lib/sdk/crt/mbstring/hanzen.c
5 * PURPOSE: Multibyte conversion routines formerly called hantozen and zentohan
6 * PROGRAMER: Ariadne, Taiji Yamada
7 * UPDATE HISTORY:
8 Modified from Taiji Yamada japanese code system utilities
9 * 12/04/99: Created
10 */
11
12#include <precomp.h>
13#include <mbstring.h>
14#include <locale.h>
15
16/* Maps cp932 single byte character to multi byte character */
17static const unsigned char mbbtombc_932[] = {
18 0x40,0x49,0x68,0x94,0x90,0x93,0x95,0x66,0x69,0x6a,0x96,0x7b,0x43,0x7c,0x44,0x5e,
19 0x4f,0x50,0x51,0x52,0x53,0x54,0x55,0x56,0x57,0x58,0x46,0x47,0x83,0x81,0x84,0x48,
20 0x97,0x60,0x61,0x62,0x63,0x64,0x65,0x66,0x67,0x68,0x69,0x6a,0x6b,0x6c,0x6d,0x6e,
21 0x6f,0x70,0x71,0x72,0x73,0x74,0x75,0x76,0x77,0x78,0x79,0x6d,0x8f,0x6e,0x4f,0x76,
22 0x77,0x78,0x79,0x6d,0x8f,0x6e,0x4f,0x51,0x65,0x81,0x82,0x83,0x84,0x85,0x86,0x87,
23 0x88,0x89,0x8a,0x8b,0x8c,0x8d,0x8e,0x8f,0x90,0x91,0x92,0x93,0x94,0x95,0x50,
24 0x42,0x75,0x76,0x41,0x45,0x92,0x40,0x42,0x44,0x46,0x48,0x83,0x85,0x87,0x62,
25 0x5b,0x41,0x43,0x45,0x47,0x49,0x4a,0x4c,0x4e,0x50,0x52,0x54,0x56,0x58,0x5a,0x5c,
26 0x5e,0x60,0x63,0x65,0x67,0x69,0x6a,0x6b,0x6c,0x6d,0x6e,0x71,0x74,0x77,0x7a,0x7d,
27 0x7e,0x80,0x81,0x82,0x84,0x86,0x88,0x89,0x8a,0x8b,0x8c,0x8d,0x8f,0x93,0x4a,0x4b };
28
29/* Maps multibyte cp932 punctuation marks to single byte equivalents */
30static const unsigned char mbctombb_932_punct[] = {
31 0x20,0xa4,0xa1,0x2c,0x2e,0xa5,0x3a,0x3b,0x3f,0x21,0xde,0xdf,0x00,0x00,0x00,0x5e,
32 0x7e,0x5f,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xb0,0x00,0x00,0x2f,0x00,
33 0x00,0x00,0x7c,0x00,0x00,0x60,0x27,0x00,0x22,0x28,0x29,0x00,0x00,0x5b,0x5d,0x7b,
34 0x7d,0x00,0x00,0x00,0x00,0xa2,0xa3,0x00,0x00,0x00,0x00,0x2b,0x2d,0x00,0x00,0x00,
35 0x00,0x3d,0x00,0x3c,0x3e,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x5c,
36 0x24,0x00,0x00,0x25,0x23,0x26,0x2a,0x40};
37
38/* Maps multibyte cp932 hiragana/katakana to single-byte equivalents */
39static const unsigned char mbctombb_932_kana[] = {
40 0xa7,0xb1,0xa8,0xb2,0xa9,0xb3,0xaa,0xb4,0xab,0xb5,0xb6,0xb6,0xb7,0xb7,0xb8,0xb8,
41 0xb9,0xb9,0xba,0xba,0xbb,0xbb,0xbc,0xbc,0xbd,0xbd,0xbe,0xbe,0xbf,0xbf,0xc0,0xc0,
42 0xc1,0xc1,0xaf,0xc2,0xc2,0xc3,0xc3,0xc4,0xc4,0xc5,0xc6,0xc7,0xc8,0xc9,0xca,0xca,
43 0xca,0xcb,0xcb,0xcb,0xcc,0xcc,0xcc,0xcd,0xcd,0xcd,0xce,0xce,0xce,0xcf,0xd0,0xd1,
44 0xd2,0xd3,0xac,0xd4,0xad,0xd5,0xae,0xd6,0xd7,0xd8,0xd9,0xda,0xdb,0xdc,0xdc,0xb2,
45 0xb4,0xa6,0xdd,0xb3,0xb6,0xb9};
46
47/*********************************************************************
48 * _mbbtombc(MSVCRT.@)
49 */
50unsigned int __cdecl _mbbtombc(unsigned int c)
51{
52 if(get_mbcinfo()->mbcodepage == 932)
53 {
54 if(c >= 0x20 && c <= 0x7e) {
55 if((c >= 0x41 && c <= 0x5a) || (c >= 0x61 && c <= 0x7a) || (c >= 0x30 && c <= 0x39))
56 return mbbtombc_932[c - 0x20] | 0x8200;
57 else
58 return mbbtombc_932[c - 0x20] | 0x8100;
59 }
60 else if(c >= 0xa1 && c <= 0xdf) {
61 if(c >= 0xa6 && c <= 0xdd && c != 0xb0)
62 return mbbtombc_932[c - 0xa1 + 0x5f] | 0x8300;
63 else
64 return mbbtombc_932[c - 0xa1 + 0x5f] | 0x8100;
65 }
66 }
67 return c; /* not Japanese or no MB char */
68}
69
70 /*********************************************************************
71 * _mbctombb (MSVCRT.@)
72 */
73unsigned int CDECL _mbctombb(unsigned int c)
74{
75 unsigned int value;
76
77 if(get_mbcinfo()->mbcodepage == 932)
78 {
79 if(c >= 0x829f && c <= 0x82f1) /* Hiragana */
80 return mbctombb_932_kana[c - 0x829f];
81 if(c >= 0x8340 && c <= 0x8396 && c != 0x837f) /* Katakana */
82 return mbctombb_932_kana[c - 0x8340 - (c >= 0x837f ? 1 : 0)];
83 if(c >= 0x8140 && c <= 0x8197) /* Punctuation */
84 {
85 value = mbctombb_932_punct[c - 0x8140];
86 return value ? value : c;
87 }
88 if((c >= 0x824f && c <= 0x8258) || /* Fullwidth digits */
89 (c >= 0x8260 && c <= 0x8279)) /* Fullwidth capitals letters */
90 return c - 0x821f;
91 if(c >= 0x8281 && c <= 0x829a) /* Fullwidth small letters */
92 return c - 0x8220;
93 /* all other cases return c */
94 }
95 return c;
96}
97
98
99
#define __cdecl
Definition: accygwin.h:79
#define CDECL
Definition: compat.h:29
const GLubyte * c
Definition: glext.h:8905
static const unsigned char mbctombb_932_kana[]
Definition: hanzen.c:39
static const unsigned char mbctombb_932_punct[]
Definition: hanzen.c:30
unsigned int CDECL _mbctombb(unsigned int c)
Definition: hanzen.c:73
static const unsigned char mbbtombc_932[]
Definition: hanzen.c:17
unsigned int __cdecl _mbbtombc(unsigned int c)
Definition: hanzen.c:50
#define c
Definition: ke_i.h:80
MSVCRT_pthreadmbcinfo get_mbcinfo(void)
Definition: locale.c:364
Definition: pdh_main.c:94