Here you can find the source of getOffsetOfVirtualColumn(Segment seg, int tabSize, int column, int[] totalVirtualWidth)
Parameter | Description |
---|---|
seg | The segment |
tabSize | The tab size |
column | The virtual column number |
totalVirtualWidth | If this array is non-null, the total virtual width will be stored in its first location if this method returns -1. |
public static int getOffsetOfVirtualColumn(Segment seg, int tabSize, int column, int[] totalVirtualWidth)
//package com.java2s; /*/*from w w w.j a va 2 s .co m*/ * StandardUtilities.java - Various miscallaneous utility functions * :tabSize=4:indentSize=4:noTabs=false: * :folding=explicit:collapseFolds=1: * * Copyright (C) 1999, 2006 Matthieu Casanova, Slava Pestov * Portions copyright (C) 2000 Richard S. Hall * Portions copyright (C) 2001 Dirk Moebius * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ import javax.swing.text.Segment; public class Main { /** * Returns the array offset of a virtual column number (taking tabs * into account) in the segment. * * @param seg The segment * @param tabSize The tab size * @param column The virtual column number * @param totalVirtualWidth If this array is non-null, the total * virtual width will be stored in its first location if this method * returns -1. * * @return -1 if the column is out of bounds */ public static int getOffsetOfVirtualColumn(Segment seg, int tabSize, int column, int[] totalVirtualWidth) { int virtualPosition = 0; for (int i = 0; i < seg.count; i++) { char ch = seg.array[seg.offset + i]; if (ch == '\t') { int tabWidth = tabSize - virtualPosition % tabSize; if (virtualPosition >= column) return i; else virtualPosition += tabWidth; } else { if (virtualPosition >= column) return i; else ++virtualPosition; } } if (totalVirtualWidth != null) totalVirtualWidth[0] = virtualPosition; return -1; } }