@@ -1205,7 +1205,7 @@ Replaces one or many characters with one or many characters. Ranges are
1205
1205
supported, both for keys and values. Regexes work as keys. In case a list of
1206
1206
keys and values is used, substrings can be replaced as well. When called with
1207
1207
C < :complement > anything but the matched value or range is replaced with a
1208
- single value. With C < :delete > the matched characters are without corresponding
1208
+ single value; with C < :delete > the matched characters without corresponding
1209
1209
replacement are removed. Combining C < :complement > and C < :delete > will remove
1210
1210
anything but the matched values, I < unless replacement characters have been
1211
1211
specified > , in which case, C < :delete > would be ignored. The adverb C < :squash >
@@ -1229,6 +1229,28 @@ Example:
1229
1229
"aaa1123bb123c".trans('a'..'z' => 'A'..'Z', :squash); # RESULT: «A1123B123C»
1230
1230
"aaa1123bb123c".trans('a'..'z' => 'x', :complement, :squash); # RESULT: «aaaxbbxc»
1231
1231
1232
+ Please note that the behavior of the two versions of the multi method is
1233
+ slightly different. The first form will transpose only one character if the
1234
+ origin is also one character:
1235
+
1236
+ = begin code
1237
+ say "abcd".trans( "a" => "zz" ); # OUTPUT: «zbcd»
1238
+ say "abcd".trans( "ab" => "yz" ); # OUTPUT: «yzcd»
1239
+ = end code
1240
+
1241
+ In the second case, behavior is as expected, since the origin is more than one
1242
+ char long. However, if the C < Pair > in the multi method does not have a C < Str > as
1243
+ an origin or target, it is handled to the second multi method, and behavior
1244
+ changes:
1245
+
1246
+ m: say "abcd".trans: ["a"] => ["zz"]; # OUTPUT: «zzbcd»
1247
+
1248
+ In this case, neither origin nor target in the C < Pair > are C < Str > ; the method
1249
+ with the C < Pair > signature then calls the second, making this call above
1250
+ equivalent to C < "abcd".trans: ["a"] = > ["zz"],> (with the comma behind, making
1251
+ it a C < Positional > , instead of a C < Pair > ), resulting in the behavior shown as
1252
+ output.
1253
+
1232
1254
= head2 method indent
1233
1255
1234
1256
multi method indent(Int $steps where { $_ == 0 } )
0 commit comments