aboutsummaryrefslogtreecommitdiffstats
path: root/src/buffer.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/buffer.h')
-rw-r--r--src/buffer.h101
1 files changed, 101 insertions, 0 deletions
diff --git a/src/buffer.h b/src/buffer.h
index 9875b8a447b..3da49414bb8 100644
--- a/src/buffer.h
+++ b/src/buffer.h
@@ -1562,6 +1562,107 @@ CHARACTER_WIDTH (int c)
1562 : !NILP (BVAR (current_buffer, ctl_arrow)) ? 2 : 4); 1562 : !NILP (BVAR (current_buffer, ctl_arrow)) ? 2 : 4);
1563} 1563}
1564 1564
1565
1566/* Like fetch_string_char_advance, but fetch character from the current
1567 buffer. */
1568
1569INLINE int
1570fetch_char_advance (ptrdiff_t *charidx, ptrdiff_t *byteidx)
1571{
1572 int output;
1573 ptrdiff_t c = *charidx, b = *byteidx;
1574 c++;
1575 unsigned char *chp = BYTE_POS_ADDR (b);
1576 if (!NILP (BVAR (current_buffer, enable_multibyte_characters)))
1577 {
1578 int chlen;
1579 output = string_char_and_length (chp, &chlen);
1580 b += chlen;
1581 }
1582 else
1583 {
1584 output = *chp;
1585 b++;
1586 }
1587 *charidx = c;
1588 *byteidx = b;
1589 return output;
1590}
1591
1592
1593/* Like fetch_char_advance, but assumes the current buffer is multibyte. */
1594
1595INLINE int
1596fetch_char_advance_no_check (ptrdiff_t *charidx, ptrdiff_t *byteidx)
1597{
1598 int output;
1599 ptrdiff_t c = *charidx, b = *byteidx;
1600 c++;
1601 unsigned char *chp = BYTE_POS_ADDR (b);
1602 int chlen;
1603 output = string_char_and_length (chp, &chlen);
1604 b += chlen;
1605 *charidx = c;
1606 *byteidx = b;
1607 return output;
1608}
1609
1610/* Return the number of bytes in the multibyte character in BUF
1611 that starts at position POS_BYTE. This relies on the fact that
1612 *GPT_ADDR and *Z_ADDR are always accessible and the values are
1613 '\0'. No range checking of POS_BYTE. */
1614
1615INLINE int
1616buf_next_char_len (struct buffer *buf, ptrdiff_t pos_byte)
1617{
1618 unsigned char *chp = BUF_BYTE_ADDRESS (buf, pos_byte);
1619 return BYTES_BY_CHAR_HEAD (*chp);
1620}
1621
1622INLINE int
1623next_char_len (ptrdiff_t pos_byte)
1624{
1625 return buf_next_char_len (current_buffer, pos_byte);
1626}
1627
1628/* Return the number of bytes in the multibyte character in BUF just
1629 before POS_BYTE. No range checking of POS_BYTE. */
1630
1631INLINE int
1632buf_prev_char_len (struct buffer *buf, ptrdiff_t pos_byte)
1633{
1634 unsigned char *chp
1635 = (BUF_BEG_ADDR (buf) + pos_byte - BEG_BYTE
1636 + (pos_byte <= BUF_GPT_BYTE (buf) ? 0 : BUF_GAP_SIZE (buf)));
1637 return raw_prev_char_len (chp);
1638}
1639
1640INLINE int
1641prev_char_len (ptrdiff_t pos_byte)
1642{
1643 return buf_prev_char_len (current_buffer, pos_byte);
1644}
1645
1646/* Increment both *CHARPOS and *BYTEPOS, each in the appropriate way. */
1647
1648INLINE void
1649inc_both (ptrdiff_t *charpos, ptrdiff_t *bytepos)
1650{
1651 (*charpos)++;
1652 (*bytepos) += (!NILP (BVAR (current_buffer, enable_multibyte_characters))
1653 ? next_char_len (*bytepos) : 1);
1654}
1655
1656/* Decrement both *CHARPOS and *BYTEPOS, each in the appropriate way. */
1657
1658INLINE void
1659dec_both (ptrdiff_t *charpos, ptrdiff_t *bytepos)
1660{
1661 (*charpos)--;
1662 (*bytepos) -= (!NILP (BVAR (current_buffer, enable_multibyte_characters))
1663 ? prev_char_len (*bytepos) : 1);
1664}
1665
1565INLINE_HEADER_END 1666INLINE_HEADER_END
1566 1667
1567#endif /* EMACS_BUFFER_H */ 1668#endif /* EMACS_BUFFER_H */