/* Both conversions need this header */
#include <UnicodeConverter.h>

/* Prior to converting to OpenTTD encoding on LOAD */

UnicodeMapping *mapping = malloc(sizeof(UnicodeMapping));

mapping->unicodeEncoding = CreateTextEncoding(kTextEncodingUnicodeDefault, kUnicodeNoSubset, kUnicodeUTF8Format);
mapping->otherEncoding = CreateTextEncoding(kTextEncodingUnicodeDefault, kUnicodeHFSPlusCompVariant, kUnicodeUTF8Format);
mapping->mappingVersion = kUnicodeUseLatestMapping;

/* After converting from OpenTTD encoding on SAVE */

UnicodeMappingPtr mapping = malloc(sizeof(UnicodeMapping));

mapping->unicodeEncoding = CreateTextEncoding(kTextEncodingUnicodeDefault, kUnicodeNoSubset, kUnicodeUTF8Format);
mapping->otherEncoding = CreateTextEncoding(kTextEncodingUnicodeDefault, kUnicodeHFSPlusDecompVariant, kUnicodeUTF8Format);
mapping->mappingVersion = kUnicodeUseLatestMapping;

/* Both conversions use the following code after defining mapping. This assumes that unichar_string is the utf-8 string. Versions of the converter prior to 1.2.1 do not support this as a result.  We could make it support by not calling OpenTTDToUTF8 and instead calling OpenTTDToUnichar and UnicharToUTF8 separately, though these would subsequently need to be defined in the header file, and all instances of kUnicodeUTF8Format would need to be changed into kUnicode16BitFormat. Either of the functions here may return errors listed at http://developer.apple.com/documentation/Carbon/Reference/Text_Encodin_sion_Manager/tec_refchap/chapter_55.6_section_1.html#//apple_ref/doc/uid/TP30000123-DontLinkChapterID_6-RCM0098 */

UnicodeToTextInfo *texinfo = NULL;

CreateUnicodeToTextInfo(mapping, texinfo);
ConvertFromUnicodeToText(texinfo, unichar_size, (ConstUniCharArrayPtr)unichar_string, 0, 0, NULL, NULL, NULL, output_byte_size, *number_of_bytes_in_unichar_string_converted, *number_of_bytes_in_converted_stream, output_buffer);
DisposeUnicodeToTextInfo(texinfo);

