eid-viewer
eid-viewer library
Loading...
Searching...
No Matches
utftranslate.h
1#ifndef UTFTRANSLATE_H
2#define UTFTRANSLATE_H
3
4#ifndef WIN32
5#include <string.h>
6
7static inline char *f(const char *c, unsigned long *l)
8{
9 *l = strlen(c);
10 return strdup(c);
11}
12
13#define EID_STRCMP(x,y) strcmp(x,y)
14#define EID_STRTOL(x,y,z) strtol(x,y,z)
15#define EID_STRDUP(x) strdup(x)
16#define EID_STRLEN(x) strlen(x)
17#define EID_VSNPRINTF(str, size, string, ap) vsnprintf(str, size, string, ap)
18#define EID_FOPEN(filename, mode) fopen(filename, mode)
19typedef char EID_CHAR;
20
21#define UTF8TOEID(utf8string, len) f(utf8string, len)
22#define UTF8TOEID_L(utf8string, len, loc) strncpy((loc), (utf8string), *(len))
23#define EIDTOUTF8(eidstring, len) f(eidstring, len)
24#define EIDTOUTF8_L(eidstring, len, loc) strncpy((loc), (eidstring), *(len))
25#ifndef TEXT
26#define TEXT(string) string
27#endif
28#else
29#include <stdio.h>
30#include <Windows.h>
31
32//caller is responsible for freeing the returned string
33wchar_t *Utf8ToUtf16(const char *utf8string, unsigned long *utf16len,
34 wchar_t * buf);
35//caller is responsible for freeing the returned string
36char *Utf16ToUtf8(const wchar_t * utf16string, unsigned long *utf8len,
37 char *buf);
38
39
40#define EID_STRCMP(x,y) wcscmp(x,y)
41#define EID_STRTOL(x,y,z) wcstol(x,y,z)
42#define EID_STRDUP(x) _wcsdup(x)
43#define EID_STRLEN(x) wcslen(x)
44#define EID_VSNPRINTF(str, size, string, ap) _vsnwprintf(str, size, string, ap)
45#define EID_FOPEN(filename, mode) _wfopen(filename, mode)
46typedef wchar_t EID_CHAR;
47
48#define UTF8TOEID(utf8string, len) Utf8ToUtf16(utf8string, len, NULL)
49#define UTF8TOEID_L(utf8string, len, loc) Utf8ToUtf16(utf8string, len, loc)
50#define EIDTOUTF8(eidstring, len) Utf16ToUtf8(eidstring, len, NULL)
51#define EIDTOUTF8_L(eidstring, len, loc) Utf16ToUtf8(eidstring, len, loc)
52
53#endif //no WIN32
54
55#define EID_SAFE_FREE(pointer) if(pointer != NULL) {free(pointer); pointer=NULL;}
56
57#endif