Java String Indent Format indentationStringOfCursorLine(String text, int cursor)

Here you can find the source of indentationStringOfCursorLine(String text, int cursor)

Description

indentation String Of Cursor Line

License

Apache License

Declaration

public static String indentationStringOfCursorLine(String text, int cursor) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    public static String indentationStringOfCursorLine(String text, int cursor) {
        int lineStart = startColOfCursorLine(text, cursor);
        int firstCharAt = lineStart;
        while (firstCharAt < text.length()) {
            // TODO: tab indentation?
            if (text.charAt(firstCharAt) != ' ') {
                break;
            }/*from w w w  .  j  a  va  2  s  . c  o m*/
            ++firstCharAt;
        }
        return text.substring(lineStart, firstCharAt);
    }

    public static int startColOfCursorLine(String text, int cursor) {
        int i = cursor;
        while (i > 0) {
            char c = text.charAt(i - 1);
            if (c == '\n') {
                break;
            }
            --i;
        }
        return i;
    }
}

Related

  1. indent2(String text, String indent)
  2. indentAllLines(String s, String indent)
  3. indentation(int howMany)
  4. indentation(int numberOfIndent)
  5. indentationLevel(CharSequence c)
  6. indentCode(String code, int indentLevel)
  7. indented(String indenter, String s)
  8. indentHtmlSpaces(int count)
  9. indention(int level, int tabSize)