def _align_column()

in c3dm/tools/tabulate.py [0:0]


def _align_column(strings, alignment, minwidth=0,
				  has_invisible=True, enable_widechars=False, is_multiline=False):
	"""[string] -> [padded_string]"""
	strings, padfn = _align_column_choose_padfn(strings, alignment, has_invisible)
	width_fn = _choose_width_fn(has_invisible, enable_widechars, is_multiline)

	s_widths = list(map(width_fn, strings))
	maxwidth = max(max(s_widths), minwidth)
	# TODO: refactor column alignment in single-line and multiline modes
	if is_multiline:
		if not enable_widechars and not has_invisible:
			padded_strings = [
				"\n".join([padfn(maxwidth, s) for s in ms.splitlines()])
				for ms in strings]
		else:
			# enable wide-character width corrections
			s_lens = [max((len(s) for s in re.split("[\r\n]", ms))) for ms in strings]
			visible_widths = [maxwidth - (w - l) for w, l in zip(s_widths, s_lens)]
			# wcswidth and _visible_width don't count invisible characters;
			# padfn doesn't need to apply another correction
			padded_strings = ["\n".join([padfn(w, s) for s in (ms.splitlines() or ms)])
							  for ms, w in zip(strings, visible_widths)]
	else:  # single-line cell values
		if not enable_widechars and not has_invisible:
			padded_strings = [padfn(maxwidth, s) for s in strings]
		else:
			# enable wide-character width corrections
			s_lens = list(map(len, strings))
			visible_widths = [maxwidth - (w - l) for w, l in zip(s_widths, s_lens)]
			# wcswidth and _visible_width don't count invisible characters;
			# padfn doesn't need to apply another correction
			padded_strings = [padfn(w, s) for s, w in zip(strings, visible_widths)]
	return padded_strings