1
2
3
4
5
6
7
8
9
10
11 package org.eclipse.jgit.util;
12
13
14
15
16
17
18 public final class RawCharSequence implements CharSequence {
19
20 public static final RawCharSequencee.html#RawCharSequence">RawCharSequence EMPTY = new RawCharSequence(null, 0, 0);
21
22 final byte[] buffer;
23
24 final int startPtr;
25
26 final int endPtr;
27
28
29
30
31
32
33
34
35
36
37
38 public RawCharSequence(byte[] buf, int start, int end) {
39 buffer = buf;
40 startPtr = start;
41 endPtr = end;
42 }
43
44
45 @Override
46 public char charAt(int index) {
47 return (char) (buffer[startPtr + index] & 0xff);
48 }
49
50
51 @Override
52 public int length() {
53 return endPtr - startPtr;
54 }
55
56
57 @Override
58 public CharSequence subSequence(int start, int end) {
59 return new RawCharSequence(buffer, startPtr + start, startPtr + end);
60 }
61
62
63 @Override
64 public String toString() {
65 final int n = length();
66 final StringBuilder b = new StringBuilder(n);
67 for (int i = 0; i < n; i++)
68 b.append(charAt(i));
69 return b.toString();
70 }
71 }