Do you still have textual data stored in stacks made with Apple’s HyperCard? If you are planning to export this data to some kind of generic text files, you may also want to convert it from the Macintosh-specific MacRoman encoding to the universal UTF-8 encoding. You can accomplish this in a post-processing step with tools such as “iconv -f macintosh -t utf-8”, but you can as well do the conversion within HyperCard itself.
Here you can download the HyperCard XFCN “macroman2utf8()”, which takes one MacRoman-encoded, null-delimited string (i. e. a normal HyperCard string) as its argument and returns the same string in UTF-8 encoding. Non-ASCII characters will not be legible in HyperCard anymore, but if you write the string to a text file and then open that file with a UTF-8-aware application, everything will look fine again. To use the external function, do the following:
Download the file “macroman2utf8.hqx” and decode it with StuffIt Expander or a similar tool. (Mac OS X should already know how to handle it.)
Open the resulting file “macroman2utf8.rsrc” with a resource editor such as ResEdit or the Resource Mover that comes with HyperCard.
Copy the two contained resources (XFCN ID 128 and UTF8 ID 128) to the HyperCard stack that contains your text, to any other existing (possibly empty) stack (and then start using stack), or to the Home Stack (careful!).
You should now be ready to call the external function just like any other function, passing it one string as its argument.
answer macroman2utf8("¡Hällö!")
write "<customer>" & macroman2utf8(field "customer" of card i of this bg) & "</customer>" & newline to file "customers.xml"Note that this external function will only change the string encoding, but it will not transform Macintosh-style “Carriage Return” line breaks to Unix-Style “Line Feed” line breaks (or anything else). If you produce line breaks in a HyperTalk script, simply replace “return” by “newline” (or whatever you like).
A corresponding XFCN for text conversion to UTF-16 is not possible: UTF-16-encoded strings will frequently contain null bytes (e. g. the higher bytes of ordinary ASCII characters), but HyperCard always interprets null bytes as string terminators. Note that you cannot call numToChar(0) in HyperCard, either.
This page is valid XHTML — Last change: 2009-08-31 by Adrian Vogel <adrian.vogel@desy.de>