-- MAC <=> PC -- -- -- © June 2004, OpenSpark Interactive Ltd -- -- ---------------------------------------------------------------------- -- ConvertToWin(aString) and ConvertToMac(aString) can be used to -- convert Macintosh- and Unix-formatted strings to Windows format, -- and Windows- and Unix-formatted strings to Macintosh format. -- -- If the string contains no line breaks, and no format is defined, -- Macintosh format is assumed. Otherwise, the format can be -- detected automatically by the presence of ascii-10 or ascii-13 -- line break characters. The format can also be passed explicitly -- as a parameter. -- -- ConvertToXXX() maps high-ANSI characters to the platform-specific -- codes, and uses the appropriate line break character. -- ConvertToWin() can optionally return a string with RETURNs for -- line breaks, if the string is being imported. -- NOTE: The enabled handlers require PRegEx xtra, available from -- . Because this xtra is free, it is not -- registered as Shockwave-Safe. If you require this functionality -- in Shockwave, use the Lingo-only handlers (commented out). On a -- long ---------------------------------------------------------------------- on GetHighANSIStrings() ---------------------------------------------- -- OUTPUT: Returns a list with the format... -- [#mac: "ÄÅÇÉÑÖÜáàâäãåçéèêëíìîïñóòôöõúùûü...", -- #win: "ƒ¼«…—÷‹·‡‚‰„ÂÁÈËÍÎÌÏÓÔÒÛÚÙˆ¦²š¾¸..."] -- ... corresponding to the character mappings on Macintosh -- and Windows for the numToChar(128 - 255) -------------------------------------------------------------------- vWinString = "" vMacString = "" if (the platform starts "Mac") then vWinFontMap = [ \ 196, 197, 199, 201, 209, 214, 220, 225, 224, 226, 228, 227, 229, \ 231, 233, 232, 234, 235, 237, 236, 238, 239, 241, 243, 242, 244, \ 246, 245, 250, 249, 251, 252, 134, 176, 162, 163, 167, 149, 182, \ 223, 174, 169, 153, 180, 168, 141, 198, 216, 144, 177, 143, 142, \ 165, 181, 240, 221, 222, 254, 138, 170, 186, 253, 230, 248, 191, \ 161, 172, 175, 131, 188, 208, 171, 187, 133, 160, 192, 195, 213, \ 140, 156, 173, 151, 147, 148, 145, 146, 247, 215, 255, 159, 158, \ 164, 139, 155, 128, 129, 135, 183, 130, 132, 137, 194, 202, 193, \ 203, 200, 205, 206, 207, 204, 211, 212, 157, 210, 218, 219, 217, \ 166, 136, 152, 150, 154, 178, 190, 184, 189, 179, 185] repeat with i = 1 to 128 vNum = vWinFontMap[i] put numToChar(vNum) after vWinString put numToChar(i + 127) after vMacString end repeat else vMacFontMap = [ \ 219, 223, 226, 196, 227, 201, 160, 224, 246, 228, 186, 220, 206, \ 173, 179, 178, 176, 212, 213, 210, 211, 165, 248, 209, 247, 170, \ 249, 221, 207, 240, 218, 217, 202, 193, 162, 163, 219, 180, 245, \ 164, 172, 169, 187, 199, 194, 208, 168, 195, 161, 177, 250, 254, \ 171, 181, 166, 225, 252, 255, 188, 200, 197, 253, 251, 192, 203, \ 231, 229, 204, 128, 129, 174, 130, 233, 131, 230, 232, 237, 234, \ 235, 236, 198, 132, 241, 238, 239, 205, 133, 215, 175, 244, 242, \ 243, 134, 183, 184, 167, 136, 135, 137, 139, 138, 140, 190, 141, \ 143, 142, 144, 145, 147, 146, 148, 149, 182, 150, 152, 151, 153, \ 155, 154, 214, 191, 157, 156, 158, 159, 189, 185, 216] repeat with i = 1 to 128 vNum = vMacFontMap[i] put numToChar(vNum) after vMacString put numToChar(i + 127) after vWinString end repeat end if return [#mac: vMacString, #win: vWinString] end GetHighANSIStrings on ConvertToWin(aString) --------------------------------------------- -- INPUT: must be a string. This is expected to be in -- Macintosh format -- OUTPUT: Returns a string in Windows format. LineFeed characters -- will be added to the string after RETURN characters. -------------------------------------------------------------------- vStringList = list(aString) vStrings = GetHighANSIStrings() re_tr(vStringList, vStrings.mac, vStrings.win) re_s (vStringList, RETURN, "g", RETURN&numToChar(10)) return vStringList.getLast() end ConvertToWin on ConvertToMac(aString)--------------------------------------------- -- INPUT: must be a string. This is expected to be in -- Windows format -- OUTPUT: Returns a string in Macintosh format. LineFeed -- characters in the string will be deleted. -------------------------------------------------------------------- vStringList = list(aString) vStrings = GetHighANSIStrings() re_tr(vStringList, vStrings.win, vStrings.mac) re_s (vStringList, numToChar(10), "g", "") return vStringList.getLast() end ConvertToMac --on ConvertToWin(aString, aFormat, aImport) --------------------------- -- -- INPUT: should be a single-byte character string -- -- can be #win, #mac or #unix. If it is none of -- -- these, then the presence or absence of the characters -- -- ascii-10 and ascii-13 in the string will be used to -- -- detect the format of the string. If the string contains -- -- no line breaks, #mac format will be assumed. If aFormat -- -- is TRUE it will override aImport. -- -- has no effect unless it is TRUE, in which case -- -- Director-format RETURN characters are used for line -- -- breaks. -- -- ACTION: Maps high-ANSI characters from Mac format to PC format -- -- so that they display properly on a PC, and maps carriage -- -- return characters to RETURN&numToChar(10) -- -- OUTPUT: A string in Windows format -- -------------------------------------------------------------------- -- -- if stringP(aString) then -- -- Allow the Import flag to take the place of the Format symbol -- if aFormat = TRUE then -- aImport = TRUE -- end if -- -- -- Define the various line break characters -- tLF = numToChar(10) -- tCR = numToChar(13) -- tCRLF = tCR&tLF -- -- case aFormat of -- #win, #mac, #unix: -- -- Continue after the case statement -- -- otherwise: -- -- Auto-detect the string format based on line breaks -- -- if offset(tLF, aString) then -- -- Windows or Unix -- if offset(tCR, aString) then -- CRLF -- aFormat = #win -- else -- LF only -- aFormat = #unix -- end if -- else -- CR only -- aFormat = #mac -- end if -- end case -- -- if aFormat <> #win then -- tFontMap = WinFontMap() -- -- tTemp = aString -- aString = "" -- -- tCount = the number of chars in tTemp -- repeat with i = 1 to tCount -- tChar = tTemp.char[i] -- -- tCharNum = charToNum(tChar) -- case tCharNum of -- 10, 13: -- Line Feed on Unix (TextEdit), RETURN on Mac -- tChar = tCRLF -- -- otherwise: -- if tCharNum > 127 then -- and charNum < 256 then -- tChar = numToChar(tFontMap[tCharNum - 127]) -- end if -- end case -- -- put tChar after aString -- end repeat -- end if -- -- if aImport = TRUE then -- -- Director uses RETURN, not CRLF internally -- aString = ReplaceAll(aString, tCRLF, tCR) -- end if -- end if -- aString is a string -- -- return aString --end ConvertToWin -- -- -- --on ConvertToMac(aString, aFormat) ------------------------------------ -- -- INPUT: should be a single-byte character string -- -- can be #win, #mac or #unix. If it is none of -- -- these, then the presence or absence of the characters -- -- ascii-10 and ascii-13 in the string will be used to -- -- detect the format of the string. If the string contains -- -- no line breaks, #mac format will be assumed -- -- ACTION: Maps high-ANSI characters from PC format to Mac format -- -- so that they display properly on a Mac, and removes -- -- numToChar(10) line feed characters -- -------------------------------------------------------------------- -- -- if stringP(aString) then -- -- Define the various line break characters -- tLF = numToChar(10) -- tCR = numToChar(13) -- tCRLF = tCR&tLF -- -- case aFormat of -- #win, #mac, #unix: -- -- Continue after this case statement -- -- otherwise: -- -- Auto-detect the string format based on line breaks -- if offset(tLF, aString) then -- -- Windows or Unix -- if offset(tCR, aString) then -- CRLF -- aFormat = #win -- else -- LF only -- aFormat = #unix -- end if -- else -- CR only -- aFormat = #mac -- end if -- end case -- -- case aFormat of -- #mac: -- -- Leave the string as it is -- -- #unix: -- -- Convert line-breaks -- aString = ReplaceAll(aString, tLF, tCR) -- -- #win: -- -- Convert high-ANSI characters and line breaks -- tFontMap = WinFontMap() -- -- tTemp = aString -- aString = "" -- -- tCount = the number of chars in tTemp -- repeat with i = 1 to tCount -- tChar = tTemp.char[i] -- -- tCharNum = charToNum(tChar) -- if tCharNum = 10 then -- tChar = "" -- -- else if tCharNum > 127 and tCharNum < 256 then -- tChar = numToChar(127 + tFontMap.getPos(tCharNum)) -- end if -- -- put tChar after aString -- -- end repeat -- end case -- end if -- -- return aString --end ConvertToMac -- -- -- --on WinFontMap() ------------------------------------------------------ -- -- OUTPUT: Returns a list based on the data in Fontmap.txt. On Mac, -- -- the character numToChar(128) maps to numToChar(196) on -- -- PC. Item n in this list shows the PC mapping for n+127 -- -- on Mac. -- -- NOTE: Performance is slightly improved (<5%) if the list is -- -- created once and stored in a global, as indicated by the -- -- commented lines. -- -------------------------------------------------------------------- -- -- -- global gWinFontMap -- -- if voidP(gWinFontMap) then -- gWinFontMap = [ \ --196, 197, 199, 201, 209, 214, 220, 225, 224, 226, 228, 227, 229, \ --231, 233, 232, 234, 235, 237, 236, 238, 239, 241, 243, 242, 244, \ --246, 245, 250, 249, 251, 252, 134, 176, 162, 163, 167, 149, 182, \ --223, 174, 169, 153, 180, 168, 141, 198, 216, 144, 177, 143, 142, \ --165, 181, 240, 221, 222, 254, 138, 170, 186, 253, 230, 248, 191, \ --161, 172, 175, 131, 188, 208, 171, 187, 133, 160, 192, 195, 213, \ --140, 156, 173, 151, 147, 148, 145, 146, 247, 215, 255, 159, 158, \ --164, 139, 155, 128, 129, 135, 183, 130, 132, 137, 194, 202, 193, \ --203, 200, 205, 206, 207, 204, 211, 212, 157, 210, 218, 219, 217, \ --166, 136, 152, 150, 154, 178, 190, 184, 189, 179, 185] -- -- end if -- -- return gWinFontMap --end WinFontMap -- -- -- --on ReplaceAll(aString, aSubString, aReplacement) --------------------- -- -- INPUT: is the main string to search in -- -- is a string which may appear in -- -- is a string which is to replace all -- -- occurrences of in -- -- OUTPUT: returns an updated version of where all -- -- occurrences of have been replaced by -- -- -- -------------------------------------------------------------------- -- -- if aSubString = "" then -- return aString -- end if -- -- tTreatedString = "" -- tLengthAdjust = the number of chars of aSubString - 1 -- -- repeat while TRUE -- tOffset = offset(aSubString, aString) -- if tOffset then -- if tOffset - 1 then -- put chars(aString, 1, (tOffset - 1)) after tTreatedString -- end if -- -- put aReplacement after tTreatedString -- delete char 1 to (tOffset + tLengthAdjust) of aString -- -- else -- there are no more occurrences -- put aString after tTreatedString -- return tTreatedString -- end if -- -- end repeat --end ReplaceAll