unicode.hpp 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. #ifndef _RAR_UNICODE_
  2. #define _RAR_UNICODE_
  3. #ifndef _EMX
  4. #define MBFUNCTIONS
  5. #endif
  6. #if defined(MBFUNCTIONS) || defined(_WIN_ALL) || defined(_EMX) && !defined(_DJGPP)
  7. #define UNICODE_SUPPORTED
  8. #endif
  9. #if !defined(SFX_MODULE) && (defined(_MSC_VER) || defined(__BORLANDC__))
  10. // If C_UNICODE_RTL is defined, we can use library Unicode functions like
  11. // wcscpy. Otherwise, for compatibility with old compilers or for removing
  12. // RTL to reduce SFX module size, we need need to use our own implementations.
  13. #define C_UNICODE_RTL
  14. #endif
  15. #ifdef _WIN_ALL
  16. #define DBCS_SUPPORTED
  17. #endif
  18. #ifdef _EMX
  19. int uni_init(int codepage);
  20. int uni_done();
  21. #endif
  22. #ifdef __BORLANDC__
  23. // Borland C++ Builder 5 uses the old style swprintf without the buffer size,
  24. // so we replace it with snwprintf in our custom sprintfw definition.
  25. #define sprintfw snwprintf
  26. #elif defined (__OpenBSD__)
  27. #define sprintfw(s,...) *(s)=0
  28. #else
  29. #define sprintfw swprintf
  30. #endif
  31. bool WideToChar(const wchar *Src,char *Dest,size_t DestSize=0x1000000);
  32. bool CharToWide(const char *Src,wchar *Dest,size_t DestSize=0x1000000);
  33. byte* WideToRaw(const wchar *Src,byte *Dest,size_t SrcSize=0x1000000);
  34. wchar* RawToWide(const byte *Src,wchar *Dest,size_t DestSize=0x1000000);
  35. void WideToUtf(const wchar *Src,char *Dest,size_t DestSize);
  36. void UtfToWide(const char *Src,wchar *Dest,size_t DestSize);
  37. bool UnicodeEnabled();
  38. int wcsicomp(const wchar *s1,const wchar *s2);
  39. int wcsnicomp(const wchar *s1,const wchar *s2,size_t n);
  40. wchar* wcslower(wchar *Str);
  41. wchar* wcsupper(wchar *Str);
  42. int toupperw(int ch);
  43. int tolowerw(int ch);
  44. int atoiw(const wchar *s);
  45. #ifdef DBCS_SUPPORTED
  46. class SupportDBCS
  47. {
  48. public:
  49. SupportDBCS();
  50. void Init();
  51. char* charnext(const char *s);
  52. size_t strlend(const char *s);
  53. char *strchrd(const char *s, int c);
  54. char *strrchrd(const char *s, int c);
  55. void copychrd(char *dest,const char *src);
  56. bool IsLeadByte[256];
  57. bool DBCSMode;
  58. };
  59. extern SupportDBCS gdbcs;
  60. inline char* charnext(const char *s) {return (char *)(gdbcs.DBCSMode ? gdbcs.charnext(s):s+1);}
  61. inline size_t strlend(const char *s) {return (uint)(gdbcs.DBCSMode ? gdbcs.strlend(s):strlen(s));}
  62. inline char* strchrd(const char *s, int c) {return (char *)(gdbcs.DBCSMode ? gdbcs.strchrd(s,c):strchr(s,c));}
  63. inline char* strrchrd(const char *s, int c) {return (char *)(gdbcs.DBCSMode ? gdbcs.strrchrd(s,c):strrchr(s,c));}
  64. inline void copychrd(char *dest,const char *src) {if (gdbcs.DBCSMode) gdbcs.copychrd(dest,src); else *dest=*src;}
  65. inline bool IsDBCSMode() {return(gdbcs.DBCSMode);}
  66. inline void InitDBCS() {gdbcs.Init();}
  67. #else
  68. #define charnext(s) ((s)+1)
  69. #define strlend strlen
  70. #define strchrd strchr
  71. #define strrchrd strrchr
  72. #define IsDBCSMode() (true)
  73. inline void copychrd(char *dest,const char *src) {*dest=*src;}
  74. #endif
  75. #endif