da8fa87b55e687a2ad3afc32a6d7a5a8e08c3a3a
[phpeclipse.git] / net.sourceforge.phpeclipse.ui / src / net / sourceforge / phpeclipse / xml / ui / internal / text / XMLTagRule.java
1 /*
2  * Copyright (c) 2002-2004 Widespace, OU and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Common Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/cpl-v10.html
7  *
8  * Contributors:
9  *     Igor Malinin - initial contribution
10  *
11  * $Id: XMLTagRule.java,v 1.2 2006-10-21 23:14:13 pombredanne Exp $
12  */
13
14 package net.sourceforge.phpeclipse.xml.ui.internal.text;
15
16 import org.eclipse.jface.text.rules.ICharacterScanner;
17 import org.eclipse.jface.text.rules.IRule;
18 import org.eclipse.jface.text.rules.IToken;
19 import org.eclipse.jface.text.rules.Token;
20
21 /**
22  * Rule detecting XML tag brackets and name.
23  * 
24  * @author Igor Malinin
25  */
26 public class XMLTagRule implements IRule {
27
28         private IToken token;
29
30         public XMLTagRule(IToken token) {
31                 this.token = token;
32         }
33
34         public IToken evaluate(ICharacterScanner scanner) {
35                 int ch = scanner.read();
36                 if (ch == '>') {
37                         return token;
38                 }
39                 if (ch == '/') {
40                         ch = scanner.read();
41                         if (ch == '>') {
42                                 return token;
43                         }
44
45                         scanner.unread();
46                         scanner.unread();
47                         return Token.UNDEFINED;
48                 }
49                 if (ch == '<') {
50                         ch = scanner.read();
51                         if (ch == '/') {
52                                 ch = scanner.read();
53                         }
54                         loop: while (true) {
55                                 switch (ch) {
56                                 case ICharacterScanner.EOF:
57                                 case 0x09:
58                                 case 0x0A:
59                                 case 0x0D:
60                                 case 0x20:
61                                         break loop;
62                                 }
63
64                                 ch = scanner.read();
65                         }
66
67                         scanner.unread();
68                         return token;
69                 }
70                 scanner.unread();
71                 return Token.UNDEFINED;
72         }
73 }