Automattic\WooCommerce\Blocks\Domain\Services

CheckoutLink::split_escaped │ private │ WC 1.0

Split a string on unescaped delimiters.

Method of the class: CheckoutLink{}

No Hooks.

Returns

string[]. Split values with delimiter escapes removed.

Usage

// private - for code of main (parent) class only
$result = $this->split_escaped( $value, $delimiter, $limit );
$value(string) (required)
Value to split.
$delimiter(string) (required)
Single-character delimiter.
$limit(int)
Maximum number of returned segments.
Default: PHP_INT_MAX

CheckoutLink::split_escaped() code WC 11.3.0

private function split_escaped( $value, $delimiter, $limit = PHP_INT_MAX ) {
	$segments = [ '' ];
	$index    = 0;
	$length   = strlen( $value );

	for ( $position = 0; $position < $length; ++$position ) {
		$character = $value[ $position ];

		if ( '~' === $character && $position + 1 < $length && $delimiter === $value[ $position + 1 ] ) {
			$segments[ $index ] .= $delimiter;
			++$position;
		} elseif ( $delimiter === $character && count( $segments ) < $limit ) {
			$segments[] = '';
			++$index;
		} else {
			$segments[ $index ] .= $character;
		}
	}

	return $segments;
}