1 /*
2 * Copyright (c) 1999, 2019, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
248 * A LineMap that handles tab expansion correctly. The cost is
249 * an additional bit per character in the source array.
250 */
251 public static class LineTabMapImpl extends LineMapImpl {
252 private BitSet tabMap; // bits set for tab positions.
253
254 public LineTabMapImpl(int max) {
255 super();
256 tabMap = new BitSet(max);
257 }
258
259 protected void setTabPosition(int offset) {
260 tabMap.set(offset);
261 }
262
263 public int getColumnNumber(int pos) {
264 int lineStart = startPosition[getLineNumber(pos) - FIRSTLINE];
265 int column = 0;
266 for (int bp = lineStart; bp < pos; bp++) {
267 if (tabMap.get(bp))
268 column = (column / TabInc * TabInc) + TabInc;
269 else
270 column++;
271 }
272 return column + FIRSTCOLUMN;
273 }
274
275 public int getPosition(int line, int column) {
276 int pos = startPosition[line - FIRSTLINE];
277 column -= FIRSTCOLUMN;
278 int col = 0;
279 while (col < column) {
280 pos++;
281 if (tabMap.get(pos))
282 col = (col / TabInc * TabInc) + TabInc;
283 else
284 col++;
285 }
286 return pos;
287 }
288 }
289 }
|
1 /*
2 * Copyright (c) 1999, 2020, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
248 * A LineMap that handles tab expansion correctly. The cost is
249 * an additional bit per character in the source array.
250 */
251 public static class LineTabMapImpl extends LineMapImpl {
252 private BitSet tabMap; // bits set for tab positions.
253
254 public LineTabMapImpl(int max) {
255 super();
256 tabMap = new BitSet(max);
257 }
258
259 protected void setTabPosition(int offset) {
260 tabMap.set(offset);
261 }
262
263 public int getColumnNumber(int pos) {
264 int lineStart = startPosition[getLineNumber(pos) - FIRSTLINE];
265 int column = 0;
266 for (int bp = lineStart; bp < pos; bp++) {
267 if (tabMap.get(bp))
268 column = tabulate(column);
269 else
270 column++;
271 }
272 return column + FIRSTCOLUMN;
273 }
274
275 public int getPosition(int line, int column) {
276 int pos = startPosition[line - FIRSTLINE];
277 column -= FIRSTCOLUMN;
278 int col = 0;
279 while (col < column) {
280 pos++;
281 if (tabMap.get(pos))
282 col = tabulate(col);
283 else
284 col++;
285 }
286 return pos;
287 }
288 }
289 }
|