Open samdark opened 1 year ago
Seems, problem here:
It's allow escape separate symbols. For example:
array: ['x']['a.b']['c']
path: x.a\.b.c
For boost may prepare key via explode('.', self::ARR_PATH)
.
Need to try this:
<?php
$key = 'x.a\.b.c';
$parts = splitIt($key);
var_dump($parts);
function splitIt(string $key, string $delimiter = '.', $escape = '\\')
{
$prev = 0;
$parts = [];
for ($i = 0, $len = strlen($key); $i < $len; $i++) {
if ($key[$i] === $delimiter && ($i === 0 || $key[$i-1] !== $escape)) {
$parts[] = str_replace($escape, '', substr($key, $prev, $i - $prev));
$prev = $i + 1;
}
}
$parts[] = substr($key, $prev, $i - $prev);
return $parts;
}
Also
$array = preg_split('~\\\\.(*SKIP)(*FAIL)|\|~s', $string);
See https://stackoverflow.com/questions/6243778/split-string-by-delimiter-but-not-if-it-is-escaped
Here is a benchamark code
And results