std::String::slice<Char, Traits>
slice<Char, Traits>
Represents a slice of a string with specified character type and traits, similar to std::string_view in C++
Template Parameters
CharTraits
Type Aliases
view_t = libcxx::basic_string_view<CharT>char_traits = Traitschar_t = CharTslice_t = slice<CharT>size_t = usizeslice_vec = vec<slice_t>char_vec = vec<CharT>
Enums
Operation
Operation type for string operations
Values
- Keep: Keep the delimiter in the result
- Remove: Remove the delimiter from the result
Private Members
len
- Type:
usize - Description: Length of the slice
data
- Type:
view_t - Description: String view data
- Default:
{}
Constructors
slice
Default constructor
slice() noexceptslice
Copy constructor
slice(const slice& other) noexceptslice
Move constructor
slice(slice&& other) noexceptslice
Constructor from C-style string
slice(const CharT* str) noexceptslice
Constructor from C-style string with size
slice(const CharT* str, size: size_t) noexceptslice
Constructor from string view
slice(view: view_t) noexceptslice
Constructor from character vector
slice(vec: char_vec&) noexceptslice
Constructor from character vector (move)
slice(vec: char_vec&&) noexceptOperators
operator view_t
Conversion to string view
op view_t(self) -> view_toperator==
Equality comparison
op ==(self, const slice& other) -> booloperator!=
Inequality comparison
op !=(self, const slice& other) -> booloperator<
Less than comparison
op <(self, const slice& other) -> booloperator>
Greater than comparison
op >(self, const slice& other) -> booloperator<=
Less than or equal comparison
op <=(self, const slice& other) -> booloperator>=
Greater than or equal comparison
op >=(self, const slice& other) -> booloperator in
Contains operator for slice
op in(self, needle: slice&) -> booloperator in
Contains operator for character
op in(self, chr: CharT&) -> booloperator[]
Access character at index
op [``](self, index: usize) -> CharTMethods
size
Returns the length of the slice’s data, essential for bounds checking and iteration
size(self) -> size_texchange
Exchanges content with another slice
exchange(self, other: slice&) -> voidreplace
Replaces content with another slice
replace(self, other: slice&) -> voidreplace
Replaces content with C-style string
replace(self, str: CharT*, size: usize) -> voidraw
Returns a pointer to the slice’s underlying data, essential for direct access
raw(self) -> const CharT*is_empty
Indicates whether the slice has no data, crucial for control flow
is_empty(self) -> boolsubslice
Creates a view into a portion of the slice, vital for safe substring operations
subslice(self, pos: usize, len: usize) -> slicel_strip
Strips whitespace from the left
l_strip(self, delim: char_vec& = {' ', '\t', '\n', '\r'}) -> slicer_strip
Strips whitespace from the right
r_strip(self, delim: char_vec& = {' ', '\t', '\n', '\r'}) -> slicestrip
Strips whitespace from both ends
strip(self, delim: char_vec& = {' ', '\t', '\n', '\r'}) -> slicelength
Returns the length of the slice
length(self) -> usizestarts_with
Checks if slice starts with needle
starts_with(self, needle: slice&) -> boolends_with
Checks if slice ends with needle
ends_with(self, needle: slice&) -> boolcontains
Checks if slice contains needle
contains(self, needle: slice&) -> boolcontains
Checks if slice contains character
contains(self, chr: CharT&) -> boolcompare
Compares two slices lexicographically
compare(self, other: slice&) -> isizesplit_lines
Returns a vector of line views, necessary for line-based processing
split_lines(self) -> slice_vecsplit
Returns a vector of views, necessary for delimiter-based processing
split(self, delim: slice&, op: Operation = Operation::Remove) -> slice_veclfind
Finds first occurrence of needle
lfind(self, needle: slice&) -> usize?rfind
Finds last occurrence of needle
rfind(self, needle: slice&) -> usize?find_first_of
Finds first occurrence of any character in needle
find_first_of(self, needle: slice&) -> usize?find_last_of
Finds last occurrence of any character in needle
find_last_of(self, needle: slice&) -> usize?find_first_not_of
Finds first character not in needle
find_first_not_of(self, needle: slice&) -> usize?find_last_not_of
Finds last character not in needle
find_last_not_of(self, needle: slice&) -> usize?