KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ant > internal > ui > editor > text > DocTypeRule


1 /*******************************************************************************
2  * Copyright (c) 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11
12 package org.eclipse.ant.internal.ui.editor.text;
13
14 import org.eclipse.jface.text.rules.ICharacterScanner;
15 import org.eclipse.jface.text.rules.IToken;
16 import org.eclipse.jface.text.rules.MultiLineRule;
17
18 public class DocTypeRule extends MultiLineRule {
19
20     private int fEmbeddedStart= 0;
21
22     public DocTypeRule(IToken token) {
23         super("<!DOCTYPE", ">", token); //$NON-NLS-1$ //$NON-NLS-2$
24
}
25
26     /*
27      * (non-Javadoc)
28      *
29      * @see org.eclipse.jface.text.rules.PatternRule#endSequenceDetected(org.eclipse.jface.text.rules.ICharacterScanner)
30      */

31     protected boolean endSequenceDetected(ICharacterScanner scanner) {
32         int c;
33         while ((c = scanner.read()) != ICharacterScanner.EOF) {
34             if (c == fEscapeCharacter) {
35                 // Skip the escaped character.
36
scanner.read();
37             } else if (c == '<') {
38                 fEmbeddedStart++;
39             } else if (c == '>') {
40                 if (fEmbeddedStart == 0) {
41                     return true;
42                 }
43                 fEmbeddedStart--;
44             }
45         }
46         
47         scanner.unread();
48         return false;
49     }
50 }
Popular Tags