@@ -584,23 +584,33 @@ See L<S05/Substitution>
584
584
our Str multi method indent ($str: $steps) is export;
585
585
586
586
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.
589
596
590
597
If C<$steps> is negative, removes that many spaces instead. Should any line
591
598
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.
592
600
593
601
If C<$steps> is C<*>, removes exactly as many spaces as are needed to make at
594
602
least one line have zero indentation.
595
603
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.
604
614
605
615
=back
606
616
0 commit comments