Here you can find the source of extractHorizontalTabs(String line, int tabSize)
private static String extractHorizontalTabs(String line, int tabSize)
//package com.java2s; /**//from w w w .j av a 2 s . com * Copyright 2014 ashigeru. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import java.util.ArrayList; import java.util.List; public class Main { /** * Extracts horizontal tabs in lines. * @param lines the source lines * @param tabSize the tab column size * @return the extracted lines */ public static List<String> extractHorizontalTabs(List<String> lines, int tabSize) { List<String> results = new ArrayList<String>(); for (String line : lines) { results.add(extractHorizontalTabs(line, tabSize)); } return results; } private static String extractHorizontalTabs(String line, int tabSize) { assert line != null; StringBuilder buf = new StringBuilder(); int column = 0; for (int i = 0, n = line.length(); i < n; i++) { char c = line.charAt(i); if (c == '\t') { int count = tabSize - column % tabSize; for (int j = 0; j < count; j++) { buf.append(' '); } } else { buf.append(c); column++; } } return buf.toString(); } }