@Nullable
    static byte[] unescapeFilterValue(byte[] filter, int start, int end) {
        boolean escape = false;
        boolean escapeStart = false;
        boolean hasEscapeChar = false;
        int number;
        byte filterChar;

        int length = end - start;
        byte[] resultBytes = null;
        int resultWriterIndex = 0;
        for (int i = start; i < end; i++) {
            filterChar = filter[i];
            if (escape) {
                if ((number = Character.digit(filterChar, 16)) < 0) {
                    throw new LdapException(ResultCode.FILTER_ERROR, "Invalid escape filter");
                }
                if (escapeStart) {
                    resultBytes[resultWriterIndex] = (byte) (number << 4);
                    escapeStart = false;
                } else {
                    resultBytes[resultWriterIndex++] |= (byte) number;
                    escape = false;
                }
            } else if (filterChar == '\\') {
                escapeStart = escape = true;
                if (!hasEscapeChar) {
                    resultBytes = new byte[length];
                    int lengthToCopy = i - start;
                    resultWriterIndex = lengthToCopy;
                    System.arraycopy(filter, start, resultBytes, 0, lengthToCopy);
                    hasEscapeChar = true;
                }
            } else {
                if (hasEscapeChar) {
                    resultBytes[resultWriterIndex++] = filterChar;
                }
                escape = false;
            }
        }
        if (hasEscapeChar) {
            byte[] result = new byte[resultWriterIndex];
            System.arraycopy(resultBytes, 0, result, 0, resultWriterIndex);
            return result;
        }
        return null;
    }
@author James Chen
@implSpec <a href="https://tools.ietf.org/html/rfc4515"> RFC 4515: String Representation of
          Search Filters</a>
turms-gateway/src/main/java/im/turms/gateway/infra/ldap/element/operation/search/Filter.java