Blender V5.0
blender::csv_parse::detail Namespace Reference

Functions

int64_t find_end_of_simple_field (Span< char > buffer, int64_t start, char delimiter)
std::optional< int64_tfind_end_of_quoted_field (Span< char > buffer, int64_t start, char quote, Span< char > escape_chars)
std::optional< int64_tparse_record_fields (const Span< char > buffer, const int64_t start, const char delimiter, const char quote, const Span< char > quote_escape_chars, Vector< Span< char > > &r_fields)

Function Documentation

◆ find_end_of_quoted_field()

std::optional< int64_t > blender::csv_parse::detail::find_end_of_quoted_field ( Span< char > buffer,
int64_t start,
char quote,
Span< char > escape_chars )

Find the index of the quote that ends the current field.

Parameters
startThe index after the opening quote.
quoteThe quote character that ends the field.
escape_charsThe characters that may be used to escape the quote character.
Returns
Index of the quote character that ends the field, or std::nullopt if the field is malformed and does not have an end.

Definition at line 299 of file csv_parse.cc.

References blender::Span< T >::contains(), find_end_of_quoted_field(), i, and blender::Span< T >::size().

Referenced by find_end_of_quoted_field(), blender::csv_parse::tests::find_end_of_quoted_field(), and parse_record_fields().

◆ find_end_of_simple_field()

int64_t blender::csv_parse::detail::find_end_of_simple_field ( Span< char > buffer,
int64_t start,
char delimiter )

Find the index that ends the current field, i.e. the index of the next delimiter of newline. The start index has to be the index of the first character in the field. It may also be the end of the field already if it is empty.

Parameters
startThe index of the first character in the field. This may also be the end of the field already if it is empty.
delimiterThe character that ends the field.
Returns
Index of the next delimiter, a newline character or the end of the buffer.

Definition at line 284 of file csv_parse.cc.

References ELEM, find_end_of_simple_field(), i, and blender::Span< T >::size().

Referenced by find_end_of_simple_field(), blender::csv_parse::tests::find_end_of_simple_field(), and parse_record_fields().

◆ parse_record_fields()

std::optional< int64_t > blender::csv_parse::detail::parse_record_fields ( const Span< char > buffer,
const int64_t start,
const char delimiter,
const char quote,
const Span< char > quote_escape_chars,
Vector< Span< char > > & r_fields )

Finds all fields for the record starting at the given index. Typically, the record ends with a newline, but quoted multi-line records are supported as well.

Returns
Index of the start of the next record or the end of the buffer. #std::nullopt is returned if the buffer has a malformed record at the end, i.e. a quoted field that is not closed.

Definition at line 199 of file csv_parse.cc.

References BLI_assert_unreachable, ELEM, find_end_of_quoted_field(), find_end_of_simple_field(), blender::IndexRange::from_begin_end(), i, parse_record_fields(), blender::Span< T >::size(), and blender::Span< T >::slice().

Referenced by parse_record_fields().