1   
2   
3   
4   
5   
6   
7   
8   
9   
10  
11  
12  
13  
14  
15  
16  
17  
18  package org.vectomatic.svg.edit.client.engine;
19  
20  
21  
22  
23  
24  
25  
26  
27  public class IdRefTokenizer {
28  	protected static final String START = "url(#";
29  	protected static final String END = ")";
30  	static class IdRefToken {
31  		public static final int IDREF = 1;
32  		public static final int DATA = 2;
33  		int kind;
34  		String value;
35  		public int getKind() {
36  			return kind;
37  		}
38  		public String getValue() {
39  			return value;
40  		}
41  	}
42  	protected IdRefToken token = new IdRefToken();
43  	protected String str;
44  	protected int index1;
45  	protected int index2;
46  
47  	public void tokenize(String str) {
48  		this.str = str;
49  		index1 = 0;
50  		index2 = 0;
51  		token.kind = IdRefToken.IDREF;
52  		token.value = null;
53  	}
54  	public IdRefToken nextToken() {
55  		if (index1 != str.length()) {
56  			if (token.kind == IdRefToken.IDREF) {
57  				token.kind = IdRefToken.DATA;
58  				index2 = str.indexOf(START, index1);
59  				if (index2 != -1) {
60  					token.value = str.substring(index1, index2 + START.length());
61  					index1 = index2 + START.length();
62  				} else {
63  					token.value = str.substring(index1);
64  					index1 = str.length();
65  				}
66  			} else {
67  				index2 = str.indexOf(END, index1);
68  				if (index2 != -1) {
69  					token.value = str.substring(index1, index2);
70  					index1 = index2;
71  					token.kind = IdRefToken.IDREF;
72  				} else {
73  					token.value = str.substring(index1);
74  					index1 = str.length();
75  				}
76  			}
77  			return token;
78  		}
79  		return null;
80  	}
81  }