def soft_break(value, length, process=(lambda chunk: chunk)):
 delimiters = re.compile('([{}]+)'.format(''.join(map(re.escape, ',.$:/+@!?()<>[]{}'))))
 def soft_break_delimiter(match):
  results = []
  value = match.group(0)
  chunks = delimiters.split(value)
  for (i, chunk) in enumerate(chunks):
   if ((i % 2) == 1):
    results.extend([chunk, u'\u200b'])
   else:
    results.append(process(chunk))
  return u''.join(results).rstrip(u'\u200b')
 return re.sub('\\S{{{},}}'.format(length), soft_break_delimiter, value)

def soft_break ( value , length , process = ( lambda chunk : chunk ) ) : delimiters = re . compile ( '([{}]+)' . format ( '' . join ( map ( re . escape , ',.$:/+@!?()<>[]{}' ) ) ) ) def soft_break_delimiter ( match ) : results = [ ] value = match . group ( 0 ) chunks = delimiters . split ( value ) for ( i , chunk ) in enumerate ( chunks ) : if ( ( i % 2 ) == 1 ) : results . extend ( [ chunk , u'\u200b' ] ) else : results . append ( process ( chunk ) ) return u'' . join ( results ) . rstrip ( u'\u200b' ) return re . sub ( '\\S{{{},}}' . format ( length ) , soft_break_delimiter , value )
encourages soft breaking of text values above a maximum length by adding zero-width spaces after common delimeters .