protected boolean endSequenceDetected(ICharacterScanner scanner) {

    char[][] originalDelimiters = scanner.getLegalLineDelimiters();
    int count = originalDelimiters.length;
    if (fLineDelimiters == null || originalDelimiters.length != count) {
      fSortedLineDelimiters = new char[count][];
    } else {
      while (count > 0 && fLineDelimiters[count - 1] == originalDelimiters[count - 1]) count--;
    }
    if (count != 0) {
      fLineDelimiters = originalDelimiters;
      System.arraycopy(fLineDelimiters, 0, fSortedLineDelimiters, 0, fLineDelimiters.length);
      Arrays.sort(fSortedLineDelimiters, fLineDelimiterComparator);
    }

    int readCount = 1;
    char c;
    char test;
    while ((c = (char) scanner.read()) != ICharacterScanner.EOF) {
      if (c == fEscapeCharacter) {
        // Skip escaped character(s)
        if (fEscapeContinuesLine) {
          c = (char) scanner.read();
          for (int i = 0; i < fSortedLineDelimiters.length; i++) {
            if (c == fSortedLineDelimiters[i][0]
                && sequenceDetected(scanner, fSortedLineDelimiters[i], true)) break;
          }
        } else scanner.read();

      } else if (fEndSequence.length > 0 && c == fEndSequence[0]) {
        // Check if the specified end sequence has been found.
        scanner.unread();
        scanner.unread();
        test = (char) scanner.read();
        scanner.read();
        if (sequenceDetected(scanner, fEndSequence, true)) {
          if (test != ' ') return true;
        }
      } else if (fBreaksOnEOL) {
        // Check for end of line since it can be used to terminate the pattern.
        for (int i = 0; i < fSortedLineDelimiters.length; i++) {
          if (c == fSortedLineDelimiters[i][0]
              && sequenceDetected(scanner, fSortedLineDelimiters[i], true)) return false;
        }
      }
      readCount++;
    }

    if (fBreaksOnEOF) return true;

    for (; readCount > 0; readCount--) scanner.unread();

    return false;
  }
 @SuppressWarnings("unused")
 private void scanToEndOfLine(ICharacterScanner scanner) {
   int c;
   char[][] delimiters = scanner.getLegalLineDelimiters();
   while ((c = scanner.read()) != ICharacterScanner.EOF) {
     // Check for end of line since it can be used to terminate the pattern.
     for (int i = 0; i < delimiters.length; i++) {
       if (c == delimiters[i][0] && sequenceDetected(scanner, delimiters[i])) {
         return;
       }
     }
   }
 }
Пример #3
0
  protected boolean endSequenceDetected(ICharacterScanner scanner) {

    int c;
    boolean doubleQuoted = false;
    boolean singleQuoted = false;

    char[][] delimiters = scanner.getLegalLineDelimiters();
    boolean previousWasEscapeCharacter = false;
    while ((c = scanner.read()) != ICharacterScanner.EOF) {
      if (c == fEscapeCharacter) {
        // Skip the escaped character.
        scanner.read();
      } else if (c == '"') {
        if (singleQuoted == false) {
          doubleQuoted = !doubleQuoted;
        }
      } else if (c == '\'') {
        if (doubleQuoted == false) {
          singleQuoted = !singleQuoted;
        }
      } else if (fEndSequence.length > 0 && c == fEndSequence[0]) {
        // Check if the specified end sequence has been found.
        if (doubleQuoted == false
            && singleQuoted == false
            && sequenceDetected(scanner, fEndSequence, true)) return true;
      } else if (fBreaksOnEOL) {
        // Check for end of line since it can be used to terminate the pattern.
        for (int i = 0; i < delimiters.length; i++) {
          if (c == delimiters[i][0] && sequenceDetected(scanner, delimiters[i], true)) {
            if (!fEscapeContinuesLine || !previousWasEscapeCharacter) return true;
          }
        }
      }
      previousWasEscapeCharacter = (c == fEscapeCharacter);
    }
    if (fBreaksOnEOF) return true;
    scanner.unread();
    return false;
  }
Пример #4
0
 /* Copied from my superclass and modified to support case sensitivity. */
 protected boolean endSequenceDetected(ICharacterScanner scanner) {
   if (!ignoreCase) return super.endSequenceDetected(scanner);
   int c;
   char[][] delimiters = scanner.getLegalLineDelimiters();
   while ((c = scanner.read()) != ICharacterScanner.EOF) {
     if (c == fEscapeCharacter) {
       // Skip the escaped character.
       scanner.read();
     } else if (fEndSequence.length > 0
         && (c == fEndSequence[0] || Character.toLowerCase((char) c) == fEndSequence[0])) {
       // Check if the specified end sequence has been found.
       if (sequenceDetected(scanner, fEndSequence, true)) return true;
     } else if (fBreaksOnEOL) {
       // Check for end of line since it can be used to terminate the pattern.
       for (int i = 0; i < delimiters.length; i++) {
         if (c == delimiters[i][0] && sequenceDetected(scanner, delimiters[i], false)) return true;
       }
     }
   }
   scanner.unread();
   return true;
 }