Class IndentationUtils
- java.lang.Object
-
- net.ssehub.easy.instantiation.core.model.templateModel.IndentationUtils
-
public class IndentationUtils extends java.lang.ObjectIndentation utilities.- Author:
- Holger Eichelberger
-
-
Constructor Summary
Constructors Modifier Constructor Description privateIndentationUtils()Prevents external instantiation.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description private static intadvanceIfNextIsNewLine(java.lang.CharSequence text, int pos)Advance the given position if it is a new line.static booleanallLinesStartWith(java.lang.String text, int indent)Returns whether all lines start with the givenindent.static java.lang.StringappendWithLastIndentation(java.lang.String string, java.lang.String text, boolean skipLastIndent)Appends the with last indentation tostring.static intcountLineEnds(java.lang.CharSequence string, int startPos)Returns the number of line ends considering returns and new lines instringafterstartPos.private static intinsertIndentation(java.lang.StringBuilder text, int pos, int indentation)Inserts an indentation ofindentationwhitespaces atposintotext.static java.lang.StringinsertIndentation(java.lang.String content, int indentation, boolean skipFirst)Inserts indentation intocontent, i.e.,indentationwhitespaces at each line start.static booleanisIndentationChar(char ch)Returns whetherchis an indentation character.static booleanisIndentationString(java.lang.String text)Does the giventextjust consist of indentation characters?static booleanisLineEnd(char ch)Returns whetherchis a line end character.private static booleannextIs(java.lang.CharSequence text, int pos, char ch)Returns whether the next character intextafterposisch.static java.lang.StringremoveIndentation(java.lang.String content, int indentation, int tabEmu)Remove indentation incontent, i.e., all whitespace/tab combinations matching the givenindentationfollowing a line start.static java.lang.StringremoveLastIndentation(java.lang.String text, boolean includingLineEnd)Removes the last indentation intextif present.private static intskipWhitespaces(java.lang.StringBuilder text, int pos)Skips the whitespaces and tabs atposintext.
-
-
-
Method Detail
-
removeIndentation
public static java.lang.String removeIndentation(java.lang.String content, int indentation, int tabEmu)Remove indentation incontent, i.e., all whitespace/tab combinations matching the givenindentationfollowing a line start.- Parameters:
content- the text to operate onindentation- the actual indentation in number of whitespaces (positive number)tabEmu- the tab emulation in whitespaces (0 if disabled, positive number else)- Returns:
contentwithout indentation
-
nextIs
private static boolean nextIs(java.lang.CharSequence text, int pos, char ch)Returns whether the next character intextafterposisch.- Parameters:
text- the text to analyzepos- the positionch- the character to look for- Returns:
trueif the next character isch,falseelse
-
advanceIfNextIsNewLine
private static int advanceIfNextIsNewLine(java.lang.CharSequence text, int pos)Advance the given position if it is a new line.- Parameters:
text- the text to analyzepos- the position- Returns:
- the (not) advanced position
-
insertIndentation
public static java.lang.String insertIndentation(java.lang.String content, int indentation, boolean skipFirst)Inserts indentation intocontent, i.e.,indentationwhitespaces at each line start.- Parameters:
content- the text to operate onindentation- the actual indentation in number of whitespaces (positive number)skipFirst- skip the first indentation- Returns:
contentwithout indentation
-
isIndentationChar
public static boolean isIndentationChar(char ch)
Returns whetherchis an indentation character.- Parameters:
ch- the character- Returns:
truefor indentation character,falseelse
-
isLineEnd
public static boolean isLineEnd(char ch)
Returns whetherchis a line end character.- Parameters:
ch- the character- Returns:
truefor line end character,falseelse
-
skipWhitespaces
private static int skipWhitespaces(java.lang.StringBuilder text, int pos)Skips the whitespaces and tabs atposintext.- Parameters:
text- the text to be consideredpos- the start position- Returns:
- the position of the first character in
textafter the whitespaces or the first position after the end oftext
-
insertIndentation
private static int insertIndentation(java.lang.StringBuilder text, int pos, int indentation)Inserts an indentation ofindentationwhitespaces atposintotext.- Parameters:
text- the text to be modifiedpos- the insert positionindentation- the number of whitespaces to be inserted- Returns:
- the new position at the end of the indentation
-
appendWithLastIndentation
public static java.lang.String appendWithLastIndentation(java.lang.String string, java.lang.String text, boolean skipLastIndent)Appends the with last indentation tostring.- Parameters:
string- the string to look intotext- the text to appendskipLastIndent- anyway skip the last indentation- Returns:
- the string with appended indentation (if there was any)
-
countLineEnds
public static int countLineEnds(java.lang.CharSequence string, int startPos)Returns the number of line ends considering returns and new lines instringafterstartPos.- Parameters:
string- the string to analyzestartPos- the start position within string- Returns:
- the number of line ends
-
allLinesStartWith
public static boolean allLinesStartWith(java.lang.String text, int indent)Returns whether all lines start with the givenindent.- Parameters:
text- the text to analyzeindent- the indent to check for- Returns:
trueif all lines start with the given indent,falseelse
-
removeLastIndentation
public static java.lang.String removeLastIndentation(java.lang.String text, boolean includingLineEnd)Removes the last indentation intextif present. This includes (from end oftext) line end characters and indentation characters, but no further characters.- Parameters:
text- the text to remove the last indentation forincludingLineEnd- whether the preceing line end(s) shall also be removed- Returns:
- the text without last indentation
-
isIndentationString
public static boolean isIndentationString(java.lang.String text)
Does the giventextjust consist of indentation characters?- Parameters:
text- the text- Returns:
trueif just indentation characters,falseelse
-
-