test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Functions
wordWrappers Namespace Reference

Functions

def wrap_always
 
def wrap_onspace
 
def wrap_onspace_strict
 

Function Documentation

def wordWrappers.wrap_always (   text,
  width 
)
A simple word-wrap function that wraps text on exactly width characters.
It doesn't split the text in words.

Definition at line 6 of file wordWrappers.py.

References join().

Referenced by wrap_onspace_strict().

6 
7 def wrap_always(text, width):
8  """
9  A simple word-wrap function that wraps text on exactly width characters.
10  It doesn't split the text in words.
11  """
12  return '\n'.join([ text[width*i:width*(i+1)] \
13  for i in xrange(int(math.ceil(1.*len(text)/width))) ])
static std::string join(char **cmd)
Definition: RemoteFile.cc:18
def wordWrappers.wrap_onspace (   text,
  width 
)
A word-wrap function that preserves existing line breaks
and most spaces in the text. Expects that existing line
breaks are posix newlines (\n).

Definition at line 14 of file wordWrappers.py.

Referenced by wrap_onspace_strict().

14 
15 def wrap_onspace(text,width):
16  """
17  A word-wrap function that preserves existing line breaks
18  and most spaces in the text. Expects that existing line
19  breaks are posix newlines (\n).
20  """
21  return reduce(lambda line, word, width=width: '%s%s%s' %
22  (line,
23  ' \n'[(len(line[line.rfind('\n')+1:])
24  + len(word.split('\n',1)[0]
25  ) >= width)],
26  word),
27  text.split(' ')
)
def wordWrappers.wrap_onspace_strict (   text,
  width 
)
Similar to wrap_onspace, but enforces the width constraint:
words longer than width are split.

Definition at line 28 of file wordWrappers.py.

References join(), wrap_always(), and wrap_onspace().

28 
29 def wrap_onspace_strict(text, width):
30  """
31  Similar to wrap_onspace, but enforces the width constraint:
32  words longer than width are split.
33  """
34  wordRegex = re.compile(r'\S{'+str(width)+r',}')
35  return wrap_onspace(wordRegex.sub(lambda m: wrap_always(m.group(),width),text),width)
def wrap_onspace_strict
Definition: wordWrappers.py:28