charset.c (170256) | charset.c (172468) |
---|---|
1/* 2 * Copyright (C) 1984-2007 Mark Nudelman 3 * 4 * You may distribute under the terms of either the GNU General Public 5 * License or the Less License, as specified in the README file. 6 * 7 * For more information about less, or for information on how to 8 * contact the author, see the README file. --- 553 unchanged lines hidden (view full) --- 562 public LWCHAR 563get_wchar(p) 564 char *p; 565{ 566 switch (utf_len(p[0])) 567 { 568 case 1: 569 default: | 1/* 2 * Copyright (C) 1984-2007 Mark Nudelman 3 * 4 * You may distribute under the terms of either the GNU General Public 5 * License or the Less License, as specified in the README file. 6 * 7 * For more information about less, or for information on how to 8 * contact the author, see the README file. --- 553 unchanged lines hidden (view full) --- 562 public LWCHAR 563get_wchar(p) 564 char *p; 565{ 566 switch (utf_len(p[0])) 567 { 568 case 1: 569 default: |
570 /* 0xxxxxxx */ |
|
570 return (LWCHAR) 571 (p[0] & 0xFF); 572 case 2: | 571 return (LWCHAR) 572 (p[0] & 0xFF); 573 case 2: |
574 /* 110xxxxx 10xxxxxx */ |
|
573 return (LWCHAR) ( 574 ((p[0] & 0x1F) << 6) | 575 (p[1] & 0x3F)); 576 case 3: | 575 return (LWCHAR) ( 576 ((p[0] & 0x1F) << 6) | 577 (p[1] & 0x3F)); 578 case 3: |
579 /* 1110xxxx 10xxxxxx 10xxxxxx */ |
|
577 return (LWCHAR) ( 578 ((p[0] & 0x0F) << 12) | 579 ((p[1] & 0x3F) << 6) | 580 (p[2] & 0x3F)); 581 case 4: | 580 return (LWCHAR) ( 581 ((p[0] & 0x0F) << 12) | 582 ((p[1] & 0x3F) << 6) | 583 (p[2] & 0x3F)); 584 case 4: |
585 /* 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx */ |
|
582 return (LWCHAR) ( 583 ((p[0] & 0x07) << 18) | 584 ((p[1] & 0x3F) << 12) | 585 ((p[2] & 0x3F) << 6) | 586 (p[3] & 0x3F)); 587 case 5: | 586 return (LWCHAR) ( 587 ((p[0] & 0x07) << 18) | 588 ((p[1] & 0x3F) << 12) | 589 ((p[2] & 0x3F) << 6) | 590 (p[3] & 0x3F)); 591 case 5: |
592 /* 111110xx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx */ |
|
588 return (LWCHAR) ( 589 ((p[0] & 0x03) << 24) | 590 ((p[1] & 0x3F) << 18) | 591 ((p[2] & 0x3F) << 12) | 592 ((p[3] & 0x3F) << 6) | 593 (p[4] & 0x3F)); 594 case 6: | 593 return (LWCHAR) ( 594 ((p[0] & 0x03) << 24) | 595 ((p[1] & 0x3F) << 18) | 596 ((p[2] & 0x3F) << 12) | 597 ((p[3] & 0x3F) << 6) | 598 (p[4] & 0x3F)); 599 case 6: |
600 /* 1111110x 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx */ |
|
595 return (LWCHAR) ( 596 ((p[0] & 0x01) << 30) | 597 ((p[1] & 0x3F) << 24) | 598 ((p[2] & 0x3F) << 18) | 599 ((p[3] & 0x3F) << 12) | 600 ((p[4] & 0x3F) << 6) | 601 (p[5] & 0x3F)); 602 } 603} 604 605/* | 601 return (LWCHAR) ( 602 ((p[0] & 0x01) << 30) | 603 ((p[1] & 0x3F) << 24) | 604 ((p[2] & 0x3F) << 18) | 605 ((p[3] & 0x3F) << 12) | 606 ((p[4] & 0x3F) << 6) | 607 (p[5] & 0x3F)); 608 } 609} 610 611/* |
612 * Store a character into a UTF-8 string. 613 */ 614 public void 615put_wchar(pp, ch) 616 char **pp; 617 LWCHAR ch; 618{ 619 if (!utf_mode || ch < 0x80) 620 { 621 /* 0xxxxxxx */ 622 *(*pp)++ = (char) ch; 623 } else if (ch < 0x800) 624 { 625 /* 110xxxxx 10xxxxxx */ 626 *(*pp)++ = (char) (0xC0 | ((ch >> 6) & 0x1F)); 627 *(*pp)++ = (char) (0x80 | (ch & 0x3F)); 628 } else if (ch < 0x10000) 629 { 630 /* 1110xxxx 10xxxxxx 10xxxxxx */ 631 *(*pp)++ = (char) (0xE0 | ((ch >> 12) & 0x0F)); 632 *(*pp)++ = (char) (0x80 | ((ch >> 6) & 0x3F)); 633 *(*pp)++ = (char) (0x80 | (ch & 0x3F)); 634 } else if (ch < 0x200000) 635 { 636 /* 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx */ 637 *(*pp)++ = (char) (0xF0 | ((ch >> 18) & 0x07)); 638 *(*pp)++ = (char) (0x80 | ((ch >> 12) & 0x3F)); 639 *(*pp)++ = (char) (0x80 | ((ch >> 6) & 0x3F)); 640 *(*pp)++ = (char) (0x80 | (ch & 0x3F)); 641 } else if (ch < 0x4000000) 642 { 643 /* 111110xx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx */ 644 *(*pp)++ = (char) (0xF0 | ((ch >> 24) & 0x03)); 645 *(*pp)++ = (char) (0x80 | ((ch >> 18) & 0x3F)); 646 *(*pp)++ = (char) (0x80 | ((ch >> 12) & 0x3F)); 647 *(*pp)++ = (char) (0x80 | ((ch >> 6) & 0x3F)); 648 *(*pp)++ = (char) (0x80 | (ch & 0x3F)); 649 } else 650 { 651 /* 1111110x 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx */ 652 *(*pp)++ = (char) (0xF0 | ((ch >> 30) & 0x01)); 653 *(*pp)++ = (char) (0x80 | ((ch >> 24) & 0x3F)); 654 *(*pp)++ = (char) (0x80 | ((ch >> 18) & 0x3F)); 655 *(*pp)++ = (char) (0x80 | ((ch >> 12) & 0x3F)); 656 *(*pp)++ = (char) (0x80 | ((ch >> 6) & 0x3F)); 657 *(*pp)++ = (char) (0x80 | (ch & 0x3F)); 658 } 659} 660 661/* |
|
606 * Step forward or backward one character in a string. 607 */ 608 public LWCHAR 609step_char(pp, dir, limit) 610 char **pp; 611 signed int dir; 612 char *limit; 613{ --- 496 unchanged lines hidden --- | 662 * Step forward or backward one character in a string. 663 */ 664 public LWCHAR 665step_char(pp, dir, limit) 666 char **pp; 667 signed int dir; 668 char *limit; 669{ --- 496 unchanged lines hidden --- |