Skip to content

Commit f7fcbb8

Browse files
committed
changes for successful tests
1 parent db3ab0f commit f7fcbb8

File tree

10 files changed

+136
-139
lines changed

10 files changed

+136
-139
lines changed

Changes

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{{$NEXT}}
2+
- Fix erroneous placement of exported subs
23

34
4.0.0 2025-07-17T07:52:24-05:00
45
- Released as new version 4.0.0
@@ -15,7 +16,7 @@
1516
+ added :clean-all option to normalize all parts of the split
1617
- Removed 'reverse' option from routine 'split-line'
1718
- Removed exported DEBUG $debug vaiable
18-
- Removed export keys for modules under Text::Utils
19+
- Removed export keys for modules under Text::Utils
1920
- Moved independent helper variables classes and subs to
2021
Text::Utils::* (Subs, Vars, Classes)
2122
- Moved sub 'normalize-text' to module 'Text::Utils::TaggedSubs'

META6.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
"Text::Utils": "lib/Text/Utils.rakumod",
2020
"Text::Utils::Classes": "lib/Text/Utils/Classes.rakumod",
2121
"Text::Utils::Subs": "lib/Text/Utils/Subs.rakumod",
22-
"Text::Utils::TaggedSubs": "lib/Text/Utils/TaggedSubs.rakumod",
2322
"Text::Utils::Vars": "lib/Text/Utils/Vars.rakumod"
2423
},
2524
"resources": [
Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,20 @@ use Text::Utils::Vars;
66
# normalize-string
77

88
# put in separate sub for use by other routines?
9+
910
#-----------------------------------------------------------------------
1011
#| Purpose : Trim a string and collapse multiple whitespace characters
1112
#| to single ones
1213
#| Params : The string to be normalized
1314
#| Returns : The normalized string
1415

15-
subset Kn of Any where { $_ ~~ /^ :i [0|k|n] /}; #= keep or normalize
16-
subset Sn of Any where { $_ ~~ /^ :i [0|n|s|t] /}; #= collapse all contiguous ws
17-
#constant &normalize-text is export(:normalize-text) = &normalize-string; # per lizmat, 2024-04-26
18-
our &normalize-text is export(:normalize-text) = &normalize-string; # per lizmat, 2024-04-26
16+
#= keep or normalize
17+
#subset Kn of Any is export where { $_ ~~ /^ :i [0|k|n] /};
18+
#= collapse all contiguous ws
19+
#subset Sn of Any is export where { $_ ~~ /^ :i [0|n|s|t] /};
20+
21+
# per lizmat, 2024-04-26
22+
our &normalize-text is export(:normalize-text) = &normalize-string;
1923
sub normalize-string(
2024
Str:D $str is copy,
2125
Kn :t(:$tabs)=0, #= keep or normalize

lib/Text/Utils.rakumod

Lines changed: 125 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ unit module Text::Utils;
22

33
use Text::Utils::Vars;
44
use Text::Utils::Subs;
5-
use Text::Utils::TaggedSubs :ALL;
65

76
use Font::AFM;
87

@@ -266,6 +265,131 @@ sub commify(
266265
267266
} # commify
268267
268+
#-----------------------------------------------------------------------
269+
#| Purpose : Trim a string and collapse multiple whitespace characters
270+
#| to single ones
271+
#| Params : The string to be normalized
272+
#| Returns : The normalized string
273+
274+
#= keep or normalize
275+
#subset Kn of Any is export where { $_ ~~ /^ :i [0|k|n] /};
276+
subset Kn of Any where * ~~ /^ :i [0|k|n] /;
277+
#= collapse all contiguous ws
278+
#subset Sn of Any is export where { $_ ~~ /^ :i [0|n|s|t] /};
279+
subset Sn of Any where * ~~ /^ :i [0|n|s|t] /;
280+
281+
# per lizmat, 2024-04-26
282+
our &normalize-text is export(:normalize-text) = &normalize-string;
283+
sub normalize-string(
284+
Str:D $str is copy,
285+
Kn :t(:$tabs)=0, #= keep or normalize
286+
Kn :n(:$newlines)=0, #= keep or normalize
287+
Sn :c(:$collapse-ws-to)=0, #= collapse all contiguous ws
288+
#= to one char
289+
:$no-trim, #= do not trim the input string
290+
--> Str
291+
) is export(:normalize-string) {
292+
# default is to always trim first, but to do so we must save the
293+
# original leading and trailing spaces
294+
my ($pre-ws, $post-ws);
295+
if $no-trim.defined {
296+
if $str ~~ /^ (\s+) / {
297+
$pre-ws = ~$0;
298+
}
299+
if $str ~~ / (\s+) $/ {
300+
$post-ws = ~$0;
301+
}
302+
$str .= trim;
303+
}
304+
else {
305+
$str .= trim;
306+
}
307+
308+
# then normalize all space characters
309+
$str ~~ s:g/ $WS ** 2..* /$WS/;
310+
311+
# then check for exceptions before normalizing all whitespace
312+
313+
# convenience aliases
314+
my $t = $tabs;
315+
my $c = $collapse-ws-to;
316+
my $n = $newlines;
317+
318+
if $collapse-ws-to {
319+
if $c ~~ /^ :i s / {
320+
# collapse all to a single space
321+
$str ~~ s:g/ $NL /$WS/;
322+
$str ~~ s:g/ $TAB /$WS/;
323+
$str ~~ s:g/ $WS ** 2..* /$WS/;
324+
}
325+
elsif $c ~~ /^ :i t / {
326+
# collapse all to a single tab
327+
$str ~~ s:g/ $WS /$TAB/;
328+
$str ~~ s:g/ $NL /$TAB/;
329+
$str ~~ s:g/ $TAB ** 2..* /$TAB/;
330+
}
331+
elsif $c ~~ /^ :i n / {
332+
# collapse all to a single newline
333+
$str ~~ s:g/ $WS /$NL/;
334+
$str ~~ s:g/ $TAB /$NL/;
335+
$str ~~ s:g/ $NL ** 2..* /$NL/;
336+
}
337+
}
338+
elsif $newlines and $tabs {
339+
if $t ~~ /^ :i k / {
340+
; # ok, a no-op
341+
}
342+
elsif $t ~~ /^ :i n / {
343+
$str ~~ s:g/ $TAB ** 2..* /$TAB/;
344+
}
345+
if $n ~~ /^ :i k / {
346+
; # ok, a no-op
347+
}
348+
elsif $n ~~ /^ :i n / {
349+
$str ~~ s:g/ $NL ** 2..* /$NL/;
350+
}
351+
}
352+
elsif $tabs {
353+
if $t ~~ /^ :i k / {
354+
; # ok, a no-op
355+
}
356+
elsif $t ~~ /^ :i n / {
357+
$str ~~ s:g/ $TAB ** 2..* /$TAB/;
358+
}
359+
}
360+
elsif $newlines {
361+
if $n ~~ /^ :i k / {
362+
; # ok, a no-op
363+
}
364+
elsif $n ~~ /^ :i n / {
365+
$str ~~ s:g/ $NL ** 2..* /$NL/;
366+
}
367+
}
368+
else {
369+
$str .= trim;
370+
$str ~~ s:g/ \s ** 2..* /$WS/;
371+
}
372+
373+
=begin comment
374+
else {
375+
#$str .= trim;
376+
# this also takes care of tabs and newlines
377+
$str ~~ s:g/ \s ** 2..*/ /;
378+
}
379+
=end comment
380+
381+
if $no-trim.defined {
382+
# add back any original leading or trailing spaces
383+
if $pre-ws {
384+
$str = $pre-ws ~ $str;
385+
}
386+
if $post-ws {
387+
$str = $str ~ $post-ws;
388+
}
389+
}
390+
$str;
391+
} # normalize-string
392+
269393
#-----------------------------------------------------------------------
270394
#| Purpose : Wrap a list of words into a paragraph with a maximum line
271395
#| width (default: 78) and update the input list with the

lib/Text/Utils/Subs.rakumod

Lines changed: 1 addition & 127 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ unit module Text::Utils::Subs;
55
use Test;
66

77
use Text::Utils::Vars;
8-
use Text::Utils::TaggedSubs;
8+
#use Text::Utils::TaggedSubs;
99

1010
sub calc-limit(
1111
Str:D :$line!,
@@ -65,7 +65,6 @@ sub calc-pieces(
6565
@pieces;
6666
}
6767

68-
6968
sub is-odd(
7069
UInt $num
7170
--> Bool
@@ -231,131 +230,6 @@ sub core-split-wmods(
231230
@res;
232231
}
233232

234-
=begin comment
235-
# # define "aliases" for convenience (with unique export keys)
236-
# our &strip is export(:strip) = &strip-comment;
237-
238-
# put in separate sub for use by other routines?
239-
#-----------------------------------------------------------------------
240-
#| Purpose : Trim a string and collapse multiple whitespace characters
241-
#| to single ones
242-
#| Params : The string to be normalized
243-
#| Returns : The normalized string
244-
subset Kn of Any is export where { $_ ~~ /^ :i [0|k|n] /}; #= keep or normalize
245-
subset Sn of Any is export where { $_ ~~ /^ :i [0|n|s|t] /}; #= collapse all contiguous ws
246-
247-
our &normalize-text is export(:normalize-text) = &normalize-string; # per lizmat, 2024-04-26
248-
sub normalize-string(
249-
Str:D $str is copy,
250-
Kn :t(:$tabs)=0, #= keep or normalize
251-
Kn :n(:$newlines)=0, #= keep or normalize
252-
Sn :c(:$collapse-ws-to)=0, #= collapse all contiguous ws
253-
#= to one char
254-
:$no-trim, #= do not trim the input string
255-
--> Str
256-
) is export(:normalize-string) {
257-
# default is to always trim first, but to do so we must save the
258-
# original leading and trailing spaces
259-
my ($pre-ws, $post-ws);
260-
if $no-trim.defined {
261-
if $str ~~ /^ (\s+) / {
262-
$pre-ws = ~$0;
263-
}
264-
if $str ~~ / (\s+) $/ {
265-
$post-ws = ~$0;
266-
}
267-
$str .= trim;
268-
}
269-
else {
270-
$str .= trim;
271-
}
272-
273-
# then normalize all space characters
274-
$str ~~ s:g/ $WS ** 2..* /$WS/;
275-
276-
# then check for exceptions before normalizing all whitespace
277-
278-
# convenience aliases
279-
my $t = $tabs;
280-
my $c = $collapse-ws-to;
281-
my $n = $newlines;
282-
283-
if $collapse-ws-to {
284-
if $c ~~ /^ :i s / {
285-
# collapse all to a single space
286-
$str ~~ s:g/ $NL /$WS/;
287-
$str ~~ s:g/ $TAB /$WS/;
288-
$str ~~ s:g/ $WS ** 2..* /$WS/;
289-
}
290-
elsif $c ~~ /^ :i t / {
291-
# collapse all to a single tab
292-
$str ~~ s:g/ $WS /$TAB/;
293-
$str ~~ s:g/ $NL /$TAB/;
294-
$str ~~ s:g/ $TAB ** 2..* /$TAB/;
295-
}
296-
elsif $c ~~ /^ :i n / {
297-
# collapse all to a single newline
298-
$str ~~ s:g/ $WS /$NL/;
299-
$str ~~ s:g/ $TAB /$NL/;
300-
$str ~~ s:g/ $NL ** 2..* /$NL/;
301-
}
302-
}
303-
elsif $newlines and $tabs {
304-
if $t ~~ /^ :i k / {
305-
; # ok, a no-op
306-
}
307-
elsif $t ~~ /^ :i n / {
308-
$str ~~ s:g/ $TAB ** 2..* /$TAB/;
309-
}
310-
if $n ~~ /^ :i k / {
311-
; # ok, a no-op
312-
}
313-
elsif $n ~~ /^ :i n / {
314-
$str ~~ s:g/ $NL ** 2..* /$NL/;
315-
}
316-
}
317-
elsif $tabs {
318-
if $t ~~ /^ :i k / {
319-
; # ok, a no-op
320-
}
321-
elsif $t ~~ /^ :i n / {
322-
$str ~~ s:g/ $TAB ** 2..* /$TAB/;
323-
}
324-
}
325-
elsif $newlines {
326-
if $n ~~ /^ :i k / {
327-
; # ok, a no-op
328-
}
329-
elsif $n ~~ /^ :i n / {
330-
$str ~~ s:g/ $NL ** 2..* /$NL/;
331-
}
332-
}
333-
else {
334-
$str .= trim;
335-
$str ~~ s:g/ \s ** 2..* /$WS/;
336-
}
337-
338-
=begin comment
339-
else {
340-
#$str .= trim;
341-
# this also takes care of tabs and newlines
342-
$str ~~ s:g/ \s ** 2..*/ /;
343-
}
344-
=end comment
345-
346-
if $no-trim.defined {
347-
# add back any original leading or trailing spaces
348-
if $pre-ws {
349-
$str = $pre-ws ~ $str;
350-
}
351-
if $post-ws {
352-
$str = $str ~ $post-ws;
353-
}
354-
}
355-
$str;
356-
} # end of sub normalize-string
357-
=end comment
358-
359233
=finish
360234
=begin comment
361235
sub core-split(

t/0-load.t

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ my @modules = <
44
Text::Utils
55
Text::Utils::Classes
66
Text::Utils::Subs
7-
Text::Utils::TaggedSubs
87
Text::Utils::Vars
98
>;
109

t/14-normalize-string.t

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use Test;
22

33
use Text::Utils :ALL;
44
use Text::Utils::Subs :ALL;
5-
use Text::Utils::TaggedSubs :ALL;
65

76
plan 27;
87

t/16-split-line.t

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use Test;
22

33
use Text::Utils :ALL;
44
use Text::Utils::Subs :ALL;
5-
use Text::Utils::TaggedSubs;
65

76
plan 26;
87

t/17b-strip-comment.t

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use Test;
33
use File::Temp;
44

55
use Text::Utils :ALL; #:strip-comment :normalize-string;
6-
use Text::Utils::TaggedSubs :ALL; #:strip-comment :normalize-string;
76

87
my $debug = 0; # output files are placed in local dir "tmp"
98

t/21-newline-in-cells.t

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use Test;
22

33
use Text::Utils :ALL;
44
use Text::Utils::Subs :ALL;
5-
use Text::Utils::TaggedSubs :ALL;
65

76
plan 17;
87

0 commit comments

Comments
 (0)