kodi
NptWinRtUtils.h
1 /*****************************************************************
2 |
3 | Neptune - WinRT Utilities
4 |
5 | (c) 2001-2012 Gilles Boccon-Gibod
6 | Author: Gilles Boccon-Gibod (bok@bok.net)
7 |
8  ****************************************************************/
9 
10 /*----------------------------------------------------------------------
11  | NPT_WinRtUtils
12  +---------------------------------------------------------------------*/
14 public:
15  // unicode/ascii conversion
16  static LPWSTR A2WHelper(LPWSTR lpw, LPCSTR lpa, int nChars, UINT acp);
17  static LPSTR W2AHelper(LPSTR lpa, LPCWSTR lpw, int nChars, UINT acp);
18  static size_t LStrLenW(STRSAFE_LPCWSTR lpw);
19 };
20 
21 /*----------------------------------------------------------------------
22 | macros
23 +---------------------------------------------------------------------*/
24 /* UNICODE support */
25 #define NPT_WINRT_USE_CHAR_CONVERSION int _convert = 0; LPCWSTR _lpw = NULL; LPCSTR _lpa = NULL
26 
27 #define NPT_WINRT_A2W(lpa) (\
28  ((_lpa = lpa) == NULL) ? NULL : (\
29  _convert = (int)(strlen(_lpa)+1),\
30  (INT_MAX/2<_convert)? NULL : \
31  NPT_WinRtUtils::A2WHelper((LPWSTR) alloca(_convert*sizeof(WCHAR)), _lpa, _convert, CP_UTF8)))
32 
33 /* +2 instead of +1 temporary fix for Chinese characters */
34 #define NPT_WINRT_W2A(lpw) (\
35  ((_lpw = lpw) == NULL) ? NULL : (\
36  (_convert = (NPT_WinRtUtils::LStrLenW(_lpw)+2), \
37  (_convert>INT_MAX/2) ? NULL : \
38  NPT_WinRtUtils::W2AHelper((LPSTR) alloca(_convert*sizeof(WCHAR)), _lpw, _convert*sizeof(WCHAR), CP_UTF8))))
39 
Definition: NptWinRtUtils.h:13