Apl2ToDoTextArrangementAlgorithms
This is a sub-page of PhraseBook/ToDo/Apl2Idioms
CM←(-⌊.5×+/^\⌽CM=' ')⌽CM ⍝ Centering left justified CM.
CM←(⌈.5×+/^\CM=' ')⌽CM ⍝ Centering right justified CM.
CM←(⌈.5×↑-/+/¨^\¨B(⌽B←CM=' '))⌽CM⍝ Centering non-justified CM.
CM←(+/^\CM=' ')⌽CM ⍝ Left justify matrix CM.
CM←(1-(1,CM=' ')⊥1)⌽CM ⍝ Right justify matrix CM.
C←(-⌊.5×0⌈NS-⍴C)⌽NS↑C ⍝ Centering C in field width NS.
C←(-NS)↑C ⍝ Left justify C in field width NS.
C←NS↑C ⍝ Right justify C in field width NS.
CM←(1+B)⌿CM ⍝ Replicate CM at rows indicated by B.
(,M)←(,M)[⍋,(2×⍳↑⍴M)+[0]' '=M] ⍝ Move blanks to end of each row of M.
(,M)←(,M)[⍋,(2×⍳↑⍴M)+[1]' '=M] ⍝ Move blanks to end of each row of M.
CM←(' '∨.≠CM)/CM ⍝ Remove blank columns.
CM←(CM∨.≠' ')⌿CM ⍝ Remove blank rows.
CM←(¯1↓1,B∨1⌽B←' '∨.≠CM)/CM ⍝ Remove duplicate blank columns.
CM←(¯1↓1,B∨1⌽B←CM∨.≠' ')⌿CM ⍝ Remove duplicate blank rows.
V←1↓(B∨1⌽B←0,C≠' ')/' ',C ⍝ Remove lead, trail, and duplicate blanks.
CM←(∨\' '∨.≠CM)/CM ⍝ Remove leading blank columns.
CM←(∨\CM∨.≠' ')⌿CM ⍝ Remove leading blank rows.
CM←(1-(1,' '^.=CM)⊥1)↓[1]CM ⍝ Remove trailing blank columns.
CM←(1-(1,' '^.=CM)⊥1)↓[2]CM ⍝ Remove trailing blank columns.
CM←(1-(1,CM^.=' ')⊥1)↓[0]CM ⍝ Remove trailing blank rows.
CM←(1-(1,CM^.=' ')⊥1)↓[1]CM ⍝ Remove trailing blank rows.
V←(∨\C≠' ')/C ⍝ Remove leading blanks.
V←(⌽∨\⌽C≠' ')/C ⍝ Remove trailing blanks.
((1=⌈\' 0'⍳C)/C)←' ' ⍝ Replace leading zeros with blanks.
((2=⌈\' 0'⍳C)/C)←' ' ⍝ Replace leading zeros with blanks.
VV←⍎ε'''',C,↑''''((C=' ')/C)←⊂''' ''' ⍝ Sentence to vector of words.
VV←((2>/1,B)/⍳⍴B)↓¨(1+(2</B,1)/⍳⍴B←C=' ')↑¨⊂C ⍝ Sentence to vector of words.
VV←(¯1+(2>/1,B)/⍳⍴B)↓¨((2</B,1)/⍳⍴B←C=' ')↑¨⊂C⍝ Sentence to vector of words.`
VV←(C≠' ')⊂C ⍝ Sentence to vector of words.
C←ε' ',¨VV ⍝ Sentence from vector of words.
CM←⊃(~VεC)⊂V ⍝ Vector to matrix at selected characters.
C←(IS×⍴C)⍴C ⍝ Copies. Create IS copies of C.
APL Wiki