private function clearLeadingAndTrailingSpaces(string $sentence) : string
    {
        if ($this->trailing_optimization) {
            $sentence = preg_replace('/^\\s+/', '', $sentence);
            $sentence = preg_replace('/\\s+$/', '', $sentence);
            $sentence = preg_replace('/\\s*\\n\\s*/', ' ', $sentence);
        }

        return $sentence;
    }