Android String Format formatIndent(String whiteSpace)

Here you can find the source of formatIndent(String whiteSpace)

Description

Formats the indent so that it uses as many tabs as possible

Declaration

public static String formatIndent(String whiteSpace) 

Method Source Code

//package com.java2s;

public class Main {
    public static final String ATAB = String.valueOf('\u0009');
    public static final String ASPACE = " ";

    /** Formats the indent so that it uses as many tabs as possible */
    public static String formatIndent(String whiteSpace) {
        int tabs, spaces, newTabs;
        char chTemp;
        String strTemp, ret;/*  ww  w  .ja  v a  2s  .  c o  m*/

        tabs = 0;
        spaces = 0;
        newTabs = 0;

        ret = "";

        for (int i = 0; i < whiteSpace.length(); i++) {
            chTemp = whiteSpace.charAt(i);
            strTemp = String.valueOf(chTemp);
            if (strTemp.equals(ASPACE))
                spaces++;
            else if (strTemp.equals(ATAB))
                tabs++;
        }
        if (spaces > 7) {
            newTabs = spaces / 8;
            spaces %= 8;
        }
        //Generate new indent
        for (int i = 0; i < tabs + newTabs; i++)
            ret += ATAB;
        for (int i = 0; i < spaces; i++)
            ret += ASPACE;

        return ret;
    }
}

Related

  1. simpleFormat(String s, Object aobj[])
  2. format(String str, Object... args)
  3. formatAccountNo(String accountNo)
  4. formattedNumber(String number)
  5. currentTime(CharSequence inFormat)
  6. formatNumberWithDecimals(Locale locale, String stringToFormat, int exactNumberOfDecimals)
  7. formatNumberWithDecimals(Locale locale, String stringToFormat, int minimalNumberOfDecimals, int maximumNumberOfDecimals)
  8. formatNumberWithThreeDecimals(Locale locale, String stringToFormat)
  9. formatNumberWithTwoDecimals(Locale locale, String stringToFormat)