summaryrefslogtreecommitdiff
path: root/legacy/evil
diff options
context:
space:
mode:
authorVincent Torri <vincent.torri@gmail.com>2011-11-02 07:22:11 +0000
committerVincent Torri <vincent.torri@gmail.com>2011-11-02 07:22:11 +0000
commitc664467025c49217b3b49af65ca9fd61c4b551b7 (patch)
tree96740110868fe399c1222c4c32952910d48410e3 /legacy/evil
parent5e8176838615949171a7367085ae933b96509694 (diff)
* src/lib/evil_util.c:
* src/lib/evil_util.h: Add evil_utf16_to_utf8() function, display error messages and fix a bit the documentation of the other conversion functions. SVN revision: 64636
Diffstat (limited to 'legacy/evil')
-rw-r--r--legacy/evil/ChangeLog8
-rw-r--r--legacy/evil/src/lib/evil_util.c63
-rw-r--r--legacy/evil/src/lib/evil_util.h23
3 files changed, 88 insertions, 6 deletions
diff --git a/legacy/evil/ChangeLog b/legacy/evil/ChangeLog
index 325b1766de..07c2a8cc4a 100644
--- a/legacy/evil/ChangeLog
+++ b/legacy/evil/ChangeLog
@@ -1,3 +1,11 @@
12011-11-02 Vincent Torri <doursse at users dot sf dot net>
2
3 * src/lib/evil_util.c:
4 * src/lib/evil_util.h:
5 Add evil_utf16_to_utf8() function, display error messages
6 and fix a bit the documentation of the other conversion
7 functions.
8
12011-10-12 Vincent Torri <doursse at users dot sf dot net> 92011-10-12 Vincent Torri <doursse at users dot sf dot net>
2 10
3 * src/lib/evil_util.c: 11 * src/lib/evil_util.c:
diff --git a/legacy/evil/src/lib/evil_util.c b/legacy/evil/src/lib/evil_util.c
index 59c386ac11..1ffd9ba9f9 100644
--- a/legacy/evil/src/lib/evil_util.c
+++ b/legacy/evil/src/lib/evil_util.c
@@ -21,15 +21,26 @@ evil_char_to_wchar(const char *text)
21 wchar_t *wtext; 21 wchar_t *wtext;
22 int wsize; 22 int wsize;
23 23
24 if (!text)
25 return NULL;
26
24 wsize = MultiByteToWideChar(CP_ACP, 0, text, (int)strlen(text) + 1, NULL, 0); 27 wsize = MultiByteToWideChar(CP_ACP, 0, text, (int)strlen(text) + 1, NULL, 0);
25 if ((wsize == 0) || 28 if ((wsize == 0) ||
26 (wsize > (int)(ULONG_MAX / sizeof(wchar_t)))) 29 (wsize > (int)(ULONG_MAX / sizeof(wchar_t))))
27 return NULL; 30 {
31 if (wsize == 0)
32 _evil_last_error_display(__FUNCTION__);
33 return NULL;
34 }
28 35
29 wtext = malloc(wsize * sizeof(wchar_t)); 36 wtext = malloc(wsize * sizeof(wchar_t));
30 if (wtext) 37 if (wtext)
31 if (!MultiByteToWideChar(CP_ACP, 0, text, (int)strlen(text) + 1, wtext, wsize)) 38 if (!MultiByteToWideChar(CP_ACP, 0, text, (int)strlen(text) + 1, wtext, wsize))
32 return NULL; 39 {
40 if (wsize == 0)
41 _evil_last_error_display(__FUNCTION__);
42 return NULL;
43 }
33 44
34 return wtext; 45 return wtext;
35} 46}
@@ -40,9 +51,15 @@ evil_wchar_to_char(const wchar_t *text)
40 char *atext; 51 char *atext;
41 int asize; 52 int asize;
42 53
54 if (!text)
55 return NULL;
56
43 asize = WideCharToMultiByte(CP_ACP, 0, text, -1, NULL, 0, NULL, NULL); 57 asize = WideCharToMultiByte(CP_ACP, 0, text, -1, NULL, 0, NULL, NULL);
44 if (asize == 0) 58 if (asize == 0)
45 return NULL; 59 {
60 _evil_last_error_display(__FUNCTION__);
61 return NULL;
62 }
46 63
47 atext = (char*)malloc(asize * sizeof(char)); 64 atext = (char*)malloc(asize * sizeof(char));
48 if (!atext) 65 if (!atext)
@@ -50,12 +67,50 @@ evil_wchar_to_char(const wchar_t *text)
50 67
51 asize = WideCharToMultiByte(CP_ACP, 0, text, -1, atext, asize, NULL, NULL); 68 asize = WideCharToMultiByte(CP_ACP, 0, text, -1, atext, asize, NULL, NULL);
52 if (asize == 0) 69 if (asize == 0)
53 return NULL; 70 {
71 _evil_last_error_display(__FUNCTION__);
72 return NULL;
73 }
54 74
55 return atext; 75 return atext;
56} 76}
57 77
58char * 78char *
79evil_utf16_to_utf8(const wchar_t *text16)
80{
81 char *text8;
82 DWORD flag = 0;
83 int size8;
84
85 if (!text16)
86 return NULL;
87
88#if _WIN32_WINNT >= 0x0600
89 flag = WC_ERR_INVALID_CHARS;;
90#endif
91
92 size8 = WideCharToMultiByte(CP_UTF8, flag, text16, -1, NULL, 0, NULL, NULL);
93 if (size8 == 0)
94 {
95 _evil_last_error_display(__FUNCTION__);
96 return NULL;
97 }
98
99 text8 = (char*)malloc(size8 * sizeof(char));
100 if (!text8)
101 return NULL;
102
103 size8 = WideCharToMultiByte(CP_UTF8, flag, text16, -1, text8, size8, NULL, NULL);
104 if (size8 == 0)
105 {
106 _evil_last_error_display(__FUNCTION__);
107 return NULL;
108 }
109
110 return text8;
111}
112
113char *
59evil_format_message(long err) 114evil_format_message(long err)
60{ 115{
61 LPTSTR msg; 116 LPTSTR msg;
diff --git a/legacy/evil/src/lib/evil_util.h b/legacy/evil/src/lib/evil_util.h
index eaefdec225..0170dd0f2a 100644
--- a/legacy/evil/src/lib/evil_util.h
+++ b/legacy/evil/src/lib/evil_util.h
@@ -10,7 +10,7 @@
10 * 10 *
11 * Convert a string from char * to wchar_t * and return it. If the 11 * Convert a string from char * to wchar_t * and return it. If the
12 * allocation or conversion fails, NULL is returned. On success, the 12 * allocation or conversion fails, NULL is returned. On success, the
13 * returned value must be freed. 13 * returned value must be freed when it is not used anymore.
14 * 14 *
15 * Conformity: Non applicable. 15 * Conformity: Non applicable.
16 * 16 *
@@ -29,7 +29,7 @@ EAPI wchar_t *evil_char_to_wchar(const char *text);
29 * 29 *
30 * Convert a string from wchar_t * to char * and return it. If the 30 * Convert a string from wchar_t * to char * and return it. If the
31 * allocation or conversion fails, NULL is returned. On success, the 31 * allocation or conversion fails, NULL is returned. On success, the
32 * returned value must be freed. 32 * returned value must be freed when it is not used anymore.
33 * 33 *
34 * Conformity: Non applicable. 34 * Conformity: Non applicable.
35 * 35 *
@@ -40,6 +40,25 @@ EAPI wchar_t *evil_char_to_wchar(const char *text);
40 */ 40 */
41EAPI char *evil_wchar_to_char(const wchar_t *text); 41EAPI char *evil_wchar_to_char(const wchar_t *text);
42 42
43/**
44 * @brief Convert a string from UTF-16 to UTF-8.
45 *
46 * @param text The string to convert in UTF-16.
47 * @return The converted string in UTF-8.
48 *
49 * Convert a string from UTF-16 to UTF-8 and return it. If the
50 * allocation or conversion fails, NULL is returned. On success, the
51 * returned value must be freed when it is not used anymore.
52 *
53 * Conformity: Non applicable.
54 *
55 * Supported OS: Windows 95, Windows 98, Windows Me, Windows NT, Windows 2000,
56 * Windows XP.
57 *
58 * @ingroup Evil
59 */
60EAPI char *evil_utf16_to_utf8(const wchar_t *text);
61
43EAPI char *evil_format_message(long err); 62EAPI char *evil_format_message(long err);
44 63
45EAPI char *evil_last_error_get(void); 64EAPI char *evil_last_error_get(void);