private static Filter assertionValue2SubstringFilter(final String filterString,final String attrType,final int equalPos,final int endPos){
  final byte[] valueBytes=getBytes(filterString.substring(equalPos,endPos));
  boolean hasEscape=false;
  final LinkedList<Integer> asteriskPositions=new LinkedList<>();
  for (int i=0; i < valueBytes.length; i++) {
    if (valueBytes[i] == ASTERISK) {
      asteriskPositions.add(i);
    }
 else     if (valueBytes[i] == BACKSLASH) {
      hasEscape=true;
    }
  }
  if (asteriskPositions.isEmpty()) {
    final LocalizableMessage message=ERR_LDAP_FILTER_SUBSTRING_NO_ASTERISKS.get(filterString,equalPos + 1,endPos);
    throw new LocalizedIllegalArgumentException(message);
  }
  ByteString subInitial;
  int firstPos=asteriskPositions.removeFirst();
  if (firstPos == 0) {
    subInitial=null;
  }
 else   if (hasEscape) {
    final ByteStringBuilder buffer=new ByteStringBuilder(firstPos);
    escapeHexChars(buffer,attrType,valueBytes,0,firstPos,equalPos);
    subInitial=buffer.toByteString();
  }
 else {
    subInitial=ByteString.wrap(valueBytes,0,firstPos);
  }
  final ArrayList<ByteString> subAny=new ArrayList<>();
  for (  final int asteriskPos : asteriskPositions) {
    final int length=asteriskPos - firstPos - 1;
    if (hasEscape) {
      final ByteStringBuilder buffer=new ByteStringBuilder(length);
      escapeHexChars(buffer,attrType,valueBytes,firstPos + 1,asteriskPos,equalPos);
      subAny.add(buffer.toByteString());
      buffer.clear();
    }
 else {
      subAny.add(ByteString.wrap(valueBytes,firstPos + 1,length));
    }
    firstPos=asteriskPos;
  }
  ByteString subFinal;
  if (firstPos == (valueBytes.length - 1)) {
    subFinal=null;
  }
 else {
    final int length=valueBytes.length - firstPos - 1;
    if (hasEscape) {
      final ByteStringBuilder buffer=new ByteStringBuilder(length);
      escapeHexChars(buffer,attrType,valueBytes,firstPos + 1,valueBytes.length,equalPos);
      subFinal=buffer.toByteString();
    }
 else {
      subFinal=ByteString.wrap(valueBytes,firstPos + 1,length);
    }
  }
  return new Filter(new SubstringsImpl(attrType,subInitial,subAny,subFinal));
}

private static Filter assertionValue2SubstringFilter ( final String filterString , final String attrType , final int equalPos , final int endPos ) { final byte [ ] valueBytes = getBytes ( filterString . substring ( equalPos , endPos ) ) ; boolean hasEscape = false ; final LinkedList < Integer > asteriskPositions = new LinkedList < > ( ) ; for ( int i = 0 ; i < valueBytes . length ; i ++ ) { if ( valueBytes [ i ] == ASTERISK ) { asteriskPositions . add ( i ) ; } else if ( valueBytes [ i ] == BACKSLASH ) { hasEscape = true ; } } if ( asteriskPositions . isEmpty ( ) ) { final LocalizableMessage message = ERR_LDAP_FILTER_SUBSTRING_NO_ASTERISKS . get ( filterString , equalPos + 1 , endPos ) ; throw new LocalizedIllegalArgumentException ( message ) ; } ByteString subInitial ; int firstPos = asteriskPositions . removeFirst ( ) ; if ( firstPos == 0 ) { subInitial = null ; } else if ( hasEscape ) { final ByteStringBuilder buffer = new ByteStringBuilder ( firstPos ) ; escapeHexChars ( buffer , attrType , valueBytes , 0 , firstPos , equalPos ) ; subInitial = buffer . toByteString ( ) ; } else { subInitial = ByteString . wrap ( valueBytes , 0 , firstPos ) ; } final ArrayList < ByteString > subAny = new ArrayList < > ( ) ; for ( final int asteriskPos : asteriskPositions ) { final int length = asteriskPos - firstPos - 1 ; if ( hasEscape ) { final ByteStringBuilder buffer = new ByteStringBuilder ( length ) ; escapeHexChars ( buffer , attrType , valueBytes , firstPos + 1 , asteriskPos , equalPos ) ; subAny . add ( buffer . toByteString ( ) ) ; buffer . clear ( ) ; } else { subAny . add ( ByteString . wrap ( valueBytes , firstPos + 1 , length ) ) ; } firstPos = asteriskPos ; } ByteString subFinal ; if ( firstPos == ( valueBytes . length - 1 ) ) { subFinal = null ; } else { final int length = valueBytes . length - firstPos - 1 ; if ( hasEscape ) { final ByteStringBuilder buffer = new ByteStringBuilder ( length ) ; escapeHexChars ( buffer , attrType , valueBytes , firstPos + 1 , valueBytes . length , equalPos ) ; subFinal = buffer . toByteString ( ) ; } else { subFinal = ByteString . wrap ( valueBytes , firstPos + 1 , length ) ; } } return new Filter ( new SubstringsImpl ( attrType , subInitial , subAny , subFinal ) ) ; }
converts an assertion value to a substring filter .
