Skip to content

Main content

Line Prefix Common Indent Tool

Find a literal common space/tab prefix without expanding tabs or excluding blank lines.

Loading tool…

Description

Find a literal common space/tab prefix without expanding tabs or excluding blank lines.

Text positions can be measured in UTF-16 code units, Unicode code points, grapheme clusters, or modeled display columns. These coordinates are not interchangeable. Invisible markers and delimiter policies can also affect interpretation even when a string looks unchanged, so the chosen representation needs to stay explicit.

Find a literal common space/tab prefix without expanding tabs or excluding blank lines.

When to use this tool

Use Line Prefix Common Indent when you need the stated marker, coordinate, delimiter, or normalization operation under an explicit text representation.

How to use the tool and how it works

  1. Enter lines. Use the units and conventions below.
  2. Run the tool. Correct any format, range, or cross-field input error before interpreting the output.
  3. Read commonIndent, units. Use the output convention below.

Extract leading ASCII spaces and tabs from each line in a nonempty list, then return their longest identical literal prefix and its UTF-16 length as units.1

Input fieldMeaning and unitsAccepted input
linesLinesRequired. Array of text; maximum UTF-16 length 8192; maximum items 256.
Output fieldInterpretationReturned shape
commonIndentCommon IndentRequired. Text; maximum UTF-16 length 8192.
unitsLiteral common indentation length, not equivalent display columns.Required. Safe integer.
json
{
  "input": {
    "lines": [
      "  a",
      "    b"
    ]
  },
  "output": {
    "commonIndent": "  ",
    "units": 2
  }
}

Limitations and assumptions

  • Tabs and spaces are distinct characters rather than equivalent display columns. Empty or unindented lines can reduce the common prefix to empty; no lines are dedented.
  • The field tables state structural bounds; the mechanics also specify cross-field constraints. Malformed inputs and unsupported domains cause errors. A successful false flag, empty branch value, or zero placeholder has the meaning stated above and is distinct from an input error.

Alternative or Complementary methods

Choose the coordinate system required by the consumer. Use a full parser, renderer, or segmentation method when a local marker or delimiter rule cannot determine the complete text behavior.

References

  1. Calculation and input contract: text/line-prefix-common-indent — tool.io

Similar or alternative tools