comparison src/charset.h @ 73055:e946daf4b223

(PREV_CHAR_BOUNDARY): Make it work from within a char's byte sequence. (AT_CHAR_BOUNDARY): New macro.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Fri, 22 Sep 2006 17:30:02 +0000
parents 92b0f65a55ce
children 6ee41fdd69ff
comparison
equal deleted inserted replaced
73054:24edca6ed2da 73055:e946daf4b223
656 if ((p) < (limit)) \ 656 if ((p) < (limit)) \
657 (p) += BYTES_BY_CHAR_HEAD (*(p)); \ 657 (p) += BYTES_BY_CHAR_HEAD (*(p)); \
658 } while (0) 658 } while (0)
659 659
660 660
661 /* If P is after LIMIT, advance P to the previous character boundary. 661 /* If P is after LIMIT, advance P to the previous character boundary. */
662 It assumes that P is already at a character boundary of the sane
663 mulitbyte form whose beginning address is LIMIT. */
664 662
665 #define PREV_CHAR_BOUNDARY(p, limit) \ 663 #define PREV_CHAR_BOUNDARY(p, limit) \
666 do { \ 664 do { \
667 if ((p) > (limit)) \ 665 if ((p) > (limit)) \
668 { \ 666 { \
669 const unsigned char *p0 = (p); \ 667 const unsigned char *p0 = (p); \
668 const unsigned char *p_limit = max (limit, p0 - MAX_MULTIBYTE_LENGTH);\
670 do { \ 669 do { \
671 p0--; \ 670 p0--; \
672 } while (p0 >= limit && ! CHAR_HEAD_P (*p0)); \ 671 } while (p0 >= p_limit && ! CHAR_HEAD_P (*p0)); \
673 (p) = (BYTES_BY_CHAR_HEAD (*p0) == (p) - p0) ? p0 : (p) - 1; \ 672 /* If BBCH(*p0) > p-p0, it means we were not on a boundary. */ \
673 (p) = (BYTES_BY_CHAR_HEAD (*p0) >= (p) - p0) ? p0 : (p) - 1; \
674 } \ 674 } \
675 } while (0) 675 } while (0)
676 676
677 #define AT_CHAR_BOUNDARY_P(result, p, limit) \
678 do { \
679 if (CHAR_HEAD_P (*(p)) || (p) <= limit) \
680 /* Optimization for the common case. */ \
681 (result) = 1; \
682 else \
683 { \
684 const unsigned char *p_aux = (p)+1; \
685 PREV_CHAR_BOUNDARY (p_aux, limit); \
686 (result) = (p_aux == (p)); \
687 } \
688 } while (0)
677 689
678 #ifdef emacs 690 #ifdef emacs
679 691
680 /* Increase the buffer byte position POS_BYTE of the current buffer to 692 /* Increase the buffer byte position POS_BYTE of the current buffer to
681 the next character boundary. This macro relies on the fact that 693 the next character boundary. This macro relies on the fact that