Ces fonctions permettent de convertir des chaînes de caratères du format Windows au format Macintosh et vice-versa.
ConvertStringRE() est la fonction la plus rapide, mais elle nécessite l' Xtra PRegEx (gratuit, Windows, Macinthosh). ConvertString() fait la même chose sans Xtra, elle est donc plus lente BuildHexTables() est un utilitaire pour générer les tables de conversion utilisées par ConvertStringRE(). Cette fonction n'est pas nécessaire pour l'exécution des deux premières.
-- Convertit une chaine de caractère encodée pour mac en windows et vice-versa.
-- Utilise l'xtra PRegEx pour un résultat plus rapide que ConvertString (mesuré entre 10x pour des chaines courtes et 60x pour des longues)
--
-- string: la chaine à convertir
-- direction: #WinToMac ou #MacToWin ou void
--
-- Si la direction n'est pas spécifiée, on assume une conversion vers la plateforme courante
--
-- Pierre Rossel, 18.01.2007
--
-- Si vous améliorez ou corrigez ce script, merci de m'en tenir au courant.
-- Adresse de contact dispo sur http://www.prossel.com
--
on ConvertStringRE string, direction
if voidP(direction) then
if the platform contains "Windows" then
direction = #MacToWin
else
direction = #WinToMac
end if
end if
if direction = #MacToWin then
-- For #MacToWin:
sInputTable = "\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8A\x8B\x8C\x8D\x8E\x8F\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9A\x9B\x9C\x9D\x9E\x9F\xA0\xA1\xA4\xA5\xA6\xA7\xA8\xAA\xAB\xAC\xAD\xAE\xAF\xB0\xB2\xB3\xB4\xB6\xB7\xB8\xB9\xBA\xBB\xBC\xBD\xBE\xBF\xC0\xC1\xC2\xC3\xC4\xC5\xC6\xC7\xC8\xC9\xCA\xCB\xCC\xCD\xCE\xCF\xD0\xD1\xD2\xD3\xD4\xD5\xD6\xD8\xD9\xDA\xDB\xDC\xDD\xDE\xDF\xE0\xE1\xE2\xE3\xE4\xE5\xE6\xE7\xE8\xE9\xEA\xEB\xEC\xED\xEE\xEF\xF0\xF1\xF2\xF3\xF4\xF5\xF6\xF7\xF8\xF9\xFA\xFB\xFC\xFD\xFE\xFF"
sOutputTable = "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x91\x92\x93\x94\x95\x96\x97\x98\x99\x9A\x9B\x9C\x9D\x9E\x9F\xA0\xA1\xA4\xA5\xA6\xA7\xA8\xAA\xAB\xAC\xAD\xAE\xAF\xB0\xB2\xB3\xB4\xB6\xB7\xB8\xB9\xBA\xBB\xBC\xBD\xBE\xBF\xC0\xC1\xC2\xC3\xC4\xC5\xC6\xC7\xC8\xC9\xCA\xCB\xCC\xCD\xCE\xCF\xD0\xD1\xD2\xD3\xD4\xD5\xD6\xD8\xD9\xDA\xDB\xDC\xDD\xDE\xDF\xE0\xE1\xE2\xE3\xE4\xE5\xE6\xE7\xE8\xE9\xEA\xEB\xEC\xED\xEE\xEF\xF0\xF1\xF2\xF3\xF4\xF5\xF6\xF7\xF8\xF9\xFA\xFB\xFC\xFD\xFE\xFF"
end if
lstStr = [string]
--nReplace = PRegEx_Translate(lstStr, "abc", "ABC")
--nReplace = PRegEx_Translate(lstStr, "\x61\x62\x63", "\x41\x42\x43")
nReplace = PRegEx_Translate(lstStr, sInputTable, sOutputTable)
return lstStr[1]
end
-- Utilitaire servant à générer les chaines sInputTable et sOutputTable utilisées par ConvertStringRE,
-- à partir des tables pConvertList de ConvertString
-- Utilisation: appleler BuildHexTables() dans la fenêtre de messages et copier coller les deux blocs dans ConvertStringRE
--
-- Pierre Rossel, 18.01.2007
on BuildHexTables pConvertList
if voidP(pConvertList) then
pConvertList = \
[ 128: 196, 129: 197, 130: 199, 131: 201, 132: 209, 133: 214, 134: 220,\
135: 225, 136: 224, 137: 226, 138: 228, 139: 227, 140: 229, 141: 231,\
142: 233, 143: 232, 144: 234, 145: 235, 146: 237, 147: 236, 148: 238,\
149: 239, 150: 241, 151: 243, 152: 242, 153: 244, 154: 246, 155: 245,\
156: 250, 157: 249, 158: 251, 159: 252, 160: 134, 161: 176, 164: 167,\
165: 149, 166: 182, 167: 223, 168: 174, 170: 153, 171: 180, 172: 168,\
173: 141, 174: 198, 175: 216, 176: 144, 178: 143, 179: 142, 180: 165,\
182: 240, 183: 221, 184: 222, 185: 254, 186: 138, 187: 170, 188: 186,\
189: 253, 190: 230, 191: 248, 192: 191, 193: 161, 194: 172, 195: 175,\
196: 131, 197: 188, 198: 208, 199: 171, 200: 187, 201: 133, 202: 160,\
203: 192, 204: 195, 205: 213, 206: 140, 207: 156, 208: 173, 209: 151,\
210: 147, 211: 148, 212: 145, 213: 146, 214: 247, 216: 255, 217: 159,\
218: 158, 219: 164, 220: 139, 221: 155, 222: 128, 223: 129, 224: 135,\
225: 183, 226: 130, 227: 132, 228: 137, 229: 194, 230: 202, 231: 193,\
232: 203, 233: 200, 234: 205, 235: 206, 236: 207, 237: 204, 238: 211,\
239: 212, 240: 157, 241: 210, 242: 218, 243: 219, 244: 217, 245: 166,\
246: 136, 247: 152, 248: 150, 249: 154, 250: 178, 251: 190, 252: 184,\
253: 189, 254: 179, 255: 185 ]
put "-- For #MacToWin:" & RETURN & BuildHexTables(pConvertList)
pConvertList = \
[ 196: 128, 197: 129, 199: 130, 201: 131, 209: 132, 214: 133, 220: 134,\
225: 135, 224: 136, 226: 137, 228: 138, 227: 139, 229: 140, 231: 141,\
233: 142, 232: 143, 234: 144, 235: 145, 237: 146, 236: 147, 238: 148,\
239: 149, 241: 150, 243: 151, 242: 152, 244: 153, 246: 154, 245: 155,\
250: 156, 249: 157, 251: 158, 252: 159, 134: 160, 176: 161, 167: 164,\
149: 165, 182: 166, 223: 167, 174: 168, 153: 170, 180: 171, 168: 172,\
141: 173, 198: 174, 216: 175, 144: 176, 143: 178, 142: 179, 165: 180,\
240: 182, 221: 183, 222: 184, 254: 185, 138: 186, 170: 187, 186: 188,\
253: 189, 230: 190, 248: 191, 191: 192, 161: 193, 172: 194, 175: 195,\
131: 196, 188: 197, 208: 198, 171: 199, 187: 200, 133: 201, 160: 202,\
192: 203, 195: 204, 213: 205, 140: 206, 156: 207, 173: 208, 151: 209,\
147: 210, 148: 211, 145: 212, 146: 213, 247: 214, 255: 216, 159: 217,\
158: 218, 164: 219, 139: 220, 155: 221, 128: 222, 129: 223, 135: 224,\
183: 225, 130: 226, 132: 227, 137: 228, 194: 229, 202: 230, 193: 231,\
203: 232, 200: 233, 205: 234, 206: 235, 207: 236, 204: 237, 211: 238,\
212: 239, 157: 240, 210: 241, 218: 242, 219: 243, 217: 244, 166: 245,\
136: 246, 152: 247, 150: 248, 154: 249, 178: 250, 190: 251, 184: 252,\
189: 253, 179: 254, 185: 255 ]
put "-- For #WinToMac:" & RETURN & BuildHexTables(pConvertList)
return
end if
sInput = ""
sOutput = ""
nProps = pConvertList.count
repeat with iProp = 1 to nProps
put "\x" & dh(pConvertList.getPropAt(iProp)) after sInput
put "\x" & dh(pConvertList.getAt(iProp)) after sOutput
end repeat
return "sInputTable = " & QUOTE & sInput & QUOTE & RETURN &\
"sOutputTable = " & QUOTE & sOutput & QUOTE
end
-- Convertit une chaine de caractère encodée pour mac en windows et vice-versa.
--
-- string: la chaine à convertir
-- direction: #WinToMac ou #MacToWin ou void
--
-- Si la direction n'est pas spécifiée, on assume une conversion vers la plateforme courante
--
-- Pierre Rossel, 18.01.2004
--
-- Si vous améliorez ou corrigez ce script, merci de m'en tenir au courant.
-- Adresse de contact dispo sur http://www.prossel.com
--
on ConvertString string, direction
if voidP(direction) then
if the platform contains "Windows" then
direction = #MacToWin
else
direction = #WinToMac
end if
end if
if direction = #MacToWin then
-- mac: win
pConvertList = \
[ 128: 196, 129: 197, 130: 199, 131: 201, 132: 209, 133: 214, 134: 220,\
135: 225, 136: 224, 137: 226, 138: 228, 139: 227, 140: 229, 141: 231,\
142: 233, 143: 232, 144: 234, 145: 235, 146: 237, 147: 236, 148: 238,\
149: 239, 150: 241, 151: 243, 152: 242, 153: 244, 154: 246, 155: 245,\
156: 250, 157: 249, 158: 251, 159: 252, 160: 134, 161: 176, 164: 167,\
165: 149, 166: 182, 167: 223, 168: 174, 170: 153, 171: 180, 172: 168,\
173: 141, 174: 198, 175: 216, 176: 144, 178: 143, 179: 142, 180: 165,\
182: 240, 183: 221, 184: 222, 185: 254, 186: 138, 187: 170, 188: 186,\
189: 253, 190: 230, 191: 248, 192: 191, 193: 161, 194: 172, 195: 175,\
196: 131, 197: 188, 198: 208, 199: 171, 200: 187, 201: 133, 202: 160,\
203: 192, 204: 195, 205: 213, 206: 140, 207: 156, 208: 173, 209: 151,\
210: 147, 211: 148, 212: 145, 213: 146, 214: 247, 216: 255, 217: 159,\
218: 158, 219: 164, 220: 139, 221: 155, 222: 128, 223: 129, 224: 135,\
225: 183, 226: 130, 227: 132, 228: 137, 229: 194, 230: 202, 231: 193,\
232: 203, 233: 200, 234: 205, 235: 206, 236: 207, 237: 204, 238: 211,\
239: 212, 240: 157, 241: 210, 242: 218, 243: 219, 244: 217, 245: 166,\
246: 136, 247: 152, 248: 150, 249: 154, 250: 178, 251: 190, 252: 184,\
253: 189, 254: 179, 255: 185 ]
else
-- win: mac
pConvertList = \
[ 196: 128, 197: 129, 199: 130, 201: 131, 209: 132, 214: 133, 220: 134,\
225: 135, 224: 136, 226: 137, 228: 138, 227: 139, 229: 140, 231: 141,\
233: 142, 232: 143, 234: 144, 235: 145, 237: 146, 236: 147, 238: 148,\
239: 149, 241: 150, 243: 151, 242: 152, 244: 153, 246: 154, 245: 155,\
250: 156, 249: 157, 251: 158, 252: 159, 134: 160, 176: 161, 167: 164,\
149: 165, 182: 166, 223: 167, 174: 168, 153: 170, 180: 171, 168: 172,\
141: 173, 198: 174, 216: 175, 144: 176, 143: 178, 142: 179, 165: 180,\
240: 182, 221: 183, 222: 184, 254: 185, 138: 186, 170: 187, 186: 188,\
253: 189, 230: 190, 248: 191, 191: 192, 161: 193, 172: 194, 175: 195,\
131: 196, 188: 197, 208: 198, 171: 199, 187: 200, 133: 201, 160: 202,\
192: 203, 195: 204, 213: 205, 140: 206, 156: 207, 173: 208, 151: 209,\
147: 210, 148: 211, 145: 212, 146: 213, 247: 214, 255: 216, 159: 217,\
158: 218, 164: 219, 139: 220, 155: 221, 128: 222, 129: 223, 135: 224,\
183: 225, 130: 226, 132: 227, 137: 228, 194: 229, 202: 230, 193: 231,\
203: 232, 200: 233, 205: 234, 206: 235, 207: 236, 204: 237, 211: 238,\
212: 239, 157: 240, 210: 241, 218: 242, 219: 243, 217: 244, 166: 245,\
136: 246, 152: 247, 150: 248, 154: 249, 178: 250, 190: 251, 184: 252,\
189: 253, 179: 254, 185: 255 ]
end if
len = string.length
repeat with i = 1 to len
num = pConvertList.GetAProp(CharToNum(char i of string))
if not voidP(num) then
put NumToChar(num) into char i of string
end if
end repeat
return string
end