CMS 3D CMS Logo

Functions
wordWrappers Namespace Reference

Functions

def wrap_always (text, width)
 
def wrap_onspace (text, width)
 
def wrap_onspace_strict (text, width)
 

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 8 of file wordWrappers.py.

References createfilelist.int, and join().

Referenced by wrap_onspace_strict().

8 def wrap_always(text, width):
9  """
10  A simple word-wrap function that wraps text on exactly width characters.
11  It doesn't split the text in words.
12  """
13  return '\n'.join([ text[width*i:width*(i+1)] \
14  for i in range(int(math.ceil(1.*len(text)/width))) ])
15 
def wrap_always(text, width)
Definition: wordWrappers.py:8
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 16 of file wordWrappers.py.

Referenced by wrap_onspace_strict().

16 def wrap_onspace(text,width):
17  """
18  A word-wrap function that preserves existing line breaks
19  and most spaces in the text. Expects that existing line
20  breaks are posix newlines (\n).
21  """
22  return reduce(lambda line, word, width=width: '%s%s%s' %
23  (line,
24  ' \n'[(len(line[line.rfind('\n')+1:])
25  + len(word.split('\n',1)[0]
26  ) >= width)],
27  word),
28  text.split(' ')
29  )
def wrap_onspace(text, width)
Definition: wordWrappers.py:16
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 30 of file wordWrappers.py.

References join(), edm.print(), str, wrap_always(), and wrap_onspace().

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