Java String Indent Format indentString(String s, char open, char middle, char close)

Here you can find the source of indentString(String s, char open, char middle, char close)

Description

To be used with (open,middle,close)=('[',',',']') for the output of ToStringBuilder.reflectionToString

License

Open Source License

Declaration

public static String indentString(String s, char open, char middle, char close) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /**/*from w  ww  .  j av a 2 s  .c  o  m*/
     * To be used with (open,middle,close)=('[',',',']') for the output of ToStringBuilder.reflectionToString
     */
    public static String indentString(String s, char open, char middle, char close) {
        StringBuilder b = new StringBuilder();
        int level = 0;
        for (int i = 0; i < s.length(); i++) {
            char c = s.charAt(i);
            if (c == open) {
                b.append(c);
                b.append("\n");
                ++level;
                for (int j = level; j > 0; --j)
                    b.append("  ");
            } else if (c == close) {
                b.append("\n");
                --level;
                for (int j = level; j > 0; --j)
                    b.append("  ");
                b.append(c);
            } else if (c == middle) {
                b.append(c);
                b.append("\n");
                for (int j = level; j > 0; --j)
                    b.append("  ");
            } else {
                b.append(c);
            }
        }
        return b.toString();
    }
}

Related

  1. indentRows(int level, String ss, String indentStr)
  2. indentStr(int level)
  3. indentString(final int indentSpaces)
  4. indentString(int indent)
  5. indentString(int indent)
  6. indentString(String str, String indent)
  7. indentStringBuffer(StringBuffer sb, int indent)
  8. indentText(String text, boolean indentFirstLine)
  9. indentTransform(String in, int indent)