Returns s if it's at most maxWidth chars, otherwise chops right side to fit.
553227
public static String trim(String s, int maxWidth) {
    if (s.length() <= maxWidth) {
      return (s);
    }
    return (s.substring(0, maxWidth));
  }
453894
def _string_width(string, *, _IS_ASCII=_IS_ASCII):
    """"""
    match = _IS_ASCII.match(string)
    if match:
        return match.endpos

    UNICODE_WIDE_CHAR_TYPE = 'WFA'
    width = 0
    func = unicodedata.east_asian_width
    for char in string:
        width += 2 if func(char) in UNICODE_WIDE_CHAR_TYPE else 1
    return width
179479
def cutoff(s, length=120):
    """"""
    if length < 5:
        raise ValueError('length must be >= 5')
    if len(s) <= length:
        return s
    else:
        i = (length - 2) / 2
        j = (length - 3) / 2
        return s[:i] + '...' + s[-j:]
138681
private int getCharWidth(String text, Align align)
    {
        final int width;
        if (align == Align.RIGHT)
        {
            width = getTextWidth(text);
        }
        else if (align == Align.CENTER)
        {
            width = getTextWidth(text) / 2;
        }
        else
        {
            width = 0;
        }
        return width;
    }
313971
def MAXSIDE(a, b):
        """"""
        return cmp(max(b[0], b[1]), max(a[0], a[1])) or cmp(min(b[0], b[1]), min(a[0], a[1])) or cmp(b[1], a[1]) or cmp(b[0], a[0])
309802
def tmpl_shorten(text, max_size=32):
        
        max_size = int(max_size)
        if len(text) <= max_size:
            return text
        text = textwrap.wrap(text, max_size)[0]
        import re
        text = re.sub(r'\W+$', '', text)
        return text.strip()
861324
function getPadding(str, width) {
  const spaceLen = (typeof width === 'undefined' ? 30 : width) - str.length;
  let padding = '';

  padding += '  ';
  for (let i = 2; i < spaceLen; i += 1) {
    padding += '-';
  }
  padding += '  ';
  return padding;
}
854225
function charWidth(display) {
    if (display.cachedCharWidth != null) return display.cachedCharWidth;
    var anchor = elt("span", "xxxxxxxxxx");
    var pre = elt("pre", [anchor]);
    removeChildrenAndAdd(display.measure, pre);
    var rect = anchor.getBoundingClientRect(), width = (rect.right - rect.left) / 10;
    if (width > 2) display.cachedCharWidth = width;
    return width || 10;
  }
1103129
def truncated_match(str)
      len = str.length
      available_width = @window_width - MARKER_LENGTH
      return str if len <= available_width
      left = (available_width / 2) - 1
      right = (available_width / 2) - 2 + (available_width % 2)
      str[0, left] + '...' + str[-right, right]
    end
183536
def trunc_str(s: str) -> str:
    """"""
    if len(s) > max_str_size:
        i = max(0, (max_str_size - 3) // 2)
        j = max(0, max_str_size - 3 - i)
        s = s[:i] + "..." + s[-j:]
    return s
1286371
def _get_width(maxwidth):
    """"""
    width = maxwidth / 3
    if maxwidth <= 60:
        width = maxwidth
    elif 60 < maxwidth <= 120:
        width = maxwidth / 2
    return width
464301
public float getWidthCorrected(float charSpacing, float wordSpacing)
    {
        if (image != null) {
            return image.getScaledWidth() + charSpacing;
        }
        int numberOfSpaces = 0;
        int idx = -1;
        while ((idx = value.indexOf(' ', idx + 1)) >= 0)
            ++numberOfSpaces;
        return width() + (value.length() * charSpacing + numberOfSpaces * wordSpacing);
    }
366628
protected static String justifyRight(CharSequence csq, char pad, int width) {
        try {
            StringBuilder sb = new StringBuilder(width);
            justifyRight(sb, csq, pad, width);
            return sb.toString();
        } catch (IOException e) {
            throw new AssertionError("StringBuilder failed", e);
        }
    }
883180
public static String toFullWidth(String input) {
		char[] c = input.toCharArray();
		for (int i = 0; i< c.length; i++) {
			c[i]= toFullWidth(c[i]);
		}
		return new String(c);
	}
1021567
private boolean checkSideSize( Polygon2D_F64 p ) {
		double max=0,min=Double.MAX_VALUE;

		for (int i = 0; i < p.size(); i++) {
			double l = p.getSideLength(i);
			max = Math.max(max,l);
			min = Math.min(min,l);
		}

		// See if a side is too small to decode
		if( min < 10 )
			return false;

		// see if it's under extreme perspective distortion and unlikely to be readable
		return !(min / max < thresholdSideRatio);
	}
848912
private final int strcmpMax(String s, int unfoldOffset, int max) {
        int i1, length, c1, c2;

        length=s.length();
        max-=length; /* we require length<=max, so no need to decrement max in the loop */
        i1=0;
        do {
            c1=s.charAt(i1++);
            c2=unfold[unfoldOffset++];
            if(c2==0) {
                return 1; /* reached the end of t but not of s */
            }
            c1-=c2;
            if(c1!=0) {
                return c1; /* return difference result */
            }
        } while(--length>0);
        /* ends with length==0 */

        if(max==0 || unfold[unfoldOffset]==0) {
            return 0; /* equal to length of both strings */
        } else {
            return -max; /* return lengh difference */
        }
    }
1150250
public static int rightTrimSize(String s) {

        int i = s.length();

        while (i > 0) {
            i--;

            if (s.charAt(i) != ' ') {
                return i + 1;
            }
        }

        return 0;
    }