Skip to content

std::String::basic<Char, Traits>

basic<Char, Traits>

Represents a basic string type with specified character type and traits, similar to std::basic_string in C++

Template Parameters

  • Char
  • Traits

Type Aliases

  • char_traits = Traits
  • char_t = CharT
  • size_t = usize
  • string_t = libcxx::basic_string<CharT, Traits>
  • slice_t = slice
  • slice_vec = vec<slice_t>
  • char_vec = vec<CharT>

Constructors

basic

Default constructor

basic() noexcept

basic

Copy constructor

basic(const basic& other) noexcept

basic

Move constructor

basic(basic&& other) noexcept

basic

Constructor from C++ string

basic(const libcxx::basic_string<CharT, Traits>& str) noexcept

basic

Constructor from C-style string

basic(const CharT* str) noexcept

basic

Constructor with character repeated count times

basic(const CharT chr, size_t count) noexcept

basic

Constructor from C-style string with length

basic(const CharT* str, size_t len) noexcept

basic

Constructor from string slice

basic(const slice_t& s) noexcept

Operators

operator=

Copy assignment operator

op =(self, const basic& other) -> &basic

operator=

Move assignment operator

op =(self, basic&& other) -> &basic

operator=

Assignment from C-style string

op =(self, const CharT* str) -> &basic

operator[]

Access character at index (mutable)

op [``](self, index: size_t) -> &CharT

operator[]

Access character at index (const)

op [``](self, index: size_t) -> const &CharT

operator+=

Append another string

op +=(self, const basic& other) -> &basic

operator+=

Append C-style string

op +=(self, const CharT* str) -> &basic

operator+=

Append character

op +=(self, const U chr) -> &basic

operator+

Concatenate with another string

op +(self, const basic& other) -> basic

operator+

Concatenate with C-style string

op +(self, const CharT* str) -> basic

operator+

Concatenate with character

op +(self, const U chr) -> basic

operator==

Equality comparison

op ==(self, const basic& other) -> bool

operator!=

Inequality comparison

op !=(self, const basic& other) -> bool

operator<

Less than comparison

op <(self, const basic& other) -> bool

operator>

Greater than comparison

op >(self, const basic& other) -> bool

operator<=

Less than or equal comparison

op <=(self, const basic& other) -> bool

operator>=

Greater than or equal comparison

op >=(self, const basic& other) -> bool

operator slice_t

Conversion to slice

op slice_t(self) -> slice_t

operator as

Cast to slice

op as(self, const slice_t*) -> slice_t

operator as

Cast to C-style string

op as(self, const char_t*) -> const char_t*

operator in

Contains operator for slice

op in(self, needle: slice) -> bool

operator in

Contains operator for character

op in(self, chr: CharT) -> bool

Methods

push_back

Appends a character to the end of the string

push_back(self, c: CharT) -> void

append

Appends another string

append(self, const basic& other) -> void

append

Appends C-style string with length

append(self, const CharT* str, len: size_t) -> void

append

Appends string slice

append(self, const slice_t& s) -> void

clear

Clears the string content

clear(self) -> void

replace

Replaces portion of string with another slice

replace(self, pos: size_t, len: size_t, const slice_t& other) -> void

reserve

Reserves capacity for the string

reserve(self, new_cap: size_t) -> void

resize

Resizes the string to new size

resize(self, new_size: size_t, c: CharT = CharT()) -> void

empty

Checks if string is empty

empty(self) -> bool

raw

Returns raw C-style string pointer

raw(self) -> const CharT*

size

Returns the size of the string

size(self) -> size_t

length

Returns the length of the string

length(self) -> size_t

is_empty

Checks if string is empty

is_empty(self) -> bool

raw_string

Returns reference to underlying C++ string

raw_string(self) -> &string_t

subslice

Returns a substring

subslice(self, pos: size_t, len: size_t) -> basic

l_strip

Strips whitespace from the left

l_strip(self, const char_vec& delim = {' ', '\t', '\n', '\r'}) -> basic

r_strip

Strips whitespace from the right

r_strip(self, const char_vec& delim = {' ', '\t', '\n', '\r'}) -> basic

strip

Strips whitespace from both ends

strip(self, const char_vec& delim = {' ', '\t', '\n', '\r'}) -> basic

split

Splits string by delimiter

split(self, const basic& delim, op: slice_t::Operation = slice_t::Operation::Remove) -> vec<basic>

split_lines

Splits string by newlines

split_lines(self) -> vec<basic>

starts_with

Checks if string starts with needle

starts_with(self, const basic& needle) -> bool

starts_with

Checks if string starts with character

starts_with(self, c: CharT) -> bool

starts_with

Checks if string starts with slice

starts_with(self, needle: slice) -> bool

ends_with

Checks if string ends with needle

ends_with(self, const basic& needle) -> bool

ends_with

Checks if string ends with character

ends_with(self, c: CharT) -> bool

ends_with

Checks if string ends with slice

ends_with(self, needle: slice) -> bool

contains

Checks if string contains needle

contains(self, const basic& needle) -> bool

contains

Checks if string contains character

contains(self, c: CharT) -> bool

lfind

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?