static String toLowerSnakeCase(final String value)
    {
        if (value.isEmpty())
        {
            return value;
        }

        final String cleaned = cleanUpperAcronyms(value);
        final String s = toLowerFirstChar(cleaned);
        final int length = s.length();

        final StringBuilder out = new StringBuilder(length + 4);
        char lastChar = '\0';

        for (int i = 0, j = 0; j < length; j++)
        {
            final boolean wasUpper = isUpperAlpha(lastChar);
            final boolean wasNumeric = isNumeric(lastChar);
            final boolean wasUnderscore = lastChar == '_';
            final char c = s.charAt(j);

            if (c == '_')
            {
                out.append(c);
                i = j + 1;
            }
            else if (isUpperAlpha(c))
            {
                if (wasNumeric || (!wasUpper && j - i > 1 && !wasUnderscore))
                {
                    out.append('_');
                    out.append(toLowerSnakeCase(s.substring(j)));
                    return out.toString();
                }
                out.append(Character.toLowerCase(c));
            }
            else if (isNumeric(c))
            {
                if (!wasNumeric && j - i > 1 && !wasUnderscore)
                {
                    out.append('_');
                    out.append(toLowerSnakeCase(s.substring(j)));
                    return out.toString();
                }
                out.append(c);
            }
            else
            {
                if ((wasUpper || wasNumeric) && j - i > 1 && !wasUnderscore)
                {
                    out.append('_');
                    out.append(toLowerSnakeCase(s.substring(j)));
                    return out.toString();
                }
                out.append(c);
            }

            lastChar = c;
        }

        return out.toString();
    }
Converts to 'snake_case' but will also handle when there are multiple
upper case characters in a row 'UPPERCase' => 'upper_case'.

@param value to be formatted
@return the string formatted to 'lower_snake_case'
sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/rust/RustUtil.java