View Javadoc

1   /*
2    * $Id: XMLNameDetector.java,v 1.5 2005/06/01 17:38:33 jlerner Exp $
3    *
4    * Copyright (c) 1999-2004, BBN Technologies, LLC.
5    * All rights reserved.
6    * http://www.daml.org/legal/opensource/bbn_license.html
7    */
8    
9   package com.bbn.swede.editor.rules;
10  
11  import org.eclipse.jface.text.rules.IWordDetector;
12  
13  /***
14   * <p>A word detector for finding XML names.
15   * For purposes of this rule, an XML name must meet the following requirements:
16   * </p>
17   * <ol>
18   *   <li>Begins with a letter or '_'</li>
19   *   <li>Contains at most one ':'</li>
20   *   <li>Remaining characters are letters, '_', '-', or '.'</li>
21   * </ol>
22   * @author jlerner
23   */
24  class XMLNameDetector implements IWordDetector
25  {
26     private boolean _bColonFound;
27  
28     /* (non-Javadoc)
29      * @see org.eclipse.jface.text.rules.IWordDetector#isWordStart(char)
30      */
31     public boolean isWordStart(char c)
32     {
33        _bColonFound = false;
34        if (!Character.isLetter(c) && c != '_')
35        {
36           return false;
37        }
38        return true;
39     }
40  
41     /* (non-Javadoc)
42      * @see org.eclipse.jface.text.rules.IWordDetector#isWordPart(char)
43      */
44     public boolean isWordPart(char c)
45     {
46        if (c == ':')
47        {
48           if (_bColonFound)
49           {
50              return false;
51           }
52           _bColonFound = true;
53           return true;
54        }
55        if (Character.isLetter(c) || Character.isDigit(c)
56            || c == '.' || c == '_' || c == '-')
57        {
58           return true;
59        }
60        return false;
61     }
62     
63  }