1.6.3. Discussion
Each function assumes tab stops are every eight spaces, but that can
be modified by changing the setting of the
$tab_stop variable.
The regular expression in pc_tab_expand( ) matches
both a group of tabs and all the text in a line before that group of
tabs. It needs to match the text before the tabs because the length
of that text affects how many spaces the tabs should be replaced so
that subsequent text is aligned with the next tab stop. The function
doesn't just replace each tab with eight spaces; it
adjusts text after tabs to line up with tab stops.
Similarly, pc_tab_unexpand( )
doesn't just look for eight consecutive spaces and
then replace them with one tab character. It divides up each line
into eight-character chunks and then substitutes ending whitespace in
those chunks (at least two spaces) with tabs. This not only preserves
text alignment with tab stops; it also saves space in the string.