Skip to content

Commit 5820168

Browse files
committed
Encode {} as ≤≥.
Enhance koi7 to unicode table.
1 parent 886420e commit 5820168

File tree

1 file changed

+20
-38
lines changed

1 file changed

+20
-38
lines changed

encoding.cpp

Lines changed: 20 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,6 @@ static const unsigned short gost_to_unicode_lat[256] = {
6363
/* 130-137 */ 0x7c, 0x2015, 0x5f, 0x21, 0x22, 0x042a, 0xb0, 0x2032,
6464
};
6565

66-
static const char *koi7_to_utf8[32] = {
67-
/* 0140 */ "Ю", "А", "Б", "Ц", "Д", "Е", "Ф", "Г",
68-
/* 0150 */ "Х", "И", "Й", "К", "Л", "М", "Н", "О",
69-
/* 0160 */ "П", "Я", "Р", "С", "Т", "У", "Ж", "В",
70-
/* 0170 */ "Ь", "Ы", "З", "Ш", "Э", "Щ", "Ч", "Ъ",
71-
};
72-
7366
//
7467
// Convert character in GOST-10859 encoding to Unicode.
7568
//
@@ -172,21 +165,7 @@ unsigned utf8_to_unicode(const char **p)
172165
//
173166
void iso_putc(unsigned ch, std::ostream &out)
174167
{
175-
if (ch >= ' ' && ch < 0140) {
176-
// Latin
177-
out << (char)ch;
178-
} else if (ch >= 0140 && ch < 0200) {
179-
// Cyrillic
180-
out << koi7_to_utf8[ch - 0140];
181-
} else if (ch == '\5') {
182-
out << "Ъ";
183-
} else if (ch == '\1') {
184-
// Special
185-
out << "\n";
186-
} else {
187-
// Non-text
188-
out << '`';
189-
}
168+
utf8_putc(koi7_to_unicode[ch], out);
190169
}
191170

192171
//
@@ -213,7 +192,7 @@ unsigned char unicode_to_koi7(unsigned short val)
213192
/* `abcdefg */ 0, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, // ABCDEFG
214193
/* hijklmno */ 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, // HIJKLMNO
215194
/* pqrstuvw */ 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, // PQRSTUVW
216-
/* xyz{|}~ */ 0x58, 0x59, 0x5a, 0x5b, 0x5e, 0x5d, 0x1f, 0, // XYZ[|]¬
195+
/* xyz{|}~ */ 0x58, 0x59, 0x5a, 0x0e, 0x5e, 0x0f, 0x1f, 0, // XYZ≤|≥¬
217196
/* 80 - 87 */ 0, 0, 0, 0, 0, 0, 0, 0,
218197
/* 88 - 8f */ 0, 0, 0, 0, 0, 0, 0, 0,
219198
/* 90 - 97 */ 0, 0, 0, 0, 0, 0, 0, 0,
@@ -692,21 +671,24 @@ const unsigned char text_to_gost[64] = {
692671
};
693672

694673
const unsigned short koi7_to_unicode[128] = {
695-
0x00, 0x01, 0x02, 0x03, 0x04, 0x042a, 0x06, 0x07, 0x08, 0x09, 0x0a,
696-
0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15,
697-
0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
698-
699-
0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a,
700-
0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35,
701-
0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
702-
703-
0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a,
704-
0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x50, 0x51, 0x52, 0x53, 0x54, 0x55,
705-
0x56, 0x57, 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f,
706-
707-
0x042e, 0x0410, 0x0411, 0x0426, 0x0414, 0x0415, 0x0424, 0x0413, 0x0425, 0x0418, 0x0419,
708-
0x041a, 0x041b, 0x041c, 0x041d, 0x041e, 0x041f, 0x042f, 0x0420, 0x0421, 0x0422, 0x0423,
709-
0x0416, 0x0412, 0x042c, 0x042b, 0x0417, 0x0428, 0x042d, 0x0429, 0x0427, 0x7f,
674+
// clang-format off
675+
/* Ъ× */ 0, 0x01, 0x02, 0x03, 0x04, 0x042a, 0x06, 0xd7,
676+
/* ≤≥ */ 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x2264, 0x2265,
677+
/* ‘ ―↑⏨ */ 0x2018, 0x11, 0x12, 0x13, 0x14, 0x2015, 0x2191, 0x23E8,
678+
/* ≠°÷’⊃≡∨¬ */ 0x2260, 0xb0, 0xf7, 0x2019, 0x2283, 0x2261, 0x2228, 0xac,
679+
/* !"#$%&' */ 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
680+
/* ()*+,-./ */ 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
681+
/* 01234567 */ 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
682+
/* 89:;<=>? */ 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
683+
/* @ABCDEFG */ 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
684+
/* HIJKLMNO */ 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f,
685+
/* PQRSTUVW */ 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
686+
/* XYZ[\]^_ */ 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f,
687+
/* ЮAБЦДEФГ */ 0x042e, 0x0410, 0x0411, 0x0426, 0x0414, 0x0415, 0x0424, 0x0413,
688+
/* XИЙKЛMHO */ 0x0425, 0x0418, 0x0419, 0x041a, 0x041b, 0x041c, 0x041d, 0x041e,
689+
/* ПЯPCTYЖB */ 0x041f, 0x042f, 0x0420, 0x0421, 0x0422, 0x0423, 0x0416, 0x0412,
690+
/* ЬЫЗШЭЩЧ */ 0x042c, 0x042b, 0x0417, 0x0428, 0x042d, 0x0429, 0x0427, 0x7f,
691+
// clang-format on
710692
};
711693

712694
//

0 commit comments

Comments
 (0)