01: package com.jclark.xml.tok;
02:
03: /**
04: * An Encoding for ISO 8859-1.
05: *
06: * @version $Revision: 1.3 $ $Date: 1998/08/28 10:07:26 $
07: */
08: final class ISO8859_1Encoding extends Encoding {
09:
10: private static final byte[] latin1Table;
11:
12: static {
13: latin1Table = charTypeTable[0];
14: }
15:
16: ISO8859_1Encoding() {
17: super (1);
18: }
19:
20: int byteType(byte[] buf, int off) {
21: return latin1Table[buf[off] & 0xFF];
22: }
23:
24: int byteToAscii(byte[] buf, int off) {
25: return (char) buf[off];
26: }
27:
28: // c is a significant ASCII character
29: boolean charMatches(byte[] buf, int off, char c) {
30: return (char) buf[off] == c;
31: }
32:
33: public int convert(byte[] sourceBuf, int sourceStart,
34: int sourceEnd, char[] targetBuf, int targetStart) {
35: int initTargetStart = targetStart;
36: int c;
37: while (sourceStart != sourceEnd)
38: targetBuf[targetStart++] = (char) (sourceBuf[sourceStart++] & 0xFF);
39: return targetStart - initTargetStart;
40: }
41:
42: public int getFixedBytesPerChar() {
43: return 1;
44: }
45:
46: public void movePosition(final byte[] buf, int off, int end,
47: Position pos) {
48: /* Maintain the invariant: off - colStart == colNumber. */
49: int colStart = off - pos.columnNumber;
50: int lineNumber = pos.lineNumber;
51: while (off != end) {
52: byte b = buf[off++];
53: switch (b) {
54: case (byte) '\n':
55: lineNumber += 1;
56: colStart = off;
57: break;
58: case (byte) '\r':
59: lineNumber += 1;
60: if (off != end && buf[off] == '\n')
61: off++;
62: colStart = off;
63: break;
64: }
65: }
66: pos.columnNumber = off - colStart;
67: pos.lineNumber = lineNumber;
68: }
69:
70: int extendData(final byte[] buf, int off, final int end) {
71: while (off != end && latin1Table[buf[off] & 0xFF] >= 0)
72: off++;
73: return off;
74: }
75:
76: }
|