Stringy icon indicating copy to clipboard operation
Stringy copied to clipboard

Line break normalization

Open quantum3k opened this issue 3 years ago • 0 comments

I suggest add feature for normalization line breaks. RegEx have modifier \R that matches any Unicode newline sequence. Equivalent to (?>\r\n|\n|\x0b|\f|\r|\x85). And the sources texts are sometimes very unpredictable with line breaks.

May be conside normalization method something like

	/**
	 * Normalizes all line endings in this string by using a single unified newline sequence (which may be specified manually)
	 *
	 * @param string $text source text for normalize
	 * @param string|null $newlineSequence the target newline sequence to use (optional)
	 * @return string normalized text
	 */
	public function normalizeLineEndings($text, $newlineSequence = null) {
		if ($newlineSequence === null) {
			$newlineSequence = "\n";
		}

		return \preg_replace('/\R/u', $newlineSequence, $text);
	}

(С) Borrowed this handy solution from the library https://github.com/delight-im/PHP-Str

quantum3k avatar Nov 02 '21 08:11 quantum3k