Return a fixed-length straight line with some text at the center.
        
        Usage Example::
            
            >>> StringTemplate.straight_line("Hello world!", 20, "-", 1)
            --- Hello world! ---
968876
def straight_line(title, length=100, linestyle="=", pad=0):
        
        text = "{:%s^%s}" % (linestyle, length)
        return text.format("%s%s%s" % (" "*pad, title, " "*pad))
1026438
function(text, length, moreText) {
    return text.length > length ? text.slice(0, length).trim() + moreText : text;
  }
1069551
def format(self, template=None):
        
        pattern = r"(?:<([^<]*?)\$(\w+)([^>]*?)>)"
        s = sub(pattern, self._format_repl, template or self.template)
        s = self._str_fix_whitespace(s)
        return s
40713
def right_align(value, length):
    
    if length <= 0:
        return u""

    value = text_type(value)

    if len(value) < length:
        return (" " * (length - len(value))) + value
    else:
        return value[-length:]
286856
function(str, length, pruneStr){
      if (str == null) return '';

      str = String(str); length = ~~length;
      pruneStr = pruneStr != null ? String(pruneStr) : '...';

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

      var tmpl = function(c){ return c.toUpperCase() !== c.toLowerCase() ? 'A' : ' '; },
        template = str.slice(0, length+1).replace(/.(?=\W*\w*$)/g, tmpl); // 'Hello, world' -> 'HellAA AAAAA'

      if (template.slice(template.length-2).match(/\w\w/))
        template = template.replace(/\s*\S+$/, '');
      else
        template = _s.rtrim(template.slice(0, template.length-1));

      return (template+pruneStr).length > str.length ? str : str.slice(0, template.length)+pruneStr;
    }
1318225
def get_fixed_long_line(target, previous_line, original,
                        indent_word='    ', max_line_length=79,
                        aggressive=False, experimental=False, verbose=False):
    
    indent = _get_indentation(target)
    source = target[len(indent):]
    assert source.lstrip() == source
    assert not target.lstrip().startswith('#')

    # Check for partial multiline.
    tokens = list(generate_tokens(source))

    candidates = shorten_line(
        tokens, source, indent,
        indent_word,
        max_line_length,
        aggressive=aggressive,
        experimental=experimental,
        previous_line=previous_line)

    # Also sort alphabetically as a tie breaker (for determinism).
    candidates = sorted(
        sorted(set(candidates).union([target, original])),
        key=lambda x: line_shortening_rank(
            x,
            indent_word,
            max_line_length,
            experimental=experimental))

    if verbose >= 4:
        print(('-' * 79 + '\n').join([''] + candidates + ['']),
              file=wrap_output(sys.stderr, 'utf-8'))

    if candidates:
        best_candidate = candidates[0]

        # Don't allow things to get longer.
        if longest_line_length(best_candidate) > longest_line_length(original):
            return None

        return best_candidate
1047605
def _fixed_source_line(self):
        
        line = self.lineno
        _node = self
        try:
            while line is None:
                _node = next(_node.get_children())
                line = _node.lineno
        except StopIteration:
            _node = self.parent
            while _node and line is None:
                line = _node.lineno
                _node = _node.parent
        return line
250537
def _hline(self):
        

        if not self._hline_string:
            self._hline_string = self._build_hline()
        return self._hline_string
1117777
public String lineProtocol() {
    StringBuilder sb = new StringBuilder();

    for (Point point : this.points) {
      sb.append(point.lineProtocol(this.precision)).append("\n");
    }
    return sb.toString();
  }
1302345
def text(short):
    """"""
    return indent(short, branch_method=html_block_tag, leaf_method=convert_line, pass_syntax=PASS_SYNTAX,
                  flush_left_syntax=FLUSH_LEFT_SYNTAX, flush_left_empty_line=FLUSH_LEFT_EMPTY_LINE,
                  indentation_method=find_indentation)
1217105
def get_line_str(self):
        """"""
        if self.from_string:
            return ' '.join([s for s in [self.merge_marker_str,
                                         self._datetime_str,
                                         self._line_str] if s])
        else:
            return ' '.join([s for s in [self._datetime_str,
                                         self._line_str] if s])
645607
def pretty_string(s, embedded, current_line, uni_lit=False,
                  min_trip_str=20, max_line=100):
    

    default = repr(s)

    # Punt on abnormal strings
    if (isinstance(s, special_unicode) or not isinstance(s, basestring)):
        return default
    if uni_lit and isinstance(s, bytes):
        return 'b' + default

    len_s = len(default)

    if current_line.strip():
        len_current = len(current_line)
        second_line_start = s.find('\n') + 1
        if embedded > 1 and not second_line_start:
            return default

        if len_s < min_trip_str:
            return default

        line_indent = len_current - len(current_line.lstrip())

        # Could be on a line by itself...
        if embedded and not second_line_start:
            return default

        total_len = len_current + len_s
        if total_len < max_line and not _properly_indented(s, line_indent):
            return default

    fancy = string_triplequote_repr(s)

    # Sometimes this doesn't work.  One reason is that
    # the AST has no understanding of whether \r\n was
    # entered that way in the string or was a cr/lf in the
    # file.  So we punt just so we can round-trip properly.

    try:
        if eval(fancy) == s and '\r' not in fancy:
            return fancy
    except:
        pass
    return default
1038222
def pretty_str(self, indent=0):
        
        if self.parenthesis:
            return '{}({})'.format(' ' * indent, pretty_str(self.value))
        return pretty_str(self.value, indent=indent)
1179836
def text_with_newlines(text, line_length=78, newline='\n'):
    '''
    '''
    if line_length > 0:
        if len(text) <= line_length:
            return text
        else:
            return newline.join([text[idx:idx+line_length]
                                 for idx
                                 in range(0, len(text), line_length)])
    else:
        return text
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
765095
def prettyln(text, fill='-', align='^', prefix='[ ', suffix=' ]', length=69):
    """"""
    text = '{prefix}{0}{suffix}'.format(text, prefix=prefix, suffix=suffix)
    print(
        "{0:{fill}{align}{length}}".format(
            text, fill=fill, align=align, length=length
        )
    )
1300989
def pad(self, string):
        
        size = len(string)
        target = size * (4.75 - size ** 0.27)
        pad_len = int(target) - size
        return string + self.LOREM[:pad_len] + "#"