private static function eolWorkaround_addPlaceholders($iniString)
{
$prefaceString = ' = "';
// sequence of characters before string value
$position = 0;
$length = strlen($iniString);
$result = "";
// Read the string char by char
while ($position < $length) {
$nextPrefacePos = strpos($iniString, $prefaceString, $position);
if ($nextPrefacePos === false) {
// There are no more string values
// Just append the rest of the string and we're done
$result .= substr($iniString, $position);
break;
}
// Append everything from the end of last string value to the start of another
$result .= StringUtils::substringFromTo($iniString, $position, $nextPrefacePos + strlen($prefaceString));
// Set position to the start of the string value
$position = $nextPrefacePos + strlen($prefaceString);
$stringBeginPos = $stringEndPos = $position;
$isEndOfString = false;
while (!$isEndOfString) {
if ($iniString[$position] === '\\') {
// Found escaped character
// Skip this one and the following one
$position += 2;
continue;
} else {
if ($iniString[$position] === '"') {
// This is it. Unescaped double-quote means that the string value ends here.
$isEndOfString = true;
$stringEndPos = $position;
} else {
// Regular character. Boooring - move along.
$position += 1;
}
}
}
// OK. We have the beginning and the end. Let's replace all line-endings with placeholders.
$value = StringUtils::substringFromTo($iniString, $stringBeginPos, $stringEndPos);
$result .= self::getReplacedEolString($value, 'charsToPlaceholders');
}
return $result;
}