helper for wrapping lines
328424
function (parts, indent, prefix) {
        var lines = [];
        var line = [];

        var lineLength = !!prefix ? prefix.length - 1: indent.length - 1;

        parts.forEach(function (part) {
          if (lineLength + 1 + part.length > textWidth) {
            lines.push(indent + line.join(' '));
            line = [];
            lineLength = indent.length - 1;
          }
          line.push(part);
          lineLength += part.length + 1;
        });

        if (line) {
          lines.push(indent + line.join(' '));
        }
        if (prefix) {
          lines[0] = lines[0].substr(indent.length);
        }
        return lines;
      }
134834
def trim_lines(lines)
      new_lines = lines.dup
      while new_lines[-1] && new_lines[-1].strip.empty?
        new_lines.pop
      end
      new_lines
    end
187707
def normalize_multiline(line):
    
    if line.startswith('def ') and line.rstrip().endswith(':'):
        return line + ' pass'
    elif line.startswith('return '):
        return 'def _(): ' + line
    elif line.startswith('@'):
        return line + 'def _(): pass'
    elif line.startswith('class '):
        return line + ' pass'
    elif line.startswith(('if ', 'elif ', 'for ', 'while ')):
        return line + ' pass'
    else:
        return line
375365
def wrap(self, string, width):
        
        if not string or width <= 0:
            logging.error("invalid string: %s or width: %s" % (string, width))
            return False

        tmp = ""
        for line in string.splitlines():
            if len(line) <= width:
                tmp += line + "\n"
                continue

            cur = 0
            length = len(line)
            while cur + width < length:
                cur = line[:cur+width].rfind(self.sep) + len(self.sep) - 1
                line = line[:cur] + "\n" + line[cur+1:]

            tmp += line + "\n\n"

        return tmp
449097
def format_line(data, linestyle):
    """"""
    return linestyle.begin + linestyle.sep.join(data) + linestyle.end
407283
def word_wrap(self, text, width=1023):
        
        substrings = []

        string = text
        while len(string) > width:
            index = width - 1
            while not string[index].isspace():
                index = index - 1

            line = string[0:index]
            substrings.append(line)

            string = string[index + 1:]

        substrings.append(string)

        return substrings
1094754
def _indent_line(self, line, stripspace=''):
        """"""

        return re.sub(r"^%s" % stripspace, self.indentstring
                      * self.indent, line)
1098267
def lines(self, code):
        """"""
        if isinstance(code, str):
            fix_indentation = self.fix_indentation
            if fix_indentation:
                code = fix_indentation(code)
            return self.append(code)
        else:
            return self.append(code)
1037729
def optwrap(self, text):
        """"""
        if not self.body_width:
            return text

        assert wrap, "Requires Python 2.3."
        result = ''
        newlines = 0
        for para in text.split("\n"):
            if len(para) > 0:
                if not skipwrap(para):
                    result += "\n".join(wrap(para, self.body_width))
                    if para.endswith('  '):
                        result += "  \n"
                        newlines = 1
                    else:
                        result += "\n\n"
                        newlines = 2
                else:
                    if not onlywhite(para):
                        result += para + "\n"
                        newlines = 1
            else:
                if newlines < 2:
                    result += "\n"
                    newlines += 1
        return result
950314
def dedent(lines):
    """"""
    if len(lines) != 0:
        first_lstrip = lines[0].lstrip()
        strip_len = len(lines[0]) - len(first_lstrip)
        for line in lines:
            if len(line[:strip_len].strip()) != 0:
                raise ValueError('less indentation than first line: ' +
                                 line)
            else:
                yield line[strip_len:]
728428
function TplWrap(name, runtime, root, scope, buffer, originalName, fn, parent) {
  this.name = name;
  this.originalName = originalName || name;
  this.runtime = runtime;
  this.root = root;
  // line counter
  this.pos = {line: 1};
  this.scope = scope;
  this.buffer = buffer;
  this.fn = fn;
  this.parent = parent;
}
588110
function wrap(input, wrap, ends) {

  if(!isString(input) || isUndefined(wrap)) {
    return input;
  }

  return [wrap, input, ends || wrap].join('');

}
1158808
function formatLinesWith (formatter, str) {
  return str
    .split('\n')
    .map(function (line) {
      return line.length ? formatter(line) : ''
    })
    .join('\n')
}
980792
String wrap(String toWrap, int len, int start) {
    StringBuilder buff = new StringBuilder();
    StringBuilder line = new StringBuilder();

    char[] head = new char[start];
    Arrays.fill(head, ' ');

    for (StringTokenizer tok = new StringTokenizer(toWrap, " ");
         tok.hasMoreTokens();) {
      String next = tok.nextToken();
      final int x = line.length();
      line.append(line.length() == 0 ? "" : " ").append(next);
      if (line.length() > len) {
        // The line is now too long. Backtrack: remove the last word, start a
        // new line containing just that word.
        line.setLength(x);
        buff.append(line).append(SEPARATOR).append(head);
        line.setLength(0);
        line.append(next);
      }
    }

    buff.append(line);

    return buff.toString();
  }
550642
private String wrapLine(String str) {
	int wtl = wraptext;

	if (str.length() <= wtl) return str;

	String sub = str.substring(0, wtl);
	String rest = str.substring(wtl);
	char firstR = rest.charAt(0);
	String ls = System.getProperty("line.separator");

	if (firstR == ' ' || firstR == '\t') return sub + ls + wrapLine(rest.length() > 1 ? rest.substring(1) : "");

	int indexSpace = sub.lastIndexOf(' ');
	int indexTab = sub.lastIndexOf('\t');
	int index = indexSpace <= indexTab ? indexTab : indexSpace;

	if (index == -1) return sub + ls + wrapLine(rest);
	return sub.substring(0, index) + ls + wrapLine(sub.substring(index + 1) + rest);

    }
529024
def wrap(text, width, *args, **kwargs):
    

    return sum([textwrap.wrap(line, width, *args, **kwargs)
                if line else [''] for line in text.splitlines()], [])
929627
def unindent(self, lines):
        """"""
        indent = min(
            len(self.re.match(r'^ *', line).group()) for line in lines)
        return [line[indent:].rstrip() for line in lines]