Java String Extract extractHorizontalTabs(String line, int tabSize)

Here you can find the source of extractHorizontalTabs(String line, int tabSize)

Description

extract Horizontal Tabs

License

Apache License

Declaration

private static String extractHorizontalTabs(String line, int tabSize) 

Method Source Code

//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();
    }
}

Related

  1. extractCharNgram(String content, int n)
  2. extractCommands(String fileContents)
  3. extractData(String message)
  4. extractField(int position, String regex, String source)
  5. extractGenericTypeNames(String sig)
  6. extractItems(String items)
  7. extractJobId(String line)
  8. extractKeyCodes(String codes)
  9. extractLines(String data, int tabWidth)