private String asSize(int size, String s) {
        if (s.length() > size)
            return s.substring(0, size);
        else
            return s + " ".repeat(size - s.length());
    }
Returns the position of the end of a balanced chunk of at most the given size, or 0 if there is no such chunk
vespajlib/src/main/java/com/yahoo/text/ExpressionFormatter.java