Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Line break normalization #207

Open
quantum3k opened this issue Nov 2, 2021 · 0 comments
Open

Line break normalization #207

quantum3k opened this issue Nov 2, 2021 · 0 comments

Comments

@quantum3k
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant