code: private static boolean
      isASCIIOkBiDi(CharSequence s, int length) {
          int labelStart=0;
          for(int i=0; i<length; ++i) {
              char c=s.charAt(i);
              if(c=='.') {  // dot
                  if(i>labelStart) {
                      c=s.charAt(i-1);
                      if(!('a'<=c && c<='z') && !('0'<=c && c<='9')) {
                          // Last character in the label is not an L or EN.
                          return false;
                      }
                  }
                  labelStart=i+1;
              } else if(i==labelStart) {
                  if(!('a'<=c && c<='z')) {
                      // First character in the label is not an L.
                      return false;
                  }
              } else {
                  if(c<=0x20 && (c>=0x1c || (9<=c && c<=0xd))) {
                      // Intermediate character in the label is a B, S or WS.
                      return false;
                  }
              }
          }
          return true;
      }
docs: s[length-1] must be the trailing dot.