📄 kxmlparser.java
字号:
}
private final void push(int i)
{
isWhitespace &= i <= 32;
if(txtPos == txtBuf.length)
{
char ac[] = new char[(txtPos * 4) / 3 + 4];
System.arraycopy(txtBuf, 0, ac, 0, txtPos);
txtBuf = ac;
}
txtBuf[txtPos++] = (char)i;
}
private final void parseStartTag(boolean flag)
throws IOException, XmlPullParserException
{
if(!flag)
read();
name = readName();
attributeCount = 0;
do
{
skip();
int i = peek(0);
if(flag)
{
if(i == 63)
{
read();
read('>');
return;
}
} else
{
if(i == 47)
{
degenerated = true;
read();
skip();
read('>');
break;
}
if(i == 62 && !flag)
{
read();
break;
}
}
if(i == -1)
{
error("Unexpected EOF");
return;
}
String s = readName();
if(s.length() == 0)
{
error("attr name expected");
break;
}
int k = attributeCount++ << 2;
attributes = ensureCapacity(attributes, k + 4);
attributes[k++] = "";
attributes[k++] = null;
attributes[k++] = s;
skip();
if(peek(0) != 61)
{
error("Attr.value missing f. " + s);
attributes[k] = "1";
} else
{
read('=');
skip();
int l = peek(0);
if(l != 39 && l != 34)
{
error("attr value delimiter missing!");
l = 32;
} else
{
read();
}
int i1 = txtPos;
pushText(l, true);
attributes[k] = get(i1);
txtPos = i1;
if(l != 32)
read();
}
} while(true);
int j = depth++ << 2;
elementStack = ensureCapacity(elementStack, j + 4);
elementStack[j + 3] = name;
if(depth >= nspCounts.length)
{
int ai[] = new int[depth + 4];
System.arraycopy(nspCounts, 0, ai, 0, nspCounts.length);
nspCounts = ai;
}
nspCounts[depth] = nspCounts[depth - 1];
if(processNsp)
adjustNsp();
else
namespace = "";
elementStack[j] = namespace;
elementStack[j + 1] = prefix;
elementStack[j + 2] = name;
}
private final void pushEntity()
throws IOException, XmlPullParserException
{
read();
int i = txtPos;
do
{
int j = read();
if(j == 59)
break;
if(j < 128 && (j < 48 || j > 57) && (j < 97 || j > 122) && (j < 65 || j > 90) && j != 95 && j != 45 && j != 35)
{
error("unterminated entity ref");
if(j != -1)
push(j);
return;
}
push(j);
} while(true);
String s = get(i);
txtPos = i;
if(token && type == 6)
name = s;
if(s.charAt(0) == '#')
{
int k = s.charAt(1) != 'x' ? Integer.parseInt(s.substring(1)) : Integer.parseInt(s.substring(2), 16);
push(k);
return;
}
String s1 = (String)entityMap.get(s);
unresolved = s1 == null;
if(unresolved)
{
if(!token)
error("unresolved: &" + s + ";");
} else
{
for(int l = 0; l < s1.length(); l++)
push(s1.charAt(l));
}
}
private final void pushText(int i, boolean flag)
throws IOException, XmlPullParserException
{
int j = peek(0);
int k = 0;
for(; j != -1 && j != i && (i != 32 || j > 32 && j != 62); j = peek(0))
{
if(j == 38)
{
if(!flag)
break;
pushEntity();
} else
if(j == 10 && type == 2)
{
read();
push(32);
} else
{
push(read());
}
if(j == 62 && k >= 2 && i != 93)
error("Illegal: ]]>");
if(j == 93)
k++;
else
k = 0;
}
}
private final void read(char c)
throws IOException, XmlPullParserException
{
int i = read();
if(i != c)
error("expected: '" + c + "' actual: '" + (char)i + "'");
}
private final int read()
throws IOException
{
int i;
if(peekCount == 0)
{
i = peek(0);
} else
{
i = peek[0];
peek[0] = peek[1];
}
peekCount--;
column++;
if(i == 10)
{
line++;
column = 1;
}
return i;
}
private final int peek(int i)
throws IOException
{
while(i >= peekCount)
{
int j;
if(srcBuf.length <= 1)
j = reader.read();
else
if(srcPos < srcCount)
{
j = srcBuf[srcPos++];
} else
{
srcCount = reader.read(srcBuf, 0, srcBuf.length);
if(srcCount <= 0)
j = -1;
else
j = srcBuf[0];
srcPos = 1;
}
if(j == 13)
{
wasCR = true;
peek[peekCount++] = 10;
} else
{
if(j == 10)
{
if(!wasCR)
peek[peekCount++] = 10;
} else
{
peek[peekCount++] = j;
}
wasCR = false;
}
}
return peek[i];
}
private final String readName()
throws IOException, XmlPullParserException
{
int i = txtPos;
int j = peek(0);
if((j < 97 || j > 122) && (j < 65 || j > 90) && j != 95 && j != 58 && j < 192 && !relaxed)
error("name expected");
do
{
push(read());
j = peek(0);
} while(j >= 97 && j <= 122 || j >= 65 && j <= 90 || j >= 48 && j <= 57 || j == 95 || j == 45 || j == 58 || j == 46 || j >= 183);
String s = get(i);
txtPos = i;
return s;
}
private final void skip()
throws IOException
{
do
{
int i = peek(0);
if(i <= 32 && i != -1)
read();
else
return;
} while(true);
}
public void setInput(Reader reader1)
throws XmlPullParserException
{
reader = reader1;
line = 1;
column = 0;
type = 0;
name = null;
namespace = null;
degenerated = false;
attributeCount = -1;
encoding = null;
version = null;
standalone = null;
if(reader1 == null)
{
return;
} else
{
srcPos = 0;
srcCount = 0;
peekCount = 0;
depth = 0;
entityMap = new Hashtable();
entityMap.put("amp", "&");
entityMap.put("apos", "'");
entityMap.put("gt", ">");
entityMap.put("lt", "<");
entityMap.put("quot", "\"");
return;
}
}
public void setInput(InputStream inputstream, String s)
throws XmlPullParserException
{
srcPos = 0;
srcCount = 0;
String s1 = s;
if(inputstream == null)
throw new IllegalArgumentException();
try
{
label0:
{
int i;
label1:
{
if(s1 != null)
break label0;
i = 0;
do
{
if(srcCount >= 4)
break;
int k = inputstream.read();
if(k == -1)
break;
i = i << 8 | k;
srcBuf[srcCount++] = (char)k;
} while(true);
if(srcCount != 4)
break label0;
switch(i)
{
default:
break;
case 65279:
s1 = "UTF-32BE";
srcCount = 0;
break label0;
case -131072:
s1 = "UTF-32LE";
srcCount = 0;
break label0;
case 60: // '<'
s1 = "UTF-32BE";
srcBuf[0] = '<';
srcCount = 1;
break label0;
case 1006632960:
s1 = "UTF-32LE";
srcBuf[0] = '<';
srcCount = 1;
break label0;
case 3932223:
s1 = "UTF-16BE";
srcBuf[0] = '<';
srcBuf[1] = '?';
srcCount = 2;
break label0;
case 1006649088:
s1 = "UTF-16LE";
srcBuf[0] = '<';
srcBuf[1] = '?';
srcCount = 2;
break label0;
case 1010792557:
int l;
do
{
l = inputstream.read();
if(l == -1)
break label1;
srcBuf[srcCount++] = (char)l;
} while(l != 62);
String s2 = new String(srcBuf, 0, srcCount);
int i1 = s2.indexOf("encoding");
if(i1 != -1)
{
for(; s2.charAt(i1) != '"' && s2.charAt(i1) != '\''; i1++);
char c = s2.charAt(i1++);
int j1 = s2.indexOf(c, i1);
s1 = s2.substring(i1, j1);
}
break;
}
}
if((i & 0xffff0000) == 0xfeff0000)
{
s1 = "UTF-16BE";
srcBuf[0] = (char)(srcBuf[2] << 8 | srcBuf[3]);
srcCount = 1;
} else
if((i & 0xffff0000) == 0xfffe0000)
{
s1 = "UTF-16LE";
srcBuf[0] = (char)(srcBuf[3] << 8 | srcBuf[2]);
srcCount = 1;
} else
if((i & 0xffffff00) == 0xefbbbf00)
{
s1 = "UTF-8";
srcBuf[0] = srcBuf[3];
srcCount = 1;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -