Rust

csv

Module

CSV parsing: str_getcsv() and fgetcsv().

A port of php_fgetcsv() (ext/standard/file.c, PHP 8.5): fields are split at the delimiter; a field starting (after leading whitespace) with the enclosure runs to the closing enclosure, a doubled enclosure is one enclosure character, an escape character protects the next byte (and is kept), and text after the closing enclosure up to the delimiter is appended raw. Unenclosed fields lose trailing whitespace; the line's trailing \r\n, \n or \r is dropped. An enclosure left open takes the following lines (fgetcsv()) or runs to the end of the input (str_getcsv()). A blank line is one null field.

Bytes are characters: the dev image's C library counts one byte per character in the default locale, so no multibyte sequence is special.

Contents

use php_std::csv::fgetcsv;
Rust
pub fn fgetcsv<R: BufRead>(reader: &mut R, delimiter: u8, enclosure: u8, escape: Option<u8>) -> io::Result<Option<Fields>>

PHP fgetcsv($stream, 0, $separator, $enclosure, $escape): the fields of the next record (an open enclosure takes the following lines), or None at the end of the stream (PHP's false).

use php_std::csv::str_getcsv;
Rust
pub fn str_getcsv(input: &[u8], delimiter: u8, enclosure: u8, escape: Option<u8>) -> Fields

PHP str_getcsv($string, $separator, $enclosure, $escape): the fields of input (an enclosure left open runs to the end); escape None is "" (no escape character).

Rust
pub type Fields = Vec<Option<Vec<u8>>>

One parsed line: its fields, or [null] (None) for a blank line.