boolean matches(String selector,int sCurrent,int sLast,int thisCurrent,int thisLast){
  sCurrent=Math.max(sCurrent,0);
  thisCurrent=Math.max(thisCurrent,0);
  int thisDotIndex=boundedIndexOf(name,'.',thisCurrent,thisLast);
  int thisPoundIndex=boundedIndexOf(name,'#',thisCurrent,thisLast);
  int sDotIndex=boundedIndexOf(selector,'.',sCurrent,sLast);
  int sPoundIndex=boundedIndexOf(selector,'#',sCurrent,sLast);
  if (sDotIndex != -1) {
    if (thisDotIndex == -1) {
      return false;
    }
    if (sCurrent == sDotIndex) {
      if ((thisLast - thisDotIndex) != (sLast - sDotIndex) || !selector.regionMatches(sCurrent,name,thisDotIndex,(thisLast - thisDotIndex))) {
        return false;
      }
    }
 else {
      if ((sLast - sCurrent) != (thisLast - thisCurrent) || !selector.regionMatches(sCurrent,name,thisCurrent,(thisLast - thisCurrent))) {
        return false;
      }
    }
    return true;
  }
  if (sPoundIndex != -1) {
    if (thisPoundIndex == -1) {
      return false;
    }
    if (sCurrent == sPoundIndex) {
      if ((thisLast - thisPoundIndex) != (sLast - sPoundIndex) || !selector.regionMatches(sCurrent,name,thisPoundIndex,(thisLast - thisPoundIndex))) {
        return false;
      }
    }
 else {
      if ((sLast - sCurrent) != (thisLast - thisCurrent) || !selector.regionMatches(sCurrent,name,thisCurrent,(thisLast - thisCurrent))) {
        return false;
      }
    }
    return true;
  }
  if (thisDotIndex != -1) {
    return (((thisDotIndex - thisCurrent) == (sLast - sCurrent)) && selector.regionMatches(sCurrent,name,thisCurrent,thisDotIndex - thisCurrent));
  }
  if (thisPoundIndex != -1) {
    return (((thisPoundIndex - thisCurrent) == (sLast - sCurrent)) && selector.regionMatches(sCurrent,name,thisCurrent,thisPoundIndex - thisCurrent));
  }
  return (((thisLast - thisCurrent) == (sLast - sCurrent)) && selector.regionMatches(sCurrent,name,thisCurrent,thisLast - thisCurrent));
}

boolean matches ( String selector , int sCurrent , int sLast , int thisCurrent , int thisLast ) { sCurrent = Math . max ( sCurrent , 0 ) ; thisCurrent = Math . max ( thisCurrent , 0 ) ; int thisDotIndex = boundedIndexOf ( name , '.' , thisCurrent , thisLast ) ; int thisPoundIndex = boundedIndexOf ( name , '#' , thisCurrent , thisLast ) ; int sDotIndex = boundedIndexOf ( selector , '.' , sCurrent , sLast ) ; int sPoundIndex = boundedIndexOf ( selector , '#' , sCurrent , sLast ) ; if ( sDotIndex != - 1 ) { if ( thisDotIndex == - 1 ) { return false ; } if ( sCurrent == sDotIndex ) { if ( ( thisLast - thisDotIndex ) != ( sLast - sDotIndex ) || ! selector . regionMatches ( sCurrent , name , thisDotIndex , ( thisLast - thisDotIndex ) ) ) { return false ; } } else { if ( ( sLast - sCurrent ) != ( thisLast - thisCurrent ) || ! selector . regionMatches ( sCurrent , name , thisCurrent , ( thisLast - thisCurrent ) ) ) { return false ; } } return true ; } if ( sPoundIndex != - 1 ) { if ( thisPoundIndex == - 1 ) { return false ; } if ( sCurrent == sPoundIndex ) { if ( ( thisLast - thisPoundIndex ) != ( sLast - sPoundIndex ) || ! selector . regionMatches ( sCurrent , name , thisPoundIndex , ( thisLast - thisPoundIndex ) ) ) { return false ; } } else { if ( ( sLast - sCurrent ) != ( thisLast - thisCurrent ) || ! selector . regionMatches ( sCurrent , name , thisCurrent , ( thisLast - thisCurrent ) ) ) { return false ; } } return true ; } if ( thisDotIndex != - 1 ) { return ( ( ( thisDotIndex - thisCurrent ) == ( sLast - sCurrent ) ) && selector . regionMatches ( sCurrent , name , thisCurrent , thisDotIndex - thisCurrent ) ) ; } if ( thisPoundIndex != - 1 ) { return ( ( ( thisPoundIndex - thisCurrent ) == ( sLast - sCurrent ) ) && selector . regionMatches ( sCurrent , name , thisCurrent , thisPoundIndex - thisCurrent ) ) ; } return ( ( ( thisLast - thisCurrent ) == ( sLast - sCurrent ) ) && selector . regionMatches ( sCurrent , name , thisCurrent , thisLast - thisCurrent ) ) ; }
returns true if the substring of the receiver , in the range thiscurrent , thislast matches the substring of selector in the ranme scurrent to slast based on css selector matching .
