Method code for $list.columnize2()

[Turn off line numbering]
  1: arg list, cols, @rest;
  2: var width, lines, line, separator, linelength, x, handled_length;
  3: 
  4: // turn [...] into ".   .   ."
  5: // rest[1]==separator; rest[2]==linelength
  6: [(separator ?= "   "), (linelength ?= 78)] = rest;
  7: width = linelength / cols - separator.length();
  8: lines = [];
  9: for x in [1 .. list.length() / cols] {
 10:     line = list.subrange(x * cols - 1, cols).mmap('pad, width).join(separator);
 11:     lines += [line];
 12: }
 13: handled_length = x * cols;
 14: if (list.length() != handled_length)
 15:     lines += [list.subrange(handled_length + 1).mmap('pad, width).join(separator)];
 16: return lines;

// Created 27-Mar-1995 as a part of ColdCore, see: @help Credit

Tlon