@@ -63,7 +63,9 @@ extern MCExecContext *MCECptr;
6363// IM-2014-03-06: [[ revBrowserCEF ]] Add revision number to v0 external interface
6464// SN-2014-07-08: [[ UnicodeExternalsV0 ]] Bump revision number after unicode update
6565// AL-2015-02-06: [[ SB Inclusions ]] Increment revision number of v0 external interface
66- #define EXTERNAL_INTERFACE_VERSION 3
66+ // SN-2015-03-12: [[ Bug 14413 ]] Increment revision number, for the addition of
67+ // UTF-8 <-> native string functions.
68+ #define EXTERNAL_INTERFACE_VERSION 4
6769
6870typedef struct _Xternal
6971{
@@ -1718,6 +1720,46 @@ static char *resolve_symbol_in_module(const char *arg1, const char *arg2,
17181720 return nil;
17191721}
17201722
1723+ // //////////////////////////////////////////////////////////////////////////////
1724+ // V4: UTF-8 <-> Native string conversion
1725+ // arg1 contains the string to convert, for both of the functions.
1726+ static char *convert_from_native_to_utf8 (const char *arg1, const char *arg2,
1727+ const char *arg3, int *retval)
1728+ {
1729+ MCAutoStringRef t_input;
1730+ char * t_utf8_string;
1731+ if (arg1 == NULL
1732+ || !MCStringCreateWithNativeChars ((char_t *)arg1, strlen (arg1), &t_input)
1733+ || !MCStringConvertToUTF8String (*t_input, t_utf8_string))
1734+ {
1735+ *retval = xresFail;
1736+ return nil;
1737+ }
1738+
1739+ *retval = xresSucc;
1740+ return t_utf8_string;
1741+ }
1742+
1743+ static char *convert_to_native_from_utf8 (const char *arg1, const char *arg2,
1744+ const char *arg3, int *retval)
1745+ {
1746+ MCAutoStringRef t_input;
1747+ char *t_native_string;
1748+
1749+ if (arg1 == NULL
1750+ || !MCStringCreateWithBytes ((byte_t *)arg1, strlen (arg1), kMCStringEncodingUTF8 , false , &t_input)
1751+ || !MCStringConvertToCString (*t_input, t_native_string))
1752+ {
1753+ *retval = xresFail;
1754+ return nil;
1755+ }
1756+
1757+ *retval = xresSucc;
1758+ return t_native_string;
1759+ }
1760+
1761+ // //////////////////////////////////////////////////////////////////////////////
1762+
17211763// IM-2014-03-06: [[ revBrowserCEF ]] Add externals extension to the callback list
17221764// SN-2014-07-08: [[ UnicodeExternalsV0 ]] Add externals extension to handle UTF8-encoded parameters
17231765// AL-2015-02-06: [[ SB Inclusions ]] Add new callbacks for resource loading.
@@ -1788,6 +1830,9 @@ XCB MCcbs[] =
17881830 /* V3 */ unload_module,
17891831 /* V3 */ resolve_symbol_in_module,
17901832
1833+ /* V4 */ convert_from_native_to_utf8,
1834+ /* V4 */ convert_to_native_from_utf8,
1835+
17911836 NULL
17921837};
17931838
0 commit comments