private function addWrappedStringImpl()

in src/HackBuilder.hack [123:163]


  private function addWrappedStringImpl(
    string $line,
    ?int $max_length = null,
    bool $indent_non_first_lines = true,
  ): this {
    $max_length = $max_length !== null
      ? $max_length
      : // subtract 3 for the two quotes and . operator
        $this->getMaxCodeLength() - 3;

    $lines = $this->splitString($line, $max_length, /*preserve_space*/ true);
    if (!$lines) {
      return $this;
    }

    $this->add(_Private\normalized_var_export(C\first($lines)));
    if (C\count($lines) === 1) {
      return $this;
    }

    // If we have multiple line segments to add, add all the
    // inbetween ones with the concat operator
    $this->add('.')->newLine();

    if ($indent_non_first_lines) {
      $this->indent();
    }

    $lines
      |> Vec\slice($$, 1, C\count($lines) - 2)
      |> Vec\map(
        $$,
        $line ==> $this->addLine(_Private\normalized_var_export($line).'.'),
      );
    // And then add the last
    $this->add(_Private\normalized_var_export(C\last($lines)));
    if ($indent_non_first_lines) {
      $this->unindent();
    }
    return $this;
  }