C · Splitting and Partitioning

Splitting and Partitioning

#include <stringzilla/strings.h> 6.0.0-rc.1 · 91a27bdd

API

Types

sz_split_kind_tHow a split ends its parts.
strings.h:84 ↗
enum sz_split_kind_t

Values

sz_split_each_k0Every delimiter ends a part, so neighbouring delimiters leave empty parts, as str.split(sep) does.
sz_split_runs_k1A run of delimiters ends one part and empty parts are skipped, as str.split() does.
sz_kernel_strings_split_tSignature of the sz_strings_split_best kernels, kept beside the enum it takes.
strings.h:95 ↗
typedef sz_status_t(*) sz_kernel_strings_split_t(sz_cptr_t, sz_size_t, sz_byteset_t const *, sz_split_kind_t, sz_allocator_t *, sz_strings_span_t *, sz_stream_t);
sz_kernel_strings_split_lines_tSignature of the sz_strings_split_lines_best kernels.
strings.h:99 ↗
typedef sz_status_t(*) sz_kernel_strings_split_lines_t(sz_cptr_t, sz_size_t, sz_allocator_t *, sz_strings_span_t *, sz_stream_t);
sz_kernel_strings_join_tSignature of the sz_strings_join_best kernels.
strings.h:103 ↗
typedef sz_status_t(*) sz_kernel_strings_join_t(sz_strings_view_t const *, sz_size_t, sz_size_t, sz_string_view_t const *, sz_string_view_t, sz_ptr_t, sz_size_t *, sz_stream_t);

Functions

sz_strings_split_bestSplits text at the bytes of delimiters into a tape of the parts between them.
strings.h:935 ↗
sz_status_t sz_strings_split_best(
    sz_cptr_t text,
    sz_size_t length,
    sz_byteset_t const *delimiters,
    sz_split_kind_t kind,
    sz_allocator_t *allocator,
    sz_strings_span_t *tape,
    sz_capability_t capabilities,
    sz_stream_t stream);

Backends

  • sz_strings_splitserialicelakeneon

With sz_split_each_k a text of n delimiters always makes n + 1 parts, like Python's bytes.split(sep) for a one-byte sep, generalized to a set. With sz_split_runs_k leading and trailing runs make no parts, like bytes.split() when the set is ASCII whitespace. Measures the parts first, then writes blocks of exactly their sizes, reusing those of tape like sz_strings_to_tape_best unless text lies in them; like every collection verb it is atomic.

Parameters

textinThe bytes to split, null only when length is zero.
lengthinNumber of bytes in text.
delimitersinThe bytes that separate the parts.
kindinWhether every delimiter ends a part, or every run of them.
allocatorinWhere the blocks of tape come from and return to.
tapeinoutA zeroed span, or one an earlier call produced.
capabilitiesinOne device's capabilities, like sz_capabilities_enabled_cpu reports.
streaminNull, as only CPUs split.
sz_strings_split_lines_bestSplits text at Unicode line breaks, CR LF as one, into a tape of lines without breaks.
strings.h:977 ↗
sz_status_t sz_strings_split_lines_best(
    sz_cptr_t text,
    sz_size_t length,
    sz_allocator_t *allocator,
    sz_strings_span_t *tape,
    sz_capability_t capabilities,
    sz_stream_t stream);

Backends

  • sz_strings_split_linesserialicelakeneon

The breaks are those of Python's str.splitlines() over UTF-8: LF, VT, FF, CR, FS, GS, RS, CR LF, NEL, LS and PS, and a final break leaves no empty line after it. Allocates and reuses tape like sz_strings_split_best, and like every collection verb it is atomic.

Parameters

textinThe UTF-8 bytes to split, null only when length is zero.
lengthinNumber of bytes in text.
allocatorinWhere the blocks of tape come from and return to.
tapeinoutA zeroed span, or one an earlier call produced.
capabilitiesinOne device's capabilities, like sz_capabilities_enabled_cpu reports.
streaminNull, as only CPUs split.

See also

sz_strings_join_bestWrites row r of columns as frames[0] + columns[0][r] + frames[1] + … + columns[n-1][r] + frames[n], with between written between rows, into output; a null output only measures into length.
strings.h:1020 ↗
sz_status_t sz_strings_join_best(
    sz_strings_view_t const *columns,
    sz_size_t columns_count,
    sz_size_t rows,
    sz_string_view_t const *frames,
    sz_string_view_t between,
    sz_ptr_t output,
    sz_size_t *length,
    sz_capability_t capabilities,
    sz_stream_t stream);

Backends

  • sz_strings_joinserialicelakeneon

Serializes columns as CSV lines, JSON arrays or SQL value lists without a string per cell, and joins one column with an empty frame on each side like Python's str.join.

Parameters

columnsinThe columns_count columns of rows strings each, in any layouts.
columns_countinNumber of columns, one less than the number of frames.
rowsinNumber of strings in every column.
framesinThe strings written before, between and after the cells of every row.
betweeninThe string written between consecutive rows.
outputoutRoom for exactly length bytes, or null to measure them.
lengthinoutThe bytes the join takes: written when output is null, read otherwise.
capabilitiesinOne device's capabilities, like sz_capabilities_enabled_cpu reports.
streaminNull, as only CPUs join.

Statuses