Skip to content

Commit dbfdabb

Browse files
author
Carl Masak
committed
[S32/Str] rewrote .indent description
Explained that indentation is in fact added at the end of the whitespace prefix, not at the beginning. (This is in order to make tab characters act sanely.) Rewrote other parts, but they should be identical in meaning, just (hopefully) clearer.
1 parent e7cc2ec commit dbfdabb

File tree

1 file changed

+20
-10
lines changed

1 file changed

+20
-10
lines changed

S32-setting-library/Str.pod

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -584,23 +584,33 @@ See L<S05/Substitution>
584584
our Str multi method indent ($str: $steps) is export;
585585

586586
Returns a re-indented string wherein C<$steps> number of spaces have been added
587-
to each line (i.e. to the beginning of the string and after each logical
588-
newline).
587+
to each line. If a line already begins with horizontal whitespace, the new
588+
spaces are added to the end of those.
589+
590+
If the whitespace at the beginning of the line consists of only C<chr(32)>
591+
spaces, C<chr(32)> spaces are added as indentation as well. If the whitespace
592+
at the beginning of the line consists of some other kind of horizontal
593+
whitespace, that kind of whitespace is added as indentation. If the whitespace
594+
at the beginning of the line consists of two or more different kinds of
595+
horizontal whitespace, again C<chr(32)> spaces are used.
589596

590597
If C<$steps> is negative, removes that many spaces instead. Should any line
591598
contain too few leading spaces, only those are removed and a warning is issued.
599+
At most one such warning is issued per C<.indent> call.
592600

593601
If C<$steps> is C<*>, removes exactly as many spaces as are needed to make at
594602
least one line have zero indentation.
595603

596-
When removing indentation, the method will assume hard tabs to be
597-
C<< ($?TABSTOP // 8) >> spaces, and will treat other horizontal whitespace
598-
characters as synonymous to spaces. Characters not participating in the
599-
re-indenting will be left untouched, and those added in an indent call will
600-
be either (1) consistent with subsequent leading whitespace already on the
601-
line, if these are all the same, or (2) spaces. During an unindent, the
602-
trailing tab character in a chain of leading tab characters may explode
603-
into a number of space characters.
604+
The method will assume hard tabs to be equivalent
605+
to C<< ($?TABSTOP // 8) >> spaces, and will treat any other horizontal
606+
whitespace character as equivalent to one spaces. If the indenting doesn't
607+
"add up evenly", one hard tab needs to be exploded into the equivalent
608+
number of spaces before the unindenting of that line.
609+
610+
Decisions on how to indent each line are based solely on characters on
611+
that line. Thus, an C<.indent> call on a multiline string therefore amounts
612+
to C< .lines».indent.join("\n") >, modulo exotic line endings in the
613+
original string.
604614

605615
=back
606616

0 commit comments

Comments
 (0)