Anonymous user
Word wrap: Difference between revisions
m
→{{header|REXX}}: added/changed comments, added whitespace. -- ~~~~
(→{{header|C}}: new) |
m (→{{header|REXX}}: added/changed comments, added whitespace. -- ~~~~) |
||
Line 549:
<br>No hyphenation (or de-hyphenation) is attempted.
<br>Words longer than the width of the output are acceptable and are shown, a simple change could be made to issue a notification.
<lang rexx>/*REXX
arg justify width . /*───────────JUSTIFY─────────────*/
▲/*REXX (Classic) pgm justifies (by words) a string of words──>screen*/
▲ /*Center: <centered> */
▲ /*Both: <──both margins──> */
▲ /*Right: ─────>right margin */
▲ /*Left: left margin<─────- */
▲ /*─────pick one of the above.*/
▲if width=='' then width=linesize()%2 /*null? Then pick a default.*/
▲if width==0 then width=40 /*not determinable? Use 40.*/
txt="Diplomacy is the art of saying 'Nice Doggy' until",
"you can find a rock. ─── Will Rodgers"
$='' /*this is where the money is. */▼
▲$='' /*this is where the money is.*/
do k=1 for words(txt);
▲ if length(_)>width then call tell /*word(s) exceeded the width?*/
end
call tell /*handle any residual words. */
exit /*
/*──────────────────────────────────TELL subroutine─────────────────────*/
tell: if $=='' then return /*first word may be too long. */▼
▲tell: if $=='' then return /*first word may be too long.*/
select
when just=='B' then $=justify($,width) /*
when just=='C' then $= center($,width) /*
when just=='R' then $= right($,width) /*
otherwise $= strip($) /*left
end /*select*/
say $ /*show
_=x /*handle any word overflow. */
return /*go back and keep truckin'. */</lang>
The input file:
<pre style="height:15ex;overflow:scroll">
|