Anonymous user
Word wrap: Difference between revisions
m
→{{header|REXX}}: replaced with a shorter program, changed the way "JUSTIFY" is specified. -- ~~~~
(added ocaml) |
m (→{{header|REXX}}: replaced with a shorter program, changed the way "JUSTIFY" is specified. -- ~~~~) |
||
Line 368:
<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 (Classic) pgm
arg justify width . /*───────JUSTIFY─────────────*/
if width=='' then width=linesize()%2; if width==0 then width=40▼
/*Both: <──both margins──> */
/*Right: ─────>right margin */
/*Left: left margin<─────- */
/*─────pick one of the above.*/
just=left(justify,1) /*only use 1st capital letter*/
end▼
txt=space(txt) /*eliminate superflous blanks. */▼
if
txt="Diplomacy is the art of saying 'Nice Doggy' until",
/*─────────────────────────────────────where the rubber meets the road. */▼
"you can find a rock. ─── Will Rodgers"
if length(_)>width then call tell /*this word exceeded linewidth ? */▼
▲call tell /*handle any residual words. */
$='' /*this is where the money is.*/
do k=1 for words(txt) /*parse 'til we exhaust TXT. */
/*─────────────────────────────────────TELL subroutine──────────────────*/▼
_=$ x /*append it to da money & see*/
call tell /*handle any residual words. */
exit /*let's go home & celebrate. */
tell: if $=='' then return /*first word may be too long.*/
select
when just=='B' then $=justify($,width) /*<───both───>*/
when just=='C' then $= center($,width) /* <centered> */
when just=='R' then $= right($,width) /*──────>right*/
otherwise $= strip($) /*left<───────*/
end
say $ /*show&tell, or write──>file?*/
_=x /*handle any word overflow. */
return /*go back and keep truckin'. */
</lang>
The input file:
Line 499 ⟶ 503:
∙ Parameters are variables travelling under an assumed name.
</pre>
Output when specifying: <tt> , 155 </tt>
<pre style="height:15ex;overflow:scroll">
────────── Computer programming laws ────────── The Primal Scenario -or- Basic Datum of Experience: ∙ Systems in general work poorly or not at all. ∙
Line 537 ⟶ 541:
assumed name.
</pre>
Output when specifying: <tt> , 76 </tt>
<pre style="height:15ex;overflow:scroll">
────────── Computer programming laws ────────── The Primal Scenario -or-
Line 612 ⟶ 616:
variables.) ∙ Parameters are variables travelling under an assumed name.
</pre>
Output [justified] when specifying: <tt>
<pre style="height:15ex;overflow:scroll">
────────── Computer programming laws ────────── The Primal Scenario
|