identWith method

String identWith(
  1. int deepLevel, [
  2. String identWith = " ",
  3. int multiplier = 1
])

Adds indentation to a string based on the specified deep level and indentation characters.

The deepLevel parameter specifies the number of indentation levels to add. The identWith parameter specifies the characters used for indentation. By default, it is a single space character.

  • If identWith is a single character, it will be repeated for each indentation level.
  • If identWith is a two-character string, the first character will be repeated for each indentation level, and the second character will be used for the last indentation level.
  • If identWith is a multi-character string, the first character will be used for the first indentation level, the last character will be used for the last indentation level, and the middle characters will be repeated to fill the remaining space. The multiplier parameter specifies the number of times to repeat the indentation characters for each level.

Example

String text = ' Hello, world!';
String indentedText = text.identWith(4, '>=>');
print(indentedText); // Output: '>==> Hello, world!'
String text = ' Hello, world!';
String indentedText = text.identWith(2, '  ');
print(indentedText); // Output: '    Hello, world!'

Implementation

String identWith(int deepLevel, [String identWith = " ", int multiplier = 1]) {
  if (deepLevel == 0) return this;
  var ii = identArrow(length: deepLevel * multiplier.clampMin(1), pattern: identWith);
  if (deepLevel > 0) {
    return ii + this;
  } else {
    return this + ii;
  }
}