mirror of
https://github.com/kennethreitz/clint.git
synced 2026-06-05 06:46:16 +00:00
eng.plural!
This commit is contained in:
@@ -0,0 +1,43 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
"""
|
||||||
|
clint.eng
|
||||||
|
~~~~~~~~~
|
||||||
|
|
||||||
|
This module provides English language string helpers.
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
MORON_MODE = False
|
||||||
|
COMMA = ','
|
||||||
|
CONJUNCTION = 'and'
|
||||||
|
SPACE = ' '
|
||||||
|
|
||||||
|
|
||||||
|
def join(l, conj=CONJUNCTION, im_a_moron=MORON_MODE, seperator=COMMA):
|
||||||
|
"""Joins lists of words. Oxford comma and all."""
|
||||||
|
|
||||||
|
collector = []
|
||||||
|
left = len(l)
|
||||||
|
seperator = seperator + SPACE
|
||||||
|
conj = conj + SPACE
|
||||||
|
|
||||||
|
for _l in l[:]:
|
||||||
|
|
||||||
|
left += -1
|
||||||
|
|
||||||
|
collector.append(_l)
|
||||||
|
if left > 1:
|
||||||
|
collector.append(seperator)
|
||||||
|
elif left == 1:
|
||||||
|
if len(l) == 2 or im_a_moron:
|
||||||
|
print
|
||||||
|
collector.append(SPACE)
|
||||||
|
else:
|
||||||
|
collector.append(seperator)
|
||||||
|
|
||||||
|
collector.append(conj)
|
||||||
|
elif left == 0:
|
||||||
|
pass
|
||||||
|
|
||||||
|
return unicode(''.join(collector))
|
||||||
Reference in New Issue
Block a user