| 1713 | by KEY in LINE. */ |
| 1714 | |
| 1715 | static char * |
| 1716 | begfield (struct line const *line, struct keyfield const *key) |
| 1717 | { |
| 1718 | char *ptr = line->text, *lim = ptr + line->length - 1; |
| 1719 | size_t sword = key->sword; |
| 1720 | size_t schar = key->schar; |
| 1721 | |
| 1722 | /* The leading field separator itself is included in a field when -t |
| 1723 | is absent. */ |
| 1724 | |
| 1725 | if (tab != TAB_DEFAULT) |
| 1726 | while (ptr < lim && sword--) |
| 1727 | { |
| 1728 | char *sep = memchr (ptr, tab, lim - ptr); |
| 1729 | ptr = sep ? sep : lim; |
| 1730 | if (ptr < lim) |
| 1731 | ++ptr; |
| 1732 | } |
| 1733 | else |
| 1734 | while (ptr < lim && sword--) |
| 1735 | { |
| 1736 | while (ptr < lim && blanks[to_uchar (*ptr)]) |
| 1737 | ++ptr; |
| 1738 | while (ptr < lim && !blanks[to_uchar (*ptr)]) |
| 1739 | ++ptr; |
| 1740 | } |
| 1741 | |
| 1742 | /* If we're ignoring leading blanks when computing the Start |
| 1743 | of the field, skip past them here. */ |
| 1744 | if (key->skipsblanks) |
| 1745 | while (ptr < lim && blanks[to_uchar (*ptr)]) |
| 1746 | ++ptr; |
| 1747 | |
| 1748 | /* Advance PTR by SCHAR (if possible), but no further than LIM. */ |
| 1749 | size_t remaining_bytes = lim - ptr; |
| 1750 | if (schar < remaining_bytes) |
| 1751 | ptr += schar; |
| 1752 | else |
| 1753 | ptr = lim; |
| 1754 | |
| 1755 | return ptr; |
| 1756 | } |
| 1757 | |
| 1758 | /* Return the limit of (a pointer to the first character after) the field |
| 1759 | in LINE specified by KEY. */ |
no test coverage detected