shortens string if longer than maxlen, appending ellipsis
432687
def shorten(string, maxlen):
    """"""
    if 1 < maxlen < len(string):
        string = string[:maxlen - 1] + u'…'
    return string[:maxlen]
277909
function colorCodeToShorterNames(string) {
  Object.keys(shorterNames).forEach(function(key, i) {
    if (shorterNames[key].test(string)) {
      string = string.replace(shorterNames[key], key);
    }
  });

  return string;
}
356418
def truncate_str(str_, maxlen=110, truncmsg=' ~~~TRUNCATED~~~ '):
    
    if NO_TRUNCATE:
        return str_
    if maxlen is None or maxlen == -1 or len(str_) < maxlen:
        return str_
    else:
        maxlen_ = maxlen - len(truncmsg)
        lowerb  = int(maxlen_ * .8)
        upperb  = maxlen_ - lowerb
        tup = (str_[:lowerb], truncmsg, str_[-upperb:])
        return ''.join(tup)
396818
function splitIntoLines(str, max) {
  function _splitIntoLines(str, max) {
    return str.trim().split(' ').reduce(function(lines, word) {
      var line = lines[lines.length - 1]
      if (line && wcwidth(line.join(' ')) + wcwidth(word) < max) {
        lines[lines.length - 1].push(word) // add to line
      }
      else lines.push([word]) // new line
      return lines
    }, []).map(function(l) {
      return l.join(' ')
    })
  }
  return str.split('\n').map(function(str) {
    return _splitIntoLines(str, max)
  }).reduce(function(lines, line) {
    return lines.concat(line)
  }, [])
}
1234663
static function maxLengthByWords($str, $len = 50)
    {
        $str = self::removeHTMLSpecialChars($str);
        $cut = "\x1\x2\x3";
        $str = strip_tags($str);
        list($str) = explode($cut, wordwrap($str, $len, $cut));

        return $str;
    }
1000346
def shorten(s, max_len=16):
    
    short = s
    words = [abbreviate(word) for word in get_words(s)]
    for i in range(len(words), 0, -1):
        short = ' '.join(words[:i])
        if len(short) <= max_len:
            break
    return short[:max_len]
1095279
function pad(str) {
  if (str.length < max) {
    return str + ' '.repeat(max - str.length);
  }
  return str;
}
378079
def truncate(text, length=50, ellipsis='...'):
    
    text = nativestring(text)
    return text[:length] + (text[length:] and ellipsis)
408005
def length_range(string, minimum, maximum):
    
    int_range(len(string), minimum, maximum)
    return string
368591
def abbreviate_str(string, max_len=80, indicator="..."):
  
  if not string or not max_len or len(string) <= max_len:
    return string
  elif max_len <= len(indicator):
    return string[0:max_len]
  else:
    return string[0:max_len - len(indicator)] + indicator
219228
function _stringPad(that, maxLength, fillString, left) {
	  var S = String(_defined(that));
	  var stringLength = S.length;
	  var fillStr = fillString === undefined ? ' ' : String(fillString);
	  var intMaxLength = _toLength(maxLength);
	  if (intMaxLength <= stringLength || fillStr == '') return S;
	  var fillLen = intMaxLength - stringLength;
	  var stringFiller = _stringRepeat.call(fillStr, Math.ceil(fillLen / fillStr.length));
	  if (stringFiller.length > fillLen) stringFiller = stringFiller.slice(0, fillLen);
	  return left ? stringFiller + S : S + stringFiller;
	}
371534
public static String cutEnd(String data, int maxLength) {
        if (data.length() > maxLength) {
            return data.substring(0, maxLength) + "...";
        } else {
            return data;
        }
    }
216536
public static String truncate(String string, int maxBytesLength,
            String appendString) {
        return string.getBytes().length > maxBytesLength ? truncate(string,
                maxBytesLength - appendString.getBytes().length) + appendString
                : string;
    }
657637
function(string, maxLength) {
            if (!string) return string;
            if (maxLength < 1) return string;
            if (string.length <= maxLength) return string;
            if (maxLength == 1) return string.substring(0,1) + '...';

            var midpoint = Math.ceil(string.length / 2);
            var toremove = string.length - maxLength;
            var lstrip = Math.ceil(toremove/2);
            var rstrip = toremove - lstrip;
            return string.substring(0, midpoint-lstrip) + '...' + string.substring(midpoint+rstrip);
        }
1336513
def truncate_between(str, after = 30)
      str = '' if str.nil?
      str.length > after ? "#{str[0..(after / 2) - 2]}...#{str[(str.length - ((after / 2) - 2))..str.length]}" : str
    end
104591
def truncate(v: str, *, max_len: int = 80) -> str:
    
    if isinstance(v, str) and len(v) > (max_len - 2):
        # -3 so quote + string + … + quote has correct length
        return repr(v[: (max_len - 3)] + '…')
    v = repr(v)
    if len(v) > max_len:
        v = v[: max_len - 1] + '…'
    return v
1145404
def _SkipLengthDelimited(buffer, pos, end):
  """"""

  (size, pos) = _DecodeVarint(buffer, pos)
  pos += size
  if pos > end:
    raise _DecodeError('Truncated message.')
  return pos