normalizeSpaces property

List<String> get normalizeSpaces

Delete all unnecessary spaces.

Any space outside quotation marks is deleted.

Implementation

List<String> get normalizeSpaces {
  final output = <String>[];

  /// Current (list of) values is preceded by a single quotation mark.
  ///
  /// Example:
  /// ```
  /// {
  ///   "x": "foo"
  /// }
  /// ```
  ///
  /// The characters x, f, o and o are between single quotation marks.
  var insideQuotationMarks = false;

  /// Previous processed token.
  var previous = "";

  for (final char in this) {
    final token = _Token.fromChar(
      current: char,
      previous: previous,
    );

    if (token.shouldSkip(insideQuotationMarks)) {
      continue;
    }

    output.add(char);

    previous = char;

    insideQuotationMarks = token.isInsideQuotationMarks(insideQuotationMarks);
  }

  return output;
}