blob: 48c73b9828d9b9c2f4b010ba8e3660f3aa3644d6 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.document.select.simple;
import com.yahoo.document.select.rule.IdNode;
/**
* @author baldersheim
*/
public class IdSpecParser extends Parser {
private IdNode id;
public IdNode getId() { return id; }
boolean isUserSpec() { return "user".equals(id.getField()); }
public boolean parse(CharSequence s) {
boolean retval = false;
int pos = eatWhite(s);
if (pos+1 < s.length()) {
if (icmp(s.charAt(pos), 'i') && icmp(s.charAt(pos+1),'d')) {
pos += 2;
if (pos < s.length()) {
switch (s.charAt(pos)) {
case '.':
{
int startPos = ++pos;
for (;pos < s.length() && (Character.toLowerCase(s.charAt(pos)) >= 'a') && (Character.toLowerCase(s.charAt(pos)) <= 'z'); pos++);
int len = pos - startPos;
if (((len == 4) && "user".equalsIgnoreCase(s.subSequence(startPos, startPos + 4).toString())) ||
((len == 5) && "group".equalsIgnoreCase(s.subSequence(startPos, startPos + 5).toString())) ||
((len == 6) && "scheme".equalsIgnoreCase(s.subSequence(startPos, startPos + 6).toString())) ||
((len == 8) && "specific".equalsIgnoreCase(s.subSequence(startPos, startPos + 8).toString())) ||
((len == 9) && "namespace".equalsIgnoreCase(s.subSequence(startPos, startPos + 9).toString())))
{
retval = true;
id = new IdNode().setField(s.subSequence(startPos, startPos + len).toString());
} else {
pos = startPos;
}
}
break;
case '!':
case '<':
case '>':
case '=':
case '\t':
case '\n':
case '\r':
case ' ':
{
retval = true;
id = new IdNode();
}
break;
default:
break;
}
}
}
}
setRemaining(s.subSequence(pos, s.length()));
return retval;
}
}
|