www.srekcah.org > ~utashiro > perl > scripts > fold_pl

fold_pl

What's this?

文字列を指定した場所で2つに分割するためのライブラリです。通 常の ASCII 文字列であれば、Perl の format や unpack 、あるいは 正規表現などを使って簡単にできますが、日本語文字列の場合には、 文字の途中で折り返さないように処理しなければなりません。

また、タブ、バックスペース、キャリッジリターンなどの制御文 字も考慮して処理しますので、画面やプリンタで表示される文字幅を 正確に指定することが可能です。オプションで、パディング、ワード 境界での折り返し、タブの展開、開始カラム数等を指定することがで きます。

単独のコマンドとしても実行することができ、この場合 Unix の fold(1) コマンドとほぼ同じような動きをします。

Library Interface

SYNOPSIS

require 'fold.pl';
($folded, $rest) = &fold(LINE, WIDTH, PADDING, ONWORD, EXPAND, COLUMN);

DESCRIPTION

Pass the line to be folded as a first argument and folding width as a second argument. If optional third argument is true, space character will be padded at the end of the line if necessary. If the fourth argument is true, the line is folded on the word boundaries. The fifth argument is a string which specifies what character is expanded by spaces and backspaces ('r' for carriage return, 't' for tab and 'a' for all). The sixth argument specifies start column of the string to caliculate tab stop.

Return value is a list of a folded line and the rest.

Bugs

stripe コマンドが、どうも perl5 の環境ではうまく動かないよう です。デバッグしてる暇がないので、原因がわかった方は連絡してくだ さい。もっとも、動いたところで何かの役に立つというわけではないの ですが。

Command Interface

Usage:  fold.pl [-width] [-w] [-p] [-t] [-f] [-s]
        -width: specify folding width (default 80)
        -w:     fold on word boundaries
        -p:     put padding spaces at the end of line
        -t:     truncate by width
        -f:     replace final newline by space and fill text
        -s:     delete leading space

Files