Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -module(cpchange).
- -export([cp866_to_cp1251/1, cp1251_to_cp866/1, utf8_to_cp866/1, utf8_to_cp1251/1, cp1251_to_utf8/1, cp866_to_utf8/1]).
- %-compile(export_all).
- cp866_to_cp1251(Msg) ->
- convert({cp866, cp1251, Msg}).
- cp1251_to_cp866(Msg) ->
- % что, во что, сообщение
- convert({cp1251, cp866, Msg}).
- utf8_to_cp1251(Msg) ->
- convert({utf8, cp1251, Msg}).
- utf8_to_cp866(Msg) ->
- convert({utf8, cp866, Msg}).
- cp866_to_utf8(Msg) ->
- convert({cp866, utf8, Msg}).
- cp1251_to_utf8(Msg) ->
- convert({cp1251, utf8, Msg}).
- convert(Data) ->
- % №АБВГДЕЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯабвгдежзийклмнопрстуфхцчшщъыьэюяЁё откр" закр" (в cp866 открывающиесяи закрывающиеся кавычки отсутствуют) длинный- точкаСписка
- CP1251 = [185,192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223,224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255,168,184,171,187,151,149,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,9,10,13],
- CP866 = [252,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,240,241,60,62,196,254,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,9,10,13],
- UTF8 = [8470,1040,1041,1042,1043,1044,1045,1046,1047,1048,1049,1050,1051,1052,1053,1054,1055,1056,1057,1058,1059,1060,1061,1062,1063,1064,1065,1066,1067,1068,1069,1070,1071,1072,1073,1074,1075,1076,1077,1078,1079,1080,1081,1082,1083,1084,1085,1086,1087,1088,1089,1090,1091,1092,1093,1094,1095,1096,1097,1098,1099,1100,1101,1102,1103,1025,1105,171,187,8212,8226,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,9,10,13],
- case Data of
- % что, во что, сообщение
- {cp1251, cp866, Msg} ->
- F = fun(Val) -> lists:nth(string:chr(CP1251, Val), CP866) end,
- lists:map(F, Msg);
- {cp866, cp1251, Msg} ->
- F = fun(Val) -> lists:nth(string:chr(CP866, Val), CP1251) end,
- lists:map(F, Msg);
- {utf8, cp866, Msg} ->
- F = fun(Val) -> lists:nth(string:chr(UTF8, Val), CP866) end,
- lists:map(F, Msg);
- {utf8, cp1251, Msg} ->
- F = fun(Val) -> lists:nth(string:chr(UTF8, Val), CP1251) end,
- lists:map(F, Msg);
- {cp1251, utf8, Msg} ->
- F = fun(Val) -> lists:nth(string:chr(CP1251, Val), UTF8) end,
- lists:map(F, Msg);
- {cp866, utf8, Msg} ->
- F = fun(Val) -> lists:nth(string:chr(CP866, Val), UTF8) end,
- lists:map(F, Msg)
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement