C++ · Types

Types

#include <stringzilla/find.hpp> 6.0.0-rc.1 · cb8d956a

Ask your coding agent about this page, or add the docs server to it

curl -s 'https://www.unum.cloud/docs/stringzilla/cpp/types.md' | claude -p "How would this fit my code?"

The C++ layer is built on the types below plus a 256-bit byteset.

  • sz::string_slice<char_type> — a non-owning, length-bounded view over char or char const. Two aliases exist: the read-only sz::string_view_t = string_slice<char const> and the mutable sz::string_span_t = string_slice<char>.
  • sz::string<allocator = std::allocator<char>> — an owning, Small-String-Optimized char container; the alias sz::string_t uses the default std::allocator. A stateful allocator travels with the string under the usual std::allocator_traits propagation rules, and an empty one costs no bytes.
  • sz::strings_view_t — a non-owning column of strings, wrapping a sz_strings_view_t in any of its layouts.
  • sz::strings<allocator = sz::heap_alloc<char>> — an owned, move-only column, a sz_strings_span_t tape and the allocator of its blocks; the alias sz::strings_t uses the default.
  • sz::byteset_t — the C++ wrapper around sz_byteset_t, constructible from an initializer list, a (pointer, count) pair, or a std::array, and composable with operator|.
  • sz::status_t — a scoped enum mirroring sz_status_t with success_k, bad_alloc_k, invalid_utf8_k, contains_duplicates_k, and the rest, returned by the fallible free functions and the string’s allocating verbs.

sz::string_view_t is implicitly constructible from a char const *, a (pointer, length) pair, std::string, and std::string_view, and converts back to both; sz::string_t::make builds an owning string from a view or a lazy sz::concatenate(...) expression, and copy() duplicates one, both returning an sz::expected. Both keep the std::string/std::string_view members no kernel backs — data, size, length, empty, at, front, back, iterators, substr, compare, the relational operators, and operator<=>, which order bytes through std::char_traits. Both also stream through operator<<, and <stringzilla/hash.hpp> specializes std::hash<sz::string_t> / std::hash<sz::string_view_t>, so they work as unordered-container keys.

Every operation a kernel of the library backs is a free function taking any string, from StringZilla and STL strings to string literals, and its member spelling is deleted, with a comment naming the function. These members are gone, each replaced by the free function of the same name with the string first, like sz::find(text, "x") for text.find("x"):

  • find, rfind, contains, count, find_first_of, find_first_not_of, find_last_of, find_last_not_of, contains_only, the is_alpha family, partition, rpartition, lstrip, rstrip, strip, find_all, rfind_all, split and rsplit in <stringzilla/find.hpp>, where split(byteset) is sz::split_characters and splitlines() is sz::split_characters(text, sz::newlines_set());
  • starts_with, ends_with, and the matching remove_prefix and remove_suffix in <stringzilla/compare.hpp>;
  • hash, hash_multiseed, bytesum and fill_random in <stringzilla/hash.hpp>, with sz::hash_t and the std::hash specializations;
  • utf8_count, utf8_seek, utf8_runes and the other utf8_* ranges in <stringzilla/utf8_runes.hpp> and its siblings;
  • utf8_find_denormalized, is_normalized, utf8_normalize, utf8_uncased_* and utf8_uncased_fold in <stringzilla/utf8_norm.hpp> and <stringzilla/utf8_uncased.hpp>;
  • replace_all in <stringzilla/find.hpp>, and lookup in <stringzilla/strings_verbs.hpp>, both taking the string to change in place;
  • the column members find, hashes, utf8_count, to_rows, gather, escape, unescape, lookup, normalize and join in <stringzilla/strings_verbs.hpp>, where strings::split is sz::split_into and strings::split_lines is sz::split_lines.

A verb over the default mask returns its plain result, and the overload taking an explicit capability mask and stream returns an sz::expected. The lazy ranges keep only views, so they take lvalues and borrowed views, and refuse an owning temporary like std::string("a b") at compile time.

User-defined literals live in sz::literals:

using namespace sz::literals;
sz::string_view_t v = "needle"_sv;   // a view, no allocation
sz::byteset_t s = " \t\n\r"_bs;      // a byte-set from a literal

Convenience byte-sets are available as free functions: sz::whitespaces_set(), sz::newlines_set(), sz::digits_set(), sz::hexdigits_set(), sz::octdigits_set(), and sz::ascii_letters_set().

API

Types

string_view_forExtracts the view type of a string-like type: the nested string_view_t typedef of StringZilla types, or the type itself for STL types like std::string_view.
find.hpp:445 ↗
template <typename string_type_>
struct string_view_for