1 #ifndef _RAR_UNICODE_
2 #define _RAR_UNICODE_
3 
4 #ifndef _EMX
5 #define MBFUNCTIONS
6 #endif
7 
8 #if defined(MBFUNCTIONS) || defined(_WIN_32) || defined(_EMX) && !defined(_DJGPP)
9 #define UNICODE_SUPPORTED
10 #endif
11 
12 #ifdef _WIN_32
13 #define DBCS_SUPPORTED
14 #endif
15 
16 #ifdef _EMX
17 int uni_init(int codepage);
18 int uni_done();
19 #endif
20 
21 bool WideToChar(const wchar *Src,char *Dest,size_t DestSize=0x1000000);
22 bool CharToWide(const char *Src,wchar *Dest,size_t DestSize=0x1000000);
23 byte* WideToRaw(const wchar *Src,byte *Dest,size_t DestSize=0x1000000);
24 wchar* RawToWide(const byte *Src,wchar *Dest,size_t DestSize=0x1000000);
25 void WideToUtf(const wchar *Src,char *Dest,size_t DestSize);
26 void UtfToWide(const char *Src,wchar *Dest,size_t DestSize);
27 bool UnicodeEnabled();
28 
29 size_t strlenw(const wchar *str);
30 wchar* strcpyw(wchar *dest,const wchar *src);
31 wchar* strncpyw(wchar *dest,const wchar *src,size_t n);
32 wchar* strcatw(wchar *dest,const wchar *src);
33 wchar* strncatw(wchar *dest,const wchar *src,size_t n);
34 int strcmpw(const wchar *s1,const wchar *s2);
35 int strncmpw(const wchar *s1,const wchar *s2,size_t n);
36 int stricmpw(const wchar *s1,const wchar *s2);
37 int strnicmpw(const wchar *s1,const wchar *s2,size_t n);
38 wchar *strchrw(const wchar *s,int c);
39 wchar* strrchrw(const wchar *s,int c);
40 wchar* strpbrkw(const wchar *s1,const wchar *s2);
41 wchar* strlowerw(wchar *Str);
42 wchar* strupperw(wchar *Str);
43 wchar* strdupw(const wchar *Str);
44 int toupperw(int ch);
45 int atoiw(const wchar *s);
46 
47 #ifdef DBCS_SUPPORTED
48 class SupportDBCS
49 {
50   public:
51     SupportDBCS();
52     void Init();
53 
54     char* charnext(const char *s);
55     size_t strlend(const char *s);
56     char *strchrd(const char *s, int c);
57     char *strrchrd(const char *s, int c);
58     void copychrd(char *dest,const char *src);
59 
60     bool IsLeadByte[256];
61     bool DBCSMode;
62 };
63 
64 extern SupportDBCS gdbcs;
65 
charnext(const char * s)66 inline char* charnext(const char *s) {return (char *)(gdbcs.DBCSMode ? gdbcs.charnext(s):s+1);}
strlend(const char * s)67 inline size_t strlend(const char *s) {return (uint)(gdbcs.DBCSMode ? gdbcs.strlend(s):strlen(s));}
strchrd(const char * s,int c)68 inline char* strchrd(const char *s, int c) {return (char *)(gdbcs.DBCSMode ? gdbcs.strchrd(s,c):strchr(s,c));}
strrchrd(const char * s,int c)69 inline char* strrchrd(const char *s, int c) {return (char *)(gdbcs.DBCSMode ? gdbcs.strrchrd(s,c):strrchr(s,c));}
copychrd(char * dest,const char * src)70 inline void copychrd(char *dest,const char *src) {if (gdbcs.DBCSMode) gdbcs.copychrd(dest,src); else *dest=*src;}
IsDBCSMode()71 inline bool IsDBCSMode() {return(gdbcs.DBCSMode);}
InitDBCS()72 inline void InitDBCS() {gdbcs.Init();}
73 
74 #else
75 #define charnext(s) ((s)+1)
76 #define strlend strlen
77 #define strchrd strchr
78 #define strrchrd strrchr
79 #define IsDBCSMode() (true)
copychrd(char * dest,const char * src)80 inline void copychrd(char *dest,const char *src) {*dest=*src;}
81 #endif
82 
83 #endif
84