@@ -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,50 @@ 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 a string owned by the engine, to avoid the release issue
1741+ MCExternalAddAllocatedString (MCexternalallocpool, t_utf8_string);
1742+ return t_utf8_string;
1743+ }
1744+
1745+ static char *convert_to_native_from_utf8 (const char *arg1, const char *arg2,
1746+ const char *arg3, int *retval)
1747+ {
1748+ MCAutoStringRef t_input;
1749+ char *t_native_string;
1750+
1751+ if (arg1 == NULL
1752+ || !MCStringCreateWithBytes ((byte_t *)arg1, strlen (arg1), kMCStringEncodingUTF8 , false , &t_input)
1753+ || !MCStringConvertToCString (*t_input, t_native_string))
1754+ {
1755+ *retval = xresFail;
1756+ return nil;
1757+ }
1758+
1759+ *retval = xresSucc;
1760+ // Return a string owned by the engine, to avoid the release issue
1761+ MCExternalAddAllocatedString (MCexternalallocpool, t_native_string);
1762+ return t_native_string;
1763+ }
1764+
1765+ // //////////////////////////////////////////////////////////////////////////////
1766+
17211767// IM-2014-03-06: [[ revBrowserCEF ]] Add externals extension to the callback list
17221768// SN-2014-07-08: [[ UnicodeExternalsV0 ]] Add externals extension to handle UTF8-encoded parameters
17231769// AL-2015-02-06: [[ SB Inclusions ]] Add new callbacks for resource loading.
@@ -1788,6 +1834,9 @@ XCB MCcbs[] =
17881834 /* V3 */ unload_module,
17891835 /* V3 */ resolve_symbol_in_module,
17901836
1837+ /* V4 */ convert_from_native_to_utf8,
1838+ /* V4 */ convert_to_native_from_utf8,
1839+
17911840 NULL
17921841};
17931842
0 commit comments