1use std::borrow::Cow;
4use crate::{
5 decoder::{self, incomplete::decode_helper, UTF8Entry, UTF8Len},
6 encoder::Encoder, CodePage, DecodeError, EncodeError,
7};
8impl CP1253 {
9 #[inline(always)]
21 pub fn decode(self, bytes: &[u8]) -> Result<Cow<str>, DecodeError> {
22 decode_helper(&DECODE_TABLE, bytes, None)
23 }
24 #[inline(always)]
36 pub fn decode_lossy(self, bytes: &[u8]) -> Cow<str> {
37 decode_helper(&DECODE_TABLE, bytes, Some('�')).unwrap()
38 }
39 #[inline(always)]
54 pub fn decode_lossy_fallback(self, bytes: &[u8], fallback: char) -> Cow<str> {
55 decode_helper(&DECODE_TABLE, bytes, Some(fallback)).unwrap()
56 }
57 #[inline(always)]
71 pub fn encode(self, s: &str) -> Result<Cow<[u8]>, EncodeError> {
72 self.encode_helper(s, None)
73 }
74 #[inline(always)]
86 pub fn encode_lossy(self, s: &str, fallback: u8) -> Cow<[u8]> {
87 self.encode_helper(s, Some(fallback)).unwrap()
88 }
89}
90#[derive(Copy, Clone)]
91pub struct CP1253;
92impl CodePage for CP1253 {
93 #[inline(always)]
94 fn decode<'a>(&self, bytes: &'a [u8]) -> Result<Cow<'a, str>, DecodeError> {
95 (*self).decode(bytes)
96 }
97 #[inline(always)]
98 fn decode_lossy<'a>(&self, bytes: &'a [u8]) -> Cow<'a, str> {
99 (*self).decode_lossy(bytes)
100 }
101 #[inline(always)]
105 fn decode_lossy_fallback<'a>(
106 &self,
107 bytes: &'a [u8],
108 fallback: char,
109 ) -> Cow<'a, str> {
110 (*self).decode_lossy_fallback(bytes, fallback)
111 }
112}
113const DECODE_TABLE: decoder::incomplete::Table = [
114 Some(UTF8Entry {
115 buf: [0x0, 0x0, 0x0],
116 len: UTF8Len::One,
117 }),
118 Some(UTF8Entry {
119 buf: [0x1, 0x0, 0x0],
120 len: UTF8Len::One,
121 }),
122 Some(UTF8Entry {
123 buf: [0x2, 0x0, 0x0],
124 len: UTF8Len::One,
125 }),
126 Some(UTF8Entry {
127 buf: [0x3, 0x0, 0x0],
128 len: UTF8Len::One,
129 }),
130 Some(UTF8Entry {
131 buf: [0x4, 0x0, 0x0],
132 len: UTF8Len::One,
133 }),
134 Some(UTF8Entry {
135 buf: [0x5, 0x0, 0x0],
136 len: UTF8Len::One,
137 }),
138 Some(UTF8Entry {
139 buf: [0x6, 0x0, 0x0],
140 len: UTF8Len::One,
141 }),
142 Some(UTF8Entry {
143 buf: [0x7, 0x0, 0x0],
144 len: UTF8Len::One,
145 }),
146 Some(UTF8Entry {
147 buf: [0x8, 0x0, 0x0],
148 len: UTF8Len::One,
149 }),
150 Some(UTF8Entry {
151 buf: [0x9, 0x0, 0x0],
152 len: UTF8Len::One,
153 }),
154 Some(UTF8Entry {
155 buf: [0xA, 0x0, 0x0],
156 len: UTF8Len::One,
157 }),
158 Some(UTF8Entry {
159 buf: [0xB, 0x0, 0x0],
160 len: UTF8Len::One,
161 }),
162 Some(UTF8Entry {
163 buf: [0xC, 0x0, 0x0],
164 len: UTF8Len::One,
165 }),
166 Some(UTF8Entry {
167 buf: [0xD, 0x0, 0x0],
168 len: UTF8Len::One,
169 }),
170 Some(UTF8Entry {
171 buf: [0xE, 0x0, 0x0],
172 len: UTF8Len::One,
173 }),
174 Some(UTF8Entry {
175 buf: [0xF, 0x0, 0x0],
176 len: UTF8Len::One,
177 }),
178 Some(UTF8Entry {
179 buf: [0x10, 0x0, 0x0],
180 len: UTF8Len::One,
181 }),
182 Some(UTF8Entry {
183 buf: [0x11, 0x0, 0x0],
184 len: UTF8Len::One,
185 }),
186 Some(UTF8Entry {
187 buf: [0x12, 0x0, 0x0],
188 len: UTF8Len::One,
189 }),
190 Some(UTF8Entry {
191 buf: [0x13, 0x0, 0x0],
192 len: UTF8Len::One,
193 }),
194 Some(UTF8Entry {
195 buf: [0x14, 0x0, 0x0],
196 len: UTF8Len::One,
197 }),
198 Some(UTF8Entry {
199 buf: [0x15, 0x0, 0x0],
200 len: UTF8Len::One,
201 }),
202 Some(UTF8Entry {
203 buf: [0x16, 0x0, 0x0],
204 len: UTF8Len::One,
205 }),
206 Some(UTF8Entry {
207 buf: [0x17, 0x0, 0x0],
208 len: UTF8Len::One,
209 }),
210 Some(UTF8Entry {
211 buf: [0x18, 0x0, 0x0],
212 len: UTF8Len::One,
213 }),
214 Some(UTF8Entry {
215 buf: [0x19, 0x0, 0x0],
216 len: UTF8Len::One,
217 }),
218 Some(UTF8Entry {
219 buf: [0x1A, 0x0, 0x0],
220 len: UTF8Len::One,
221 }),
222 Some(UTF8Entry {
223 buf: [0x1B, 0x0, 0x0],
224 len: UTF8Len::One,
225 }),
226 Some(UTF8Entry {
227 buf: [0x1C, 0x0, 0x0],
228 len: UTF8Len::One,
229 }),
230 Some(UTF8Entry {
231 buf: [0x1D, 0x0, 0x0],
232 len: UTF8Len::One,
233 }),
234 Some(UTF8Entry {
235 buf: [0x1E, 0x0, 0x0],
236 len: UTF8Len::One,
237 }),
238 Some(UTF8Entry {
239 buf: [0x1F, 0x0, 0x0],
240 len: UTF8Len::One,
241 }),
242 Some(UTF8Entry {
243 buf: [0x20, 0x0, 0x0],
244 len: UTF8Len::One,
245 }),
246 Some(UTF8Entry {
247 buf: [0x21, 0x0, 0x0],
248 len: UTF8Len::One,
249 }),
250 Some(UTF8Entry {
251 buf: [0x22, 0x0, 0x0],
252 len: UTF8Len::One,
253 }),
254 Some(UTF8Entry {
255 buf: [0x23, 0x0, 0x0],
256 len: UTF8Len::One,
257 }),
258 Some(UTF8Entry {
259 buf: [0x24, 0x0, 0x0],
260 len: UTF8Len::One,
261 }),
262 Some(UTF8Entry {
263 buf: [0x25, 0x0, 0x0],
264 len: UTF8Len::One,
265 }),
266 Some(UTF8Entry {
267 buf: [0x26, 0x0, 0x0],
268 len: UTF8Len::One,
269 }),
270 Some(UTF8Entry {
271 buf: [0x27, 0x0, 0x0],
272 len: UTF8Len::One,
273 }),
274 Some(UTF8Entry {
275 buf: [0x28, 0x0, 0x0],
276 len: UTF8Len::One,
277 }),
278 Some(UTF8Entry {
279 buf: [0x29, 0x0, 0x0],
280 len: UTF8Len::One,
281 }),
282 Some(UTF8Entry {
283 buf: [0x2A, 0x0, 0x0],
284 len: UTF8Len::One,
285 }),
286 Some(UTF8Entry {
287 buf: [0x2B, 0x0, 0x0],
288 len: UTF8Len::One,
289 }),
290 Some(UTF8Entry {
291 buf: [0x2C, 0x0, 0x0],
292 len: UTF8Len::One,
293 }),
294 Some(UTF8Entry {
295 buf: [0x2D, 0x0, 0x0],
296 len: UTF8Len::One,
297 }),
298 Some(UTF8Entry {
299 buf: [0x2E, 0x0, 0x0],
300 len: UTF8Len::One,
301 }),
302 Some(UTF8Entry {
303 buf: [0x2F, 0x0, 0x0],
304 len: UTF8Len::One,
305 }),
306 Some(UTF8Entry {
307 buf: [0x30, 0x0, 0x0],
308 len: UTF8Len::One,
309 }),
310 Some(UTF8Entry {
311 buf: [0x31, 0x0, 0x0],
312 len: UTF8Len::One,
313 }),
314 Some(UTF8Entry {
315 buf: [0x32, 0x0, 0x0],
316 len: UTF8Len::One,
317 }),
318 Some(UTF8Entry {
319 buf: [0x33, 0x0, 0x0],
320 len: UTF8Len::One,
321 }),
322 Some(UTF8Entry {
323 buf: [0x34, 0x0, 0x0],
324 len: UTF8Len::One,
325 }),
326 Some(UTF8Entry {
327 buf: [0x35, 0x0, 0x0],
328 len: UTF8Len::One,
329 }),
330 Some(UTF8Entry {
331 buf: [0x36, 0x0, 0x0],
332 len: UTF8Len::One,
333 }),
334 Some(UTF8Entry {
335 buf: [0x37, 0x0, 0x0],
336 len: UTF8Len::One,
337 }),
338 Some(UTF8Entry {
339 buf: [0x38, 0x0, 0x0],
340 len: UTF8Len::One,
341 }),
342 Some(UTF8Entry {
343 buf: [0x39, 0x0, 0x0],
344 len: UTF8Len::One,
345 }),
346 Some(UTF8Entry {
347 buf: [0x3A, 0x0, 0x0],
348 len: UTF8Len::One,
349 }),
350 Some(UTF8Entry {
351 buf: [0x3B, 0x0, 0x0],
352 len: UTF8Len::One,
353 }),
354 Some(UTF8Entry {
355 buf: [0x3C, 0x0, 0x0],
356 len: UTF8Len::One,
357 }),
358 Some(UTF8Entry {
359 buf: [0x3D, 0x0, 0x0],
360 len: UTF8Len::One,
361 }),
362 Some(UTF8Entry {
363 buf: [0x3E, 0x0, 0x0],
364 len: UTF8Len::One,
365 }),
366 Some(UTF8Entry {
367 buf: [0x3F, 0x0, 0x0],
368 len: UTF8Len::One,
369 }),
370 Some(UTF8Entry {
371 buf: [0x40, 0x0, 0x0],
372 len: UTF8Len::One,
373 }),
374 Some(UTF8Entry {
375 buf: [0x41, 0x0, 0x0],
376 len: UTF8Len::One,
377 }),
378 Some(UTF8Entry {
379 buf: [0x42, 0x0, 0x0],
380 len: UTF8Len::One,
381 }),
382 Some(UTF8Entry {
383 buf: [0x43, 0x0, 0x0],
384 len: UTF8Len::One,
385 }),
386 Some(UTF8Entry {
387 buf: [0x44, 0x0, 0x0],
388 len: UTF8Len::One,
389 }),
390 Some(UTF8Entry {
391 buf: [0x45, 0x0, 0x0],
392 len: UTF8Len::One,
393 }),
394 Some(UTF8Entry {
395 buf: [0x46, 0x0, 0x0],
396 len: UTF8Len::One,
397 }),
398 Some(UTF8Entry {
399 buf: [0x47, 0x0, 0x0],
400 len: UTF8Len::One,
401 }),
402 Some(UTF8Entry {
403 buf: [0x48, 0x0, 0x0],
404 len: UTF8Len::One,
405 }),
406 Some(UTF8Entry {
407 buf: [0x49, 0x0, 0x0],
408 len: UTF8Len::One,
409 }),
410 Some(UTF8Entry {
411 buf: [0x4A, 0x0, 0x0],
412 len: UTF8Len::One,
413 }),
414 Some(UTF8Entry {
415 buf: [0x4B, 0x0, 0x0],
416 len: UTF8Len::One,
417 }),
418 Some(UTF8Entry {
419 buf: [0x4C, 0x0, 0x0],
420 len: UTF8Len::One,
421 }),
422 Some(UTF8Entry {
423 buf: [0x4D, 0x0, 0x0],
424 len: UTF8Len::One,
425 }),
426 Some(UTF8Entry {
427 buf: [0x4E, 0x0, 0x0],
428 len: UTF8Len::One,
429 }),
430 Some(UTF8Entry {
431 buf: [0x4F, 0x0, 0x0],
432 len: UTF8Len::One,
433 }),
434 Some(UTF8Entry {
435 buf: [0x50, 0x0, 0x0],
436 len: UTF8Len::One,
437 }),
438 Some(UTF8Entry {
439 buf: [0x51, 0x0, 0x0],
440 len: UTF8Len::One,
441 }),
442 Some(UTF8Entry {
443 buf: [0x52, 0x0, 0x0],
444 len: UTF8Len::One,
445 }),
446 Some(UTF8Entry {
447 buf: [0x53, 0x0, 0x0],
448 len: UTF8Len::One,
449 }),
450 Some(UTF8Entry {
451 buf: [0x54, 0x0, 0x0],
452 len: UTF8Len::One,
453 }),
454 Some(UTF8Entry {
455 buf: [0x55, 0x0, 0x0],
456 len: UTF8Len::One,
457 }),
458 Some(UTF8Entry {
459 buf: [0x56, 0x0, 0x0],
460 len: UTF8Len::One,
461 }),
462 Some(UTF8Entry {
463 buf: [0x57, 0x0, 0x0],
464 len: UTF8Len::One,
465 }),
466 Some(UTF8Entry {
467 buf: [0x58, 0x0, 0x0],
468 len: UTF8Len::One,
469 }),
470 Some(UTF8Entry {
471 buf: [0x59, 0x0, 0x0],
472 len: UTF8Len::One,
473 }),
474 Some(UTF8Entry {
475 buf: [0x5A, 0x0, 0x0],
476 len: UTF8Len::One,
477 }),
478 Some(UTF8Entry {
479 buf: [0x5B, 0x0, 0x0],
480 len: UTF8Len::One,
481 }),
482 Some(UTF8Entry {
483 buf: [0x5C, 0x0, 0x0],
484 len: UTF8Len::One,
485 }),
486 Some(UTF8Entry {
487 buf: [0x5D, 0x0, 0x0],
488 len: UTF8Len::One,
489 }),
490 Some(UTF8Entry {
491 buf: [0x5E, 0x0, 0x0],
492 len: UTF8Len::One,
493 }),
494 Some(UTF8Entry {
495 buf: [0x5F, 0x0, 0x0],
496 len: UTF8Len::One,
497 }),
498 Some(UTF8Entry {
499 buf: [0x60, 0x0, 0x0],
500 len: UTF8Len::One,
501 }),
502 Some(UTF8Entry {
503 buf: [0x61, 0x0, 0x0],
504 len: UTF8Len::One,
505 }),
506 Some(UTF8Entry {
507 buf: [0x62, 0x0, 0x0],
508 len: UTF8Len::One,
509 }),
510 Some(UTF8Entry {
511 buf: [0x63, 0x0, 0x0],
512 len: UTF8Len::One,
513 }),
514 Some(UTF8Entry {
515 buf: [0x64, 0x0, 0x0],
516 len: UTF8Len::One,
517 }),
518 Some(UTF8Entry {
519 buf: [0x65, 0x0, 0x0],
520 len: UTF8Len::One,
521 }),
522 Some(UTF8Entry {
523 buf: [0x66, 0x0, 0x0],
524 len: UTF8Len::One,
525 }),
526 Some(UTF8Entry {
527 buf: [0x67, 0x0, 0x0],
528 len: UTF8Len::One,
529 }),
530 Some(UTF8Entry {
531 buf: [0x68, 0x0, 0x0],
532 len: UTF8Len::One,
533 }),
534 Some(UTF8Entry {
535 buf: [0x69, 0x0, 0x0],
536 len: UTF8Len::One,
537 }),
538 Some(UTF8Entry {
539 buf: [0x6A, 0x0, 0x0],
540 len: UTF8Len::One,
541 }),
542 Some(UTF8Entry {
543 buf: [0x6B, 0x0, 0x0],
544 len: UTF8Len::One,
545 }),
546 Some(UTF8Entry {
547 buf: [0x6C, 0x0, 0x0],
548 len: UTF8Len::One,
549 }),
550 Some(UTF8Entry {
551 buf: [0x6D, 0x0, 0x0],
552 len: UTF8Len::One,
553 }),
554 Some(UTF8Entry {
555 buf: [0x6E, 0x0, 0x0],
556 len: UTF8Len::One,
557 }),
558 Some(UTF8Entry {
559 buf: [0x6F, 0x0, 0x0],
560 len: UTF8Len::One,
561 }),
562 Some(UTF8Entry {
563 buf: [0x70, 0x0, 0x0],
564 len: UTF8Len::One,
565 }),
566 Some(UTF8Entry {
567 buf: [0x71, 0x0, 0x0],
568 len: UTF8Len::One,
569 }),
570 Some(UTF8Entry {
571 buf: [0x72, 0x0, 0x0],
572 len: UTF8Len::One,
573 }),
574 Some(UTF8Entry {
575 buf: [0x73, 0x0, 0x0],
576 len: UTF8Len::One,
577 }),
578 Some(UTF8Entry {
579 buf: [0x74, 0x0, 0x0],
580 len: UTF8Len::One,
581 }),
582 Some(UTF8Entry {
583 buf: [0x75, 0x0, 0x0],
584 len: UTF8Len::One,
585 }),
586 Some(UTF8Entry {
587 buf: [0x76, 0x0, 0x0],
588 len: UTF8Len::One,
589 }),
590 Some(UTF8Entry {
591 buf: [0x77, 0x0, 0x0],
592 len: UTF8Len::One,
593 }),
594 Some(UTF8Entry {
595 buf: [0x78, 0x0, 0x0],
596 len: UTF8Len::One,
597 }),
598 Some(UTF8Entry {
599 buf: [0x79, 0x0, 0x0],
600 len: UTF8Len::One,
601 }),
602 Some(UTF8Entry {
603 buf: [0x7A, 0x0, 0x0],
604 len: UTF8Len::One,
605 }),
606 Some(UTF8Entry {
607 buf: [0x7B, 0x0, 0x0],
608 len: UTF8Len::One,
609 }),
610 Some(UTF8Entry {
611 buf: [0x7C, 0x0, 0x0],
612 len: UTF8Len::One,
613 }),
614 Some(UTF8Entry {
615 buf: [0x7D, 0x0, 0x0],
616 len: UTF8Len::One,
617 }),
618 Some(UTF8Entry {
619 buf: [0x7E, 0x0, 0x0],
620 len: UTF8Len::One,
621 }),
622 Some(UTF8Entry {
623 buf: [0x7F, 0x0, 0x0],
624 len: UTF8Len::One,
625 }),
626 Some(UTF8Entry {
627 buf: [0xE2, 0x82, 0xAC],
628 len: UTF8Len::Three,
629 }),
630 Some(UTF8Entry {
631 buf: [0xC2, 0x81, 0x0],
632 len: UTF8Len::Two,
633 }),
634 Some(UTF8Entry {
635 buf: [0xE2, 0x80, 0x9A],
636 len: UTF8Len::Three,
637 }),
638 Some(UTF8Entry {
639 buf: [0xC6, 0x92, 0x0],
640 len: UTF8Len::Two,
641 }),
642 Some(UTF8Entry {
643 buf: [0xE2, 0x80, 0x9E],
644 len: UTF8Len::Three,
645 }),
646 Some(UTF8Entry {
647 buf: [0xE2, 0x80, 0xA6],
648 len: UTF8Len::Three,
649 }),
650 Some(UTF8Entry {
651 buf: [0xE2, 0x80, 0xA0],
652 len: UTF8Len::Three,
653 }),
654 Some(UTF8Entry {
655 buf: [0xE2, 0x80, 0xA1],
656 len: UTF8Len::Three,
657 }),
658 Some(UTF8Entry {
659 buf: [0xC2, 0x88, 0x0],
660 len: UTF8Len::Two,
661 }),
662 Some(UTF8Entry {
663 buf: [0xE2, 0x80, 0xB0],
664 len: UTF8Len::Three,
665 }),
666 Some(UTF8Entry {
667 buf: [0xC2, 0x8A, 0x0],
668 len: UTF8Len::Two,
669 }),
670 Some(UTF8Entry {
671 buf: [0xE2, 0x80, 0xB9],
672 len: UTF8Len::Three,
673 }),
674 Some(UTF8Entry {
675 buf: [0xC2, 0x8C, 0x0],
676 len: UTF8Len::Two,
677 }),
678 Some(UTF8Entry {
679 buf: [0xC2, 0x8D, 0x0],
680 len: UTF8Len::Two,
681 }),
682 Some(UTF8Entry {
683 buf: [0xC2, 0x8E, 0x0],
684 len: UTF8Len::Two,
685 }),
686 Some(UTF8Entry {
687 buf: [0xC2, 0x8F, 0x0],
688 len: UTF8Len::Two,
689 }),
690 Some(UTF8Entry {
691 buf: [0xC2, 0x90, 0x0],
692 len: UTF8Len::Two,
693 }),
694 Some(UTF8Entry {
695 buf: [0xE2, 0x80, 0x98],
696 len: UTF8Len::Three,
697 }),
698 Some(UTF8Entry {
699 buf: [0xE2, 0x80, 0x99],
700 len: UTF8Len::Three,
701 }),
702 Some(UTF8Entry {
703 buf: [0xE2, 0x80, 0x9C],
704 len: UTF8Len::Three,
705 }),
706 Some(UTF8Entry {
707 buf: [0xE2, 0x80, 0x9D],
708 len: UTF8Len::Three,
709 }),
710 Some(UTF8Entry {
711 buf: [0xE2, 0x80, 0xA2],
712 len: UTF8Len::Three,
713 }),
714 Some(UTF8Entry {
715 buf: [0xE2, 0x80, 0x93],
716 len: UTF8Len::Three,
717 }),
718 Some(UTF8Entry {
719 buf: [0xE2, 0x80, 0x94],
720 len: UTF8Len::Three,
721 }),
722 Some(UTF8Entry {
723 buf: [0xC2, 0x98, 0x0],
724 len: UTF8Len::Two,
725 }),
726 Some(UTF8Entry {
727 buf: [0xE2, 0x84, 0xA2],
728 len: UTF8Len::Three,
729 }),
730 Some(UTF8Entry {
731 buf: [0xC2, 0x9A, 0x0],
732 len: UTF8Len::Two,
733 }),
734 Some(UTF8Entry {
735 buf: [0xE2, 0x80, 0xBA],
736 len: UTF8Len::Three,
737 }),
738 Some(UTF8Entry {
739 buf: [0xC2, 0x9C, 0x0],
740 len: UTF8Len::Two,
741 }),
742 Some(UTF8Entry {
743 buf: [0xC2, 0x9D, 0x0],
744 len: UTF8Len::Two,
745 }),
746 Some(UTF8Entry {
747 buf: [0xC2, 0x9E, 0x0],
748 len: UTF8Len::Two,
749 }),
750 Some(UTF8Entry {
751 buf: [0xC2, 0x9F, 0x0],
752 len: UTF8Len::Two,
753 }),
754 Some(UTF8Entry {
755 buf: [0xC2, 0xA0, 0x0],
756 len: UTF8Len::Two,
757 }),
758 Some(UTF8Entry {
759 buf: [0xCE, 0x85, 0x0],
760 len: UTF8Len::Two,
761 }),
762 Some(UTF8Entry {
763 buf: [0xCE, 0x86, 0x0],
764 len: UTF8Len::Two,
765 }),
766 Some(UTF8Entry {
767 buf: [0xC2, 0xA3, 0x0],
768 len: UTF8Len::Two,
769 }),
770 Some(UTF8Entry {
771 buf: [0xC2, 0xA4, 0x0],
772 len: UTF8Len::Two,
773 }),
774 Some(UTF8Entry {
775 buf: [0xC2, 0xA5, 0x0],
776 len: UTF8Len::Two,
777 }),
778 Some(UTF8Entry {
779 buf: [0xC2, 0xA6, 0x0],
780 len: UTF8Len::Two,
781 }),
782 Some(UTF8Entry {
783 buf: [0xC2, 0xA7, 0x0],
784 len: UTF8Len::Two,
785 }),
786 Some(UTF8Entry {
787 buf: [0xC2, 0xA8, 0x0],
788 len: UTF8Len::Two,
789 }),
790 Some(UTF8Entry {
791 buf: [0xC2, 0xA9, 0x0],
792 len: UTF8Len::Two,
793 }),
794 None,
795 Some(UTF8Entry {
796 buf: [0xC2, 0xAB, 0x0],
797 len: UTF8Len::Two,
798 }),
799 Some(UTF8Entry {
800 buf: [0xC2, 0xAC, 0x0],
801 len: UTF8Len::Two,
802 }),
803 Some(UTF8Entry {
804 buf: [0xC2, 0xAD, 0x0],
805 len: UTF8Len::Two,
806 }),
807 Some(UTF8Entry {
808 buf: [0xC2, 0xAE, 0x0],
809 len: UTF8Len::Two,
810 }),
811 Some(UTF8Entry {
812 buf: [0xE2, 0x80, 0x95],
813 len: UTF8Len::Three,
814 }),
815 Some(UTF8Entry {
816 buf: [0xC2, 0xB0, 0x0],
817 len: UTF8Len::Two,
818 }),
819 Some(UTF8Entry {
820 buf: [0xC2, 0xB1, 0x0],
821 len: UTF8Len::Two,
822 }),
823 Some(UTF8Entry {
824 buf: [0xC2, 0xB2, 0x0],
825 len: UTF8Len::Two,
826 }),
827 Some(UTF8Entry {
828 buf: [0xC2, 0xB3, 0x0],
829 len: UTF8Len::Two,
830 }),
831 Some(UTF8Entry {
832 buf: [0xCE, 0x84, 0x0],
833 len: UTF8Len::Two,
834 }),
835 Some(UTF8Entry {
836 buf: [0xC2, 0xB5, 0x0],
837 len: UTF8Len::Two,
838 }),
839 Some(UTF8Entry {
840 buf: [0xC2, 0xB6, 0x0],
841 len: UTF8Len::Two,
842 }),
843 Some(UTF8Entry {
844 buf: [0xC2, 0xB7, 0x0],
845 len: UTF8Len::Two,
846 }),
847 Some(UTF8Entry {
848 buf: [0xCE, 0x88, 0x0],
849 len: UTF8Len::Two,
850 }),
851 Some(UTF8Entry {
852 buf: [0xCE, 0x89, 0x0],
853 len: UTF8Len::Two,
854 }),
855 Some(UTF8Entry {
856 buf: [0xCE, 0x8A, 0x0],
857 len: UTF8Len::Two,
858 }),
859 Some(UTF8Entry {
860 buf: [0xC2, 0xBB, 0x0],
861 len: UTF8Len::Two,
862 }),
863 Some(UTF8Entry {
864 buf: [0xCE, 0x8C, 0x0],
865 len: UTF8Len::Two,
866 }),
867 Some(UTF8Entry {
868 buf: [0xC2, 0xBD, 0x0],
869 len: UTF8Len::Two,
870 }),
871 Some(UTF8Entry {
872 buf: [0xCE, 0x8E, 0x0],
873 len: UTF8Len::Two,
874 }),
875 Some(UTF8Entry {
876 buf: [0xCE, 0x8F, 0x0],
877 len: UTF8Len::Two,
878 }),
879 Some(UTF8Entry {
880 buf: [0xCE, 0x90, 0x0],
881 len: UTF8Len::Two,
882 }),
883 Some(UTF8Entry {
884 buf: [0xCE, 0x91, 0x0],
885 len: UTF8Len::Two,
886 }),
887 Some(UTF8Entry {
888 buf: [0xCE, 0x92, 0x0],
889 len: UTF8Len::Two,
890 }),
891 Some(UTF8Entry {
892 buf: [0xCE, 0x93, 0x0],
893 len: UTF8Len::Two,
894 }),
895 Some(UTF8Entry {
896 buf: [0xCE, 0x94, 0x0],
897 len: UTF8Len::Two,
898 }),
899 Some(UTF8Entry {
900 buf: [0xCE, 0x95, 0x0],
901 len: UTF8Len::Two,
902 }),
903 Some(UTF8Entry {
904 buf: [0xCE, 0x96, 0x0],
905 len: UTF8Len::Two,
906 }),
907 Some(UTF8Entry {
908 buf: [0xCE, 0x97, 0x0],
909 len: UTF8Len::Two,
910 }),
911 Some(UTF8Entry {
912 buf: [0xCE, 0x98, 0x0],
913 len: UTF8Len::Two,
914 }),
915 Some(UTF8Entry {
916 buf: [0xCE, 0x99, 0x0],
917 len: UTF8Len::Two,
918 }),
919 Some(UTF8Entry {
920 buf: [0xCE, 0x9A, 0x0],
921 len: UTF8Len::Two,
922 }),
923 Some(UTF8Entry {
924 buf: [0xCE, 0x9B, 0x0],
925 len: UTF8Len::Two,
926 }),
927 Some(UTF8Entry {
928 buf: [0xCE, 0x9C, 0x0],
929 len: UTF8Len::Two,
930 }),
931 Some(UTF8Entry {
932 buf: [0xCE, 0x9D, 0x0],
933 len: UTF8Len::Two,
934 }),
935 Some(UTF8Entry {
936 buf: [0xCE, 0x9E, 0x0],
937 len: UTF8Len::Two,
938 }),
939 Some(UTF8Entry {
940 buf: [0xCE, 0x9F, 0x0],
941 len: UTF8Len::Two,
942 }),
943 Some(UTF8Entry {
944 buf: [0xCE, 0xA0, 0x0],
945 len: UTF8Len::Two,
946 }),
947 Some(UTF8Entry {
948 buf: [0xCE, 0xA1, 0x0],
949 len: UTF8Len::Two,
950 }),
951 None,
952 Some(UTF8Entry {
953 buf: [0xCE, 0xA3, 0x0],
954 len: UTF8Len::Two,
955 }),
956 Some(UTF8Entry {
957 buf: [0xCE, 0xA4, 0x0],
958 len: UTF8Len::Two,
959 }),
960 Some(UTF8Entry {
961 buf: [0xCE, 0xA5, 0x0],
962 len: UTF8Len::Two,
963 }),
964 Some(UTF8Entry {
965 buf: [0xCE, 0xA6, 0x0],
966 len: UTF8Len::Two,
967 }),
968 Some(UTF8Entry {
969 buf: [0xCE, 0xA7, 0x0],
970 len: UTF8Len::Two,
971 }),
972 Some(UTF8Entry {
973 buf: [0xCE, 0xA8, 0x0],
974 len: UTF8Len::Two,
975 }),
976 Some(UTF8Entry {
977 buf: [0xCE, 0xA9, 0x0],
978 len: UTF8Len::Two,
979 }),
980 Some(UTF8Entry {
981 buf: [0xCE, 0xAA, 0x0],
982 len: UTF8Len::Two,
983 }),
984 Some(UTF8Entry {
985 buf: [0xCE, 0xAB, 0x0],
986 len: UTF8Len::Two,
987 }),
988 Some(UTF8Entry {
989 buf: [0xCE, 0xAC, 0x0],
990 len: UTF8Len::Two,
991 }),
992 Some(UTF8Entry {
993 buf: [0xCE, 0xAD, 0x0],
994 len: UTF8Len::Two,
995 }),
996 Some(UTF8Entry {
997 buf: [0xCE, 0xAE, 0x0],
998 len: UTF8Len::Two,
999 }),
1000 Some(UTF8Entry {
1001 buf: [0xCE, 0xAF, 0x0],
1002 len: UTF8Len::Two,
1003 }),
1004 Some(UTF8Entry {
1005 buf: [0xCE, 0xB0, 0x0],
1006 len: UTF8Len::Two,
1007 }),
1008 Some(UTF8Entry {
1009 buf: [0xCE, 0xB1, 0x0],
1010 len: UTF8Len::Two,
1011 }),
1012 Some(UTF8Entry {
1013 buf: [0xCE, 0xB2, 0x0],
1014 len: UTF8Len::Two,
1015 }),
1016 Some(UTF8Entry {
1017 buf: [0xCE, 0xB3, 0x0],
1018 len: UTF8Len::Two,
1019 }),
1020 Some(UTF8Entry {
1021 buf: [0xCE, 0xB4, 0x0],
1022 len: UTF8Len::Two,
1023 }),
1024 Some(UTF8Entry {
1025 buf: [0xCE, 0xB5, 0x0],
1026 len: UTF8Len::Two,
1027 }),
1028 Some(UTF8Entry {
1029 buf: [0xCE, 0xB6, 0x0],
1030 len: UTF8Len::Two,
1031 }),
1032 Some(UTF8Entry {
1033 buf: [0xCE, 0xB7, 0x0],
1034 len: UTF8Len::Two,
1035 }),
1036 Some(UTF8Entry {
1037 buf: [0xCE, 0xB8, 0x0],
1038 len: UTF8Len::Two,
1039 }),
1040 Some(UTF8Entry {
1041 buf: [0xCE, 0xB9, 0x0],
1042 len: UTF8Len::Two,
1043 }),
1044 Some(UTF8Entry {
1045 buf: [0xCE, 0xBA, 0x0],
1046 len: UTF8Len::Two,
1047 }),
1048 Some(UTF8Entry {
1049 buf: [0xCE, 0xBB, 0x0],
1050 len: UTF8Len::Two,
1051 }),
1052 Some(UTF8Entry {
1053 buf: [0xCE, 0xBC, 0x0],
1054 len: UTF8Len::Two,
1055 }),
1056 Some(UTF8Entry {
1057 buf: [0xCE, 0xBD, 0x0],
1058 len: UTF8Len::Two,
1059 }),
1060 Some(UTF8Entry {
1061 buf: [0xCE, 0xBE, 0x0],
1062 len: UTF8Len::Two,
1063 }),
1064 Some(UTF8Entry {
1065 buf: [0xCE, 0xBF, 0x0],
1066 len: UTF8Len::Two,
1067 }),
1068 Some(UTF8Entry {
1069 buf: [0xCF, 0x80, 0x0],
1070 len: UTF8Len::Two,
1071 }),
1072 Some(UTF8Entry {
1073 buf: [0xCF, 0x81, 0x0],
1074 len: UTF8Len::Two,
1075 }),
1076 Some(UTF8Entry {
1077 buf: [0xCF, 0x82, 0x0],
1078 len: UTF8Len::Two,
1079 }),
1080 Some(UTF8Entry {
1081 buf: [0xCF, 0x83, 0x0],
1082 len: UTF8Len::Two,
1083 }),
1084 Some(UTF8Entry {
1085 buf: [0xCF, 0x84, 0x0],
1086 len: UTF8Len::Two,
1087 }),
1088 Some(UTF8Entry {
1089 buf: [0xCF, 0x85, 0x0],
1090 len: UTF8Len::Two,
1091 }),
1092 Some(UTF8Entry {
1093 buf: [0xCF, 0x86, 0x0],
1094 len: UTF8Len::Two,
1095 }),
1096 Some(UTF8Entry {
1097 buf: [0xCF, 0x87, 0x0],
1098 len: UTF8Len::Two,
1099 }),
1100 Some(UTF8Entry {
1101 buf: [0xCF, 0x88, 0x0],
1102 len: UTF8Len::Two,
1103 }),
1104 Some(UTF8Entry {
1105 buf: [0xCF, 0x89, 0x0],
1106 len: UTF8Len::Two,
1107 }),
1108 Some(UTF8Entry {
1109 buf: [0xCF, 0x8A, 0x0],
1110 len: UTF8Len::Two,
1111 }),
1112 Some(UTF8Entry {
1113 buf: [0xCF, 0x8B, 0x0],
1114 len: UTF8Len::Two,
1115 }),
1116 Some(UTF8Entry {
1117 buf: [0xCF, 0x8C, 0x0],
1118 len: UTF8Len::Two,
1119 }),
1120 Some(UTF8Entry {
1121 buf: [0xCF, 0x8D, 0x0],
1122 len: UTF8Len::Two,
1123 }),
1124 Some(UTF8Entry {
1125 buf: [0xCF, 0x8E, 0x0],
1126 len: UTF8Len::Two,
1127 }),
1128 None,
1129];
1130impl Encoder for CP1253 {
1131 #[doc(hidden)]
1132 #[inline]
1133 fn encode_grapheme(&self, bytes: &mut &[u8]) -> Option<u8> {
1134 let (&a, rest) = bytes.split_first().unwrap();
1135 Some(
1136 match (a, &bytes) {
1137 (0x00..=0x7F, _) => {
1138 *bytes = rest;
1139 a
1140 }
1141 (0xC2, [_, b, ..]) => {
1142 *bytes = &bytes[2..];
1143 match b {
1144 0x81 => 0x81,
1145 0x88 => 0x88,
1146 0x8A => 0x8A,
1147 0x8C => 0x8C,
1148 0x8D => 0x8D,
1149 0x8E => 0x8E,
1150 0x8F => 0x8F,
1151 0x90 => 0x90,
1152 0x98 => 0x98,
1153 0x9A => 0x9A,
1154 0x9C => 0x9C,
1155 0x9D => 0x9D,
1156 0x9E => 0x9E,
1157 0x9F => 0x9F,
1158 0xA0 => 0xA0,
1159 0xA3 => 0xA3,
1160 0xA4 => 0xA4,
1161 0xA5 => 0xA5,
1162 0xA6 => 0xA6,
1163 0xA7 => 0xA7,
1164 0xA8 => 0xA8,
1165 0xA9 => 0xA9,
1166 0xAB => 0xAB,
1167 0xAC => 0xAC,
1168 0xAD => 0xAD,
1169 0xAE => 0xAE,
1170 0xB0 => 0xB0,
1171 0xB1 => 0xB1,
1172 0xB2 => 0xB2,
1173 0xB3 => 0xB3,
1174 0xB5 => 0xB5,
1175 0xB6 => 0xB6,
1176 0xB7 => 0xB7,
1177 0xBB => 0xBB,
1178 0xBD => 0xBD,
1179 _ => return None,
1180 }
1181 }
1182 (0xC6, [_, b, ..]) => {
1183 *bytes = &bytes[2..];
1184 match b {
1185 0x92 => 0x83,
1186 _ => return None,
1187 }
1188 }
1189 (0xCE, [_, b, ..]) => {
1190 *bytes = &bytes[2..];
1191 match b {
1192 0x85 => 0xA1,
1193 0x86 => 0xA2,
1194 0x84 => 0xB4,
1195 0x88 => 0xB8,
1196 0x89 => 0xB9,
1197 0x8A => 0xBA,
1198 0x8C => 0xBC,
1199 0x8E => 0xBE,
1200 0x8F => 0xBF,
1201 0x90 => 0xC0,
1202 0x91 => 0xC1,
1203 0x92 => 0xC2,
1204 0x93 => 0xC3,
1205 0x94 => 0xC4,
1206 0x95 => 0xC5,
1207 0x96 => 0xC6,
1208 0x97 => 0xC7,
1209 0x98 => 0xC8,
1210 0x99 => 0xC9,
1211 0x9A => 0xCA,
1212 0x9B => 0xCB,
1213 0x9C => 0xCC,
1214 0x9D => 0xCD,
1215 0x9E => 0xCE,
1216 0x9F => 0xCF,
1217 0xA0 => 0xD0,
1218 0xA1 => 0xD1,
1219 0xA3 => 0xD3,
1220 0xA4 => 0xD4,
1221 0xA5 => 0xD5,
1222 0xA6 => 0xD6,
1223 0xA7 => 0xD7,
1224 0xA8 => 0xD8,
1225 0xA9 => 0xD9,
1226 0xAA => 0xDA,
1227 0xAB => 0xDB,
1228 0xAC => 0xDC,
1229 0xAD => 0xDD,
1230 0xAE => 0xDE,
1231 0xAF => 0xDF,
1232 0xB0 => 0xE0,
1233 0xB1 => 0xE1,
1234 0xB2 => 0xE2,
1235 0xB3 => 0xE3,
1236 0xB4 => 0xE4,
1237 0xB5 => 0xE5,
1238 0xB6 => 0xE6,
1239 0xB7 => 0xE7,
1240 0xB8 => 0xE8,
1241 0xB9 => 0xE9,
1242 0xBA => 0xEA,
1243 0xBB => 0xEB,
1244 0xBC => 0xEC,
1245 0xBD => 0xED,
1246 0xBE => 0xEE,
1247 0xBF => 0xEF,
1248 _ => return None,
1249 }
1250 }
1251 (0xCF, [_, b, ..]) => {
1252 *bytes = &bytes[2..];
1253 match b {
1254 0x80 => 0xF0,
1255 0x81 => 0xF1,
1256 0x82 => 0xF2,
1257 0x83 => 0xF3,
1258 0x84 => 0xF4,
1259 0x85 => 0xF5,
1260 0x86 => 0xF6,
1261 0x87 => 0xF7,
1262 0x88 => 0xF8,
1263 0x89 => 0xF9,
1264 0x8A => 0xFA,
1265 0x8B => 0xFB,
1266 0x8C => 0xFC,
1267 0x8D => 0xFD,
1268 0x8E => 0xFE,
1269 _ => return None,
1270 }
1271 }
1272 (0xE2, [_, b, c, ..]) => {
1273 *bytes = &bytes[3..];
1274 match b {
1275 0x80 => {
1276 match c {
1277 0x9A => 0x82,
1278 0x9E => 0x84,
1279 0xA6 => 0x85,
1280 0xA0 => 0x86,
1281 0xA1 => 0x87,
1282 0xB0 => 0x89,
1283 0xB9 => 0x8B,
1284 0x98 => 0x91,
1285 0x99 => 0x92,
1286 0x9C => 0x93,
1287 0x9D => 0x94,
1288 0xA2 => 0x95,
1289 0x93 => 0x96,
1290 0x94 => 0x97,
1291 0xBA => 0x9B,
1292 0x95 => 0xAF,
1293 _ => return None,
1294 }
1295 }
1296 0x82 => {
1297 match c {
1298 0xAC => 0x80,
1299 _ => return None,
1300 }
1301 }
1302 0x84 => {
1303 match c {
1304 0xA2 => 0x99,
1305 _ => return None,
1306 }
1307 }
1308 _ => return None,
1309 }
1310 }
1311 (0xC2..=0xDF, _) => {
1312 *bytes = &bytes[2..];
1313 return None;
1314 }
1315 (0xE0..=0xEF, _) => {
1316 *bytes = &bytes[3..];
1317 return None;
1318 }
1319 (0xF0..=0xF4, _) => {
1320 *bytes = &bytes[4..];
1321 return None;
1322 }
1323 _ => panic!(),
1324 },
1325 )
1326 }
1327}