xref: /reactos/sdk/lib/crt/mbstring/jmstojis.c (revision c2c66aff)
1*c2c66affSColin Finck #include <precomp.h>
2*c2c66affSColin Finck #include <mbstring.h>
3*c2c66affSColin Finck #include <locale.h>
4*c2c66affSColin Finck 
5*c2c66affSColin Finck /*
6*c2c66affSColin Finck  * @implemented
7*c2c66affSColin Finck  */
_mbcjmstojis(unsigned int c)8*c2c66affSColin Finck unsigned int __cdecl _mbcjmstojis(unsigned int c)
9*c2c66affSColin Finck {
10*c2c66affSColin Finck   /* Conversion takes place only when codepage is 932.
11*c2c66affSColin Finck      In all other cases, c is returned unchanged */
12*c2c66affSColin Finck   if(get_mbcinfo()->mbcodepage == 932)
13*c2c66affSColin Finck   {
14*c2c66affSColin Finck     if(_ismbclegal(c) && HIBYTE(c) < 0xf0)
15*c2c66affSColin Finck     {
16*c2c66affSColin Finck       if(HIBYTE(c) >= 0xe0)
17*c2c66affSColin Finck         c -= 0x4000;
18*c2c66affSColin Finck 
19*c2c66affSColin Finck       c = (((HIBYTE(c) - 0x81)*2 + 0x21) << 8) | LOBYTE(c);
20*c2c66affSColin Finck 
21*c2c66affSColin Finck       if(LOBYTE(c) > 0x7f)
22*c2c66affSColin Finck         c -= 0x1;
23*c2c66affSColin Finck 
24*c2c66affSColin Finck       if(LOBYTE(c) > 0x9d)
25*c2c66affSColin Finck         c += 0x83;
26*c2c66affSColin Finck       else
27*c2c66affSColin Finck         c -= 0x1f;
28*c2c66affSColin Finck     }
29*c2c66affSColin Finck     else
30*c2c66affSColin Finck       return 0; /* Codepage is 932, but c can't be converted */
31*c2c66affSColin Finck   }
32*c2c66affSColin Finck 
33*c2c66affSColin Finck   return c;
34*c2c66affSColin Finck }
35