Changeset 7547


Ignore:
Timestamp:
2004-06-03T13:09:28+12:00 (20 years ago)
Author:
kjdon
Message:

the text::wrap module is not a standard one apparently, so I have made my own function to wrap the long lines (copied from Michaels stuff)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gsdl/perllib/plugins/MARCPlug.pm

    r7533 r7547  
    6666#use MARC::Record; 
    6767#use MARC::Batch;
    68 use Text::Wrap;
    6968
    7069sub new {
     
    251250
    252251    # line wrapping
    253     $Text::Wrap::columns = 80;
    254     $$textref = wrap("", "", $$textref);
    255 
     252    $$textref = &wrap_text_in_columns($$textref, 80);
    256253    $$textref = "<pre>\n" . $$textref . "</pre>\n"; # HTML formatting...
    257254
     
    261258}
    262259
     260sub wrap_text_in_columns
     261{
     262    my ($text, $columnwidth) = @_;
     263    my $newtext = "";
     264    my $linelength = 0;
     265   
     266    # Break the text into words, and display one at a time
     267    my @words = split(/ /, $text);
     268
     269    foreach $word (@words) {
     270    # If printing this word would exceed the column end, start a new line
     271    if (($linelength + length($word)) >= $columnwidth) {
     272        $newtext .= "\n";
     273        $linelength = 0;
     274    }
     275   
     276    # Write the word
     277    $newtext .= " $word";
     278    if ($word =~ /\n/) {
     279        $linelength = 0;
     280    } else {
     281        $linelength = $linelength + length(" $word");
     282    }
     283    }
     284
     285    $newtext .= "\n";
     286    return $newtext;
     287}
    263288
    264289
Note: See TracChangeset for help on using the changeset viewer.