@@ -23,55 +23,48 @@ use Text::More :strip-comment;
2323# the '#' is the default comment character
2424my $ line = " some text # a comment" ;
2525$ line = strip-comment $ line ;
26- say $ line # OUTPUT: « some text »
26+ say $ line ; # OUTPUT: « some text »
2727```
28- If you want to be fancier:
28+ If you want to be fancier, return the stripped line and its comment,
29+ bit normalized (trimmed of leading and trailing spaces, contiguous
30+ spaces collapsed to one):
2931
3032``` raku
3133# define your own comment character(s)
3234# save the comment and normalize the returned strings
3335my ($ line , $ comm ) = strip-comment $ line , : mark<%% >, : save-comment, : normalize;
34- say $ line # OUTPUT: «some text»
35- say $ comm # OUTPUT: «a comment»
36+ say $ line ; # OUTPUT: «some text»
37+ say $ comm ; # OUTPUT: «a comment»
3638```
37-
3839The default behavior is to find the first comment character in the input
3940string, but you may choose to start the search from the end of the
4041input string:
4142
4243``` raku
4344my $ line = " text 1 # text 2 # comment" ;
4445$ line = strip-comment $ line , : reverse;
45- say $ line # OUTPUT: «text 1 # text 2 »
46+ say $ line ; # OUTPUT: «text 1 # text 2 »
4647```
47-
4848Note that the routine is line oriented, so embedded newlines
4949may give unexpected results:
50-
5150``` raku
5251my $ line = q :to /HERE /;
5352text 1 # comment 1
5453text 2 # comment 2
5554HERE
5655$ line = strip-comment $ line
57- say $ line # OUTPUT: «text 1 »
56+ say $ line ; # OUTPUT: «text 1 »
5857```
59-
6058## Installation
61-
6259``` Raku
6360zef install Text::Utils
6461```
65-
6662## Documentation
67-
6863``` Raku
6964zef install p6doc
7065p6doc Text::Utils
7166```
72-
7367## See also
74-
7568- ` Text::Abbrev `
7669- ` Text::BorderedBlock `
7770- ` Text::Diff::Sift4 `
0 commit comments