• Модуль: translate
  • Путь к файлу: ~/bitrix/modules/translate/lib/io/csvfile.php
  • Класс: BitrixTranslateIOCsvFile
  • Вызов: CsvFile::fetchDelimiter
protected function fetchDelimiter(): ?array
{
	$isInside = false;
	$str = '';
	$result = [];
	while ($this->currentPosition <= $this->fileSize)
	{
		$ch = $this->buffer[$this->bufferPosition];
		if ($ch === "r" || $ch === "n")
		{
			if (!$isInside)
			{
				while ($this->currentPosition <= $this->fileSize)
				{
					$this->incrementCurrentPosition();
					$ch = $this->buffer[$this->bufferPosition];
					if ($ch !== "r" && $ch !== "n")
					{
						break;
					}
				}
				if ($this->firstHeader)
				{
					$this->firstHeader = false;
					$result = [];
					$str = '';
					continue;
				}

				$result[] = $str;

				return $result;
			}
		}
		elseif ($ch === """)
		{
			if (!$isInside)
			{
				$isInside = true;
				$this->incrementCurrentPosition();
				continue;
			}

			$this->incrementCurrentPosition();
			if ($this->buffer[$this->bufferPosition] !== """)
			{
				$isInside = false;
				continue;
			}
		}
		elseif ($ch === $this->fieldDelimiter)
		{
			if (!$isInside)
			{
				$result[] = $str;
				$str = '';
				$this->incrementCurrentPosition();
				continue;
			}
		}

		//inline "call"
		$this->currentPosition ++;
		$this->bufferPosition ++;
		if ($this->bufferPosition >= $this->bufferSize)
		{
			$this->buffer = $this->read(1024 * 1024);
			$this->bufferSize = $this->getStringByteLength($this->buffer);
			$this->bufferPosition = 0;
		}

		$str .= $ch;
	}

	if ($str !== '')
	{
		$result[] = $str;
	}

	if ($result === [])
	{
		$result = null;
	}

	return $result;
}