2 * Copyright (c) 2008-2010 Mozilla Foundation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 * DEALINGS IN THE SOFTWARE.
23 package nu
.validator
.htmlparser
.impl
;
25 import nu
.validator
.htmlparser
.annotation
.NoLength
;
28 * An UTF-16 buffer that knows the start and end indeces of its unconsumed
34 public final class UTF16Buffer
{
37 * The backing store of the buffer. May be larger than the logical content
38 * of this <code>UTF16Buffer</code>.
40 private final @NoLength char[] buffer
;
43 * The index of the first unconsumed character in the backing buffer.
48 * The index of the slot immediately after the last character in the backing
49 * buffer that is part of the logical content of this
50 * <code>UTF16Buffer</code>.
57 * Constructor for wrapping an existing UTF-16 code unit array.
62 * the index of the first character to consume
64 * the index immediately after the last character to consume
66 public UTF16Buffer(@NoLength char[] buffer
, int start
, int end
) {
75 * Returns the start index.
77 * @return the start index
79 public int getStart() {
84 * Sets the start index.
89 public void setStart(int start
) {
94 * Returns the backing buffer.
96 * @return the backing buffer
98 public @NoLength char[] getBuffer() {
103 * Returns the end index.
105 * @return the end index
107 public int getEnd() {
112 * Checks if the buffer has data left.
114 * @return <code>true</code> if there's data left
116 public boolean hasMore() {
121 * Returns <code>end - start</code>.
123 * @return <code>end - start</code>
125 public int getLength() {
130 * Adjusts the start index to skip over the first character if it is a line
131 * feed and the previous character was a carriage return.
134 * whether the previous character was a carriage return
136 public void adjust(boolean lastWasCR
) {
137 if (lastWasCR
&& buffer
[start
] == '\n') {
143 * Sets the end index.
148 public void setEnd(int end
) {