indent method

String indent(
  1. int indentationLevel
)

Returns _input with indentationLevel applied while preserving relative indentation.

For example, the input:

Hello World

applied with indentationLevel of 3 results in:

Hello

World

If the starting indentation level is higher than indentationLevel, the value will be unindented accordingly.

For example, the input:

   Hello
  World

applied with indentationLevel of 3 also results in:

Hello

World

Implementation

String indent(int indentationLevel) {
  final lines = _processLines();
  final currentIndentationLevel = _findCommonIndentationLevel(lines);
  return _indent(lines, currentIndentationLevel, indentationLevel);
}