Skip to content

Commit

Permalink
Changed TextFormatting.pm method names for consistency.
Browse files Browse the repository at this point in the history
  • Loading branch information
mathw committed Apr 21, 2009
1 parent 8fdbf76 commit f77ed6a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
14 changes: 7 additions & 7 deletions lib/Form/TextFormatting.pm
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Utility functions for formatting text in Form.pm.
enum Justify <left right centre full>;
enum Alignment <top middle bottom>;

sub chop_first_word(Str $source is rw) returns Str {
sub chop-first-word(Str $source is rw) returns Str {
if $source ~~ / ^^ (\S+) \s* (.*) $$ / {
my $word = ~$/[0];
$source = ~$/[1];
Expand All @@ -23,13 +23,13 @@ sub chop_first_word(Str $source is rw) returns Str {
}
}

sub fit_in_width(Str $text, Int $width) #{returns Array of Str} {
sub fit-in-width(Str $text, Int $width) #{returns Array of Str} {

my Str $fitted = '';
my Str $remainder = $text;
my Str $word;

while $word = chop_first_word($remainder) {
while $word = chop-first-word($remainder) {
if $fitted.chars + $word.chars <= $width {
$fitted ~= $word;
if $fitted.chars < $width {
Expand All @@ -55,16 +55,16 @@ sub fit_in_width(Str $text, Int $width) #{returns Array of Str} {
$remainder.=substr($width);
}

return (trim_ending_whitespace($fitted), $remainder);
return (trim-ending-whitespace($fitted), $remainder);
}


sub unjustified_wrap(Str $text, Int $width) #{returns Array of Str} {
sub unjustified-wrap(Str $text, Int $width) #{returns Array of Str} {
my $rem = $text;
my $line;

my @array = gather loop {
($line, $rem) = fit_in_width($rem, $width);
($line, $rem) = fit-in-width($rem, $width);
# we have to force a copy here or take will end up with the same value
# every single time! This might be a rakudo issue, or a spec issue
# or just expected behaviour
Expand All @@ -76,7 +76,7 @@ sub unjustified_wrap(Str $text, Int $width) #{returns Array of Str} {
return @array;
}

sub trim_ending_whitespace(Str $line) returns Str {
sub trim-ending-whitespace(Str $line) returns Str {
return $line.subst(/ <ws> $$ /, '');
}

Expand Down
8 changes: 4 additions & 4 deletions t/03-textformatting.t
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,19 @@ my $text = "The quick brown fox, jumps over the lazy dog.";
my $fitted;
my $remainder;

($fitted, $remainder) = Form::TextFormatting::fit_in_width($text, 6);
($fitted, $remainder) = Form::TextFormatting::fit-in-width($text, 6);
ok($fitted eq 'The', "First line fitted correctly");
ok($remainder eq 'quick brown fox, jumps over the lazy dog.', "First line remainder correct");
($fitted, $remainder) = Form::TextFormatting::fit_in_width($text, 20);
($fitted, $remainder) = Form::TextFormatting::fit-in-width($text, 20);
ok($fitted eq 'The quick brown fox,', "Wider line fitted correctly");
ok($remainder eq 'jumps over the lazy dog.', "Wider line remainder correct");
($fitted, $remainder) = Form::TextFormatting::fit_in_width($text, 2);
($fitted, $remainder) = Form::TextFormatting::fit-in-width($text, 2);
ok($fitted eq 'Th', 'Partial word fill correct');
ok($remainder eq 'e quick brown fox, jumps over the lazy dog.', 'Partial word remainder correct');


# now wrapping whole sets of lines
my @lines = Form::TextFormatting::unjustified_wrap($text, 6);
my @lines = Form::TextFormatting::unjustified-wrap($text, 6);
# okay, we should have...
my @expected = <The quick brown fox, jumps over the lazy dog.>;
ok(@lines.elems == 9, "Correct number of lines.");
Expand Down

0 comments on commit f77ed6a

Please sign in to comment.