|
2 | 2 | * ISO-8859-1 conversion routines for HTMLDOC, an HTML document
|
3 | 3 | * processing program.
|
4 | 4 | *
|
5 |
| - * Copyright 2011-2019 by Michael R Sweet. |
| 5 | + * Copyright 2011-2024 by Michael R Sweet. |
6 | 6 | * Copyright 1997-2010 by Easy Software Products. All rights reserved.
|
7 | 7 | *
|
8 | 8 | * This program is free software. Distribution and use rights are outlined in
|
9 | 9 | * the file "COPYING".
|
10 | 10 | */
|
11 | 11 |
|
12 |
| -/* |
13 |
| - * Include necessary headers. |
14 |
| - */ |
15 |
| - |
16 | 12 | #include <stdio.h>
|
17 | 13 | #include <stdlib.h>
|
18 | 14 |
|
@@ -441,11 +437,49 @@ iso8859(uchar value) /* I - ISO-8859-1 equivalent */
|
441 | 437 |
|
442 | 438 | if (iso8859_names[value] == NULL)
|
443 | 439 | {
|
444 |
| - buf[0] = value; |
445 |
| - buf[1] = '\0'; |
| 440 | + if (value < 127) |
| 441 | + { |
| 442 | + // ASCII... |
| 443 | + buf[0] = value; |
| 444 | + buf[1] = '\0'; |
| 445 | + } |
| 446 | + else if (_htmlUTF8) |
| 447 | + { |
| 448 | + // UTF-8... |
| 449 | + int unich = _htmlUnicode[value]; // Unicode character |
| 450 | + |
| 451 | + if (unich < 0x400) |
| 452 | + { |
| 453 | + buf[0] = 0xc0 | (unich >> 6); |
| 454 | + buf[1] = 0x80 | (unich & 0x3f); |
| 455 | + buf[2] = '\0'; |
| 456 | + } |
| 457 | + else if (unich < 0x10000) |
| 458 | + { |
| 459 | + buf[0] = 0xe0 | (unich >> 12); |
| 460 | + buf[1] = 0x80 | ((unich >> 6) & 0x3f); |
| 461 | + buf[2] = 0x80 | (unich & 0x3f); |
| 462 | + buf[3] = '\0'; |
| 463 | + } |
| 464 | + else |
| 465 | + { |
| 466 | + buf[0] = 0xf0 | (unich >> 18); |
| 467 | + buf[1] = 0x80 | ((unich >> 12) & 0x3f); |
| 468 | + buf[2] = 0x80 | ((unich >> 6) & 0x3f); |
| 469 | + buf[3] = 0x80 | (unich & 0x3f); |
| 470 | + buf[4] = '\0'; |
| 471 | + } |
| 472 | + } |
| 473 | + else |
| 474 | + { |
| 475 | + // Character-set neutral way to map to Unicode... |
| 476 | + snprintf((char *)buf, sizeof(buf), "&#%d;", _htmlUnicode[value]); |
| 477 | + } |
446 | 478 | }
|
447 | 479 | else
|
| 480 | + { |
448 | 481 | snprintf((char *)buf, sizeof(buf), "&%s;", iso8859_names[value]->name);
|
| 482 | + } |
449 | 483 |
|
450 | 484 | return (buf);
|
451 | 485 | }
|
|
0 commit comments