• Модуль: main
  • Путь к файлу: ~/bitrix/modules/main/classes/general/csv_data.php
  • Класс: CCSVData
  • Вызов: CCSVData::FetchDelimiter
public function FetchDelimiter()
{
	if (!$this->__file)
	{
		return false;
	}

	$bInString = false;
	$str = "";
	$res_r = array();
	while ($this->iCurPos < $this->iFileLength)
	{
		$ch = $this->__buffer[$this->__buffer_pos];
		if ($ch == "r" || $ch == "n")
		{
			if (!$bInString)
			{
				while ($this->iCurPos < $this->iFileLength)
				{
					$this->IncCurPos();
					$ch = $this->__buffer[$this->__buffer_pos];
					if ($ch != "r" && $ch != "n")
					{
						break;
					}
				}
				if ($this->bFirstHeader)
				{
					$this->bFirstHeader = false;
					$res_r = array();
					$str = "";
					continue;
				}
				else
				{
					$res_r[] = $str;
					return $res_r;
				}
			}
		}
		elseif ($ch == """)
		{
			if (!$bInString)
			{
				$bInString = true;
				$this->IncCurPos();
				continue;
			}
			else
			{
				$this->IncCurPos();
				if($this->__buffer[$this->__buffer_pos]!=""")
				{
					$bInString = false;
					continue;
				}
			}
		}
		elseif ($ch == $this->cDelimiter)
		{
			if (!$bInString)
			{
				$res_r[] = $str;
				$str = "";
				$this->IncCurPos();
				continue;
			}
		}

		//inline "call"
		$this->iCurPos++;
		$this->__buffer_pos++;
		if($this->__buffer_pos >= $this->__buffer_size)
		{
			if(feof($this->__file))
			{
				$this->__buffer = "";
			}
			else
			{
				$this->__buffer = fread($this->__file, 1024*1024);
			}
			$this->__buffer_size = strlen($this->__buffer);
			$this->__buffer_pos = 0;
		}

		$str .= $ch;
	}

	if ($str <> '')
	{
		$res_r[] = $str;
	}

	if(empty($res_r))
	{
		return false;
	}
	else
	{
		return $res_r;
	}
}