private static String truncateSequences(String text, int maxConsecutiveLength, int firstTruncationPos) {
        char [] truncated = text.toCharArray();
        char prev = truncated[firstTruncationPos];
        int sequenceCount = maxConsecutiveLength + 1;
        int wp=firstTruncationPos;
        for (int rp=wp+1; rp < truncated.length; rp++) {
            char curr = truncated[rp];
            if (prev == curr) {
                sequenceCount++;
                if (sequenceCount <= maxConsecutiveLength) {
                    truncated[wp++] = curr;
                }
            } else {
                truncated[wp++] = curr;
                sequenceCount = 1;
                prev = curr;
            }
        }
        return String.copyValueOf(truncated, 0, wp);
    }
This will truncate sequences in a string of the same character that exceed the maximum
allowed length.

@return The same string or a new one if truncation is done.
vespajlib/src/main/java/com/yahoo/text/StringUtilities.java