Here you can find the source of expandTabs(String string, int tabSize)
Parameter | Description |
---|---|
string | the string |
tabSize | the tab size |
private static StringBuffer expandTabs(String string, int tabSize)
//package com.java2s; /******************************************************************************* * Copyright (c) 2000, 2015 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors://from ww w . j a v a 2s .c o m * IBM Corporation - initial API and implementation *******************************************************************************/ public class Main { /** * Expands the given string's tabs according to the given tab size. * * @param string the string * @param tabSize the tab size * @return the expanded string * @since 3.1 */ private static StringBuffer expandTabs(String string, int tabSize) { StringBuffer expanded = new StringBuffer(); for (int i = 0, n = string.length(), chars = 0; i < n; i++) { char ch = string.charAt(i); if (ch == '\t') { for (; chars < tabSize; chars++) expanded.append(' '); chars = 0; } else { expanded.append(ch); chars++; if (chars >= tabSize) chars = 0; } } return expanded; } }