Справочник функций

Ваш аккаунт

Войти через: 
Забыли пароль?
Регистрация
Информацию о новых материалах можно получать и без регистрации:

Почтовая рассылка

Подписчиков: -1
Последний выпуск: 19.06.2015

Как перекодировать файл.

2.5K
05 декабря 2002 года
xIgor
2 / / 04.12.2002
Подскажите как можно реализовать перекодировку текста в заданную кодировку ,если известна исходная .
2.8K
08 декабря 2002 года
Raven
2 / / 07.12.2002
В принципе перекодировать файл достаточно просто, большую часть работы занимает расчёт таблиц перекодировки. Алгоритм следующий:(подходит для TRichEdit и TMemo)

...................
int SymbolCode, TextLength = RichEdit -> Text.Length();
//SymbolCode можно обьявить типа Byte
unsigned char* text1 = new char[TextLength+1];
//Коды символов должны быть положительными
char* text2 = new char[TextLength+1];
//unsigned char* в RichEdit не запихать
unsigned char Symbol;
strcpy(text1, RichEdit->Text.c_str());
strcpy(text2, RichEdit->Text.c_str());
...................
for (int i=0; i<TextLength; i++)
{
SymbolCode = text1;
text2 = DosToWinTable[SymbolCode];
//Здесь указать нужную таблицу
}
...................
RichEdit->Text = text2;

Вот мои таблицы перекодировки, но где то в одной из них, работающей с KOI8 есть глюк.

int DosToWinTable[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
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,127,
-64,-63,-62,-61,-60,-59,-58,-57,-56,-55,-54,-53,-52,-51,-50,-49,-48,-47,-46,-45,-44,-43,-42,-41,-40,-39,-38,-37,-36,-35,-34,-33,
-32,-31,-30,-29,-28,-27,-26,-25,-24,-23,-22,-21,-20,-19,-18,-17, 45, 45, 45,-90, 43,-90,-90,-84,-84,-90,-90,-84, 45, 45, 45,-84,
76, 43, 84, 43, 45, 43,-90,-90,-76, 45,-90,-84,-90,-61, 43,-90,-90, 84, 84, 76, 76, 45, 45, 43, 43, 45, 45, 45, 45,-90,-90,-45,
-16,-15,-14,-13,-12,-11,-10, -9, -8, -7, -6, -5, -4, -3, -2, -1,-88,-72,-86,-70,-81,-65,-95,-94,-80,-107,-73,-138,-71,-92,-90,-96};

int KoiToWinTable[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
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,127,
-106,-90, 63,-84, 63, 63,-122,-121, 63, 63,-121, 63, 63, 63, 63, 63, 63, 63, 63,-90, 63,-107, 63, 63, 63, 63,-96,-81,-80,-80,-73,-79,
61,-90, 63,-72, 63, 63,-84,-84,-84, 63, 63, 63, 63, 63, 63,-90,-90,-90,-90,-88,-90,-90, 63, 63, 63, 63, 63, 63,-121,-121,-121,-87,
-2,-32,-31,-10,-28,-27,-12,-29,-11,-24,-23,-22,-21,-20,-19,-18,-17, -1,-16,-15,-14,-13,-26,-30, -4, -5,-25, -8, -3, -7, -9, -6,
-34,-64,-33,-42,-60,-59,-44,-51,-43,-56,-55,-54,-53,-52,-51,-50,-49,-33,-48,-47,-46,-45,-58,-62,-36,-37,-57,-40,-35,-39,-41,-38};


int DosToKoiTable[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
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,127,
-31,-30, -9,-25,-28,-27,-10, -6,-23,-22,-21,-20,-19,-18,-17,-16,-14,-13,-12,-11,-26,-24,-29, -2, -5, -3, -1, -7, -8, -4,-32,-15,
-63,-62,-39,-57,-60,-59,-42,-38,-55,-54,-53,-52,-51,-50,-49,-48,-114,-113,-112,-111,-123,-78,-76,-89,-90,-75,-97,-88,-82,-83,-84,-125,
-124,-119,-120,-122,-128,-118,-81,-80,-85,-91,-69,-72,-79,-96,-66,-71,-70,-74,-73-86,-87,-94,-92,-67,-68,-123,-126,-115,-116,-114,-113,-117,
-46,-45,-44,-43,-58,-56,-60,-34,-37,-35,-33,-39,-40,-38,-64,-47,-77,-93,-106,-105,-104,-103,-101,-99,-100,-107,-98,-106,-99,-65,-108,-102};

int WinToKoiTable[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
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,127,
63, 63, 39, 63, 34, 58,-99,-99, 63, 37, 63, 60, 63, 63, 63, 63, 63, 39, 39, 34, 34, 7, 45, 45, 63, 84, 63, 62, 63, 63, 63, 63,
-102,-104,-103, 63,-65, 63,-108, 21,-77, 99,-65, 60,-88, 45, 82,-99,-98, 43, 73,105, 63,-97, 20,-98,-93,-65,-65, 62, 63, 63, 63,-65,
-31,-30, -9,-25,-28,-27,-10, -6,-23,-22,-21,-20,-19,-18,-17,-16,-14,-13,-12,-11,-26,-24,-29, -2, -5, -3, -1, -7, -8, -4,-32,-15,
-63,-62,-41,-57,-60,-59,-42,-38,-55,-54,-53,-52,-51,-50,-49,-48,-46,-45,-44,-43,-58,-56,-61,-34,-37,-35,-33,-39,-40,-38,-64,-47};

int KoiToDosTable[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
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,127,
-60,-77,-38,-65,-64,-39,-61,-77,-62,-63,-59,-33,-36,-37,-35,-34,-80,-79,-78,-77, -2, -7, -5,-51, 60, 62, -1,-77, -8, -8, -6, -5,
-51,-70,-43,-15,-42,-55,-72,-73,-69,-44,-45,-56,-66,-67,-68,-58,-57,-52,-75,-16,-74,-71,-47,-46,-53,-49,-48,-54,-40,-41,-50, -3,
-18,-96,-95,-26,-92,-91,-28,-93,-27,-88,-87,-86,-85,-84,-83,-82,-81,-17,-32,-31,-30,-29,-90,-94,-20,-21,-89,-24,-19,-23,-25,-22,
-98,-128,-127,-106,-124,-123,-108,-125,-107,-120,-119,-118,-117,-116,-115,-114,-113,-97,-112,-111,-110,-109,-122,-126,-100,-101,-121,-104,-99,-103,-105,-102};

int WinToDosTable[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
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,127,
63, 63, 39, 63, 34, 58,-59,-40, 63, 37, 63, 60, 63, 63, 63, 63, 63, 39, 39, 34, 34, 7, 45, 45, 63, 84, 63, 62, 63, 63, 63, 63,
-1,-10, -9, 63, -3, 63,-77, 21,-16, 99,-14, 60,-65, 45, 82,-12, -8, 43, 73,105, 63,-25, 20, -6,-15, -4,-13, 62, 63, 63, 63,-11,
-128,-127,-126,-125,-124,-123,-122,-121,-120,-119,-118,-117,-116,-115,-114,-113,-112,-111,-110,-109,-108,-107,-106,-105,-104,-103,-102,-101,-100, -99,-98,-97,
-96,-95,-94,-93,-92,-91,-90,-89,-88,-87,-86,-85,-84,-83,-82,-81,-32,-31,-30,-29,-28,-27,-26,-25,-24,-23,-22,-21,-20,-19,-18,-17};

Все таблицы содержат одинаковое начало в 128 символов, это сделано для оптимизации алгоритма по скорости. Текст размером ~1Mb обрабатывает примерно за секунду.
Реклама на сайте | Обмен ссылками | Ссылки | Экспорт (RSS) | Контакты
Добавить статью | Добавить исходник | Добавить хостинг-провайдера | Добавить сайт в каталог