@@ -36,6 +36,29 @@ char *string_to_utf8(const char *p_native_path)
3636 return t_utf8_path;
3737}
3838
39+ char *string_from_utf8 (const char *p_utf8_string)
40+ {
41+ int t_length;
42+ // Make sure that the length includes the NULL terminating char
43+ t_length = strlen (p_utf8_string) + 1 ;
44+
45+ WCHAR *t_utf16_path;
46+ t_utf16_path = (WCHAR *)malloc (sizeof (WCHAR ) * t_length);
47+ MultiByteToWideChar (CP_UTF8 , MB_PRECOMPOSED , p_utf8_string, t_length, t_utf16_path, t_length);
48+
49+ int t_native_length;
50+ t_native_length = WideCharToMultiByte (CP_ACP , 0 , t_utf16_path, t_length, NULL , 0 , NULL , NULL );
51+
52+ char *t_native_string;
53+ t_native_string = (char *)malloc (t_native_length);
54+
55+ WideCharToMultiByte (CP_ACP , 0 , t_utf16_path, t_length, t_native_string, t_native_length, NULL , NULL );
56+
57+ free (t_utf16_path);
58+
59+ return t_native_string;
60+ }
61+
3962char *os_path_to_native_utf8 (const char *p_path)
4063{
4164 char *t_native_path;
@@ -118,4 +141,37 @@ char *os_path_resolve(const char *p_native_path)
118141 char *cstr = strclone (p_native_path);
119142 cstr = os_path_to_native (cstr);
120143 return cstr;
121- }
144+ }
145+
146+
147+ // SN-2015-03-10:[[ Bug 14413 ]] Added UTF-8 conversion functions
148+
149+ // Parameters:
150+ // p_utf8_string : pointer to UTF-8 encoded string.
151+ // Returns:
152+ // a pointer to the native-encoded string. Must be freed by the caller
153+ // Semantics:
154+ // Converts a UTF-8 encoded srting into a Native string
155+ char *ConvertCStringFromUTF8ToNative (const char * p_utf8_path, int *r_success)
156+ {
157+ char *t_native_string;
158+ t_native_string = string_from_utf8 (p_utf8_path);
159+
160+ *r_success = t_native_string != NULL ;
161+ return t_native_string;
162+ }
163+
164+ // Parameters:
165+ // p_native_string : pointer to native-encoded string.
166+ // Returns:
167+ // a pointer to the UTF-8 encoded string. Must be freed by the caller
168+ // Semantics:
169+ // Converts a native srting into a UTF-8 encoded string
170+ char *ConvertCStringFromNativeToUTF8 (const char * p_native_string, int *r_success)
171+ {
172+ char *t_utf8_string;
173+ t_utf8_string = string_to_utf8 (p_native_string);
174+
175+ *r_success = t_utf8_string != NULL ;
176+ return t_utf8_string;
177+ }
0 commit comments