pub struct JsStr<'a> { /* private fields */ }Expand description
This is equivalent to Rust’s &str.
Implementations§
Source§impl<'a> JsStr<'a>
impl<'a> JsStr<'a>
Sourcepub const fn latin1(value: &'a [u8]) -> Self
pub const fn latin1(value: &'a [u8]) -> Self
Creates a JsStr from codepoints that can fit in a u8.
Sourcepub const fn variant(self) -> JsStrVariant<'a>
pub const fn variant(self) -> JsStrVariant<'a>
Return the inner JsStrVariant varient of the JsStr.
Sourcepub fn trim_start(self) -> Self
pub fn trim_start(self) -> Self
Trims all leading space.
Sourcepub fn get<I>(self, index: I) -> Option<I::Value>where
I: JsSliceIndex<'a>,
pub fn get<I>(self, index: I) -> Option<I::Value>where
I: JsSliceIndex<'a>,
Returns an element or subslice depending on the type of index, otherwise None.
Sourcepub fn get_expect<I>(&self, index: I) -> I::Valuewhere
I: JsSliceIndex<'a>,
pub fn get_expect<I>(&self, index: I) -> I::Valuewhere
I: JsSliceIndex<'a>,
Sourcepub unsafe fn get_unchecked<I>(self, index: I) -> I::Valuewhere
I: JsSliceIndex<'a>,
pub unsafe fn get_unchecked<I>(self, index: I) -> I::Valuewhere
I: JsSliceIndex<'a>,
Returns an element or subslice depending on the type of index, without doing bounds check.
§Safety
Caller must ensure the index is not out of bounds
Sourcepub fn starts_with(&self, needle: JsStr<'_>) -> bool
pub fn starts_with(&self, needle: JsStr<'_>) -> bool
Returns true if needle is a prefix of the JsStr.
Sourcepub fn ends_with(&self, needle: JsStr<'_>) -> bool
pub fn ends_with(&self, needle: JsStr<'_>) -> bool
Returns true if needle is a suffix of the JsStr.
Sourcepub fn index_of(
&self,
search_value: JsStr<'_>,
from_index: usize,
) -> Option<usize>
pub fn index_of( &self, search_value: JsStr<'_>, from_index: usize, ) -> Option<usize>
Sourcepub fn code_point_at(&self, position: usize) -> CodePoint
pub fn code_point_at(&self, position: usize) -> CodePoint
Abstract operation CodePointAt( string, position ).
The abstract operation CodePointAt takes arguments string (a String) and position (a
non-negative integer) and returns a Record with fields [[CodePoint]] (a code point),
[[CodeUnitCount]] (a positive integer), and [[IsUnpairedSurrogate]] (a Boolean). It
interprets string as a sequence of UTF-16 encoded code points, as described in 6.1.4, and reads
from it a single code point starting with the code unit at index position.
More information:
§Panics
If position is smaller than size of string.
Sourcepub fn code_points(&self) -> impl Iterator<Item = CodePoint> + Clone + use<'a>
pub fn code_points(&self) -> impl Iterator<Item = CodePoint> + Clone + use<'a>
Gets an iterator of all the Unicode codepoints of a JsStr.
Sourcepub fn code_points_lossy(self) -> impl Iterator<Item = char> + 'a
pub fn code_points_lossy(self) -> impl Iterator<Item = char> + 'a
Gets an iterator of all the Unicode codepoints of a JsStr, replacing
unpaired surrogates with the replacement character. This is faster than
using Self::code_points.
Sourcepub fn to_std_string_with_surrogates(
&self,
) -> impl Iterator<Item = Result<String, u16>> + use<'a>
pub fn to_std_string_with_surrogates( &self, ) -> impl Iterator<Item = Result<String, u16>> + use<'a>
Decodes a JsStr into an iterator of Result<String, u16>, returning surrogates as
errors.
Sourcepub fn to_std_string(&self) -> Result<String, FromUtf16Error>
pub fn to_std_string(&self) -> Result<String, FromUtf16Error>
Decodes a JsStr into a String, returning an error if it contains any invalid data.
§Errors
FromUtf16Error if it contains any invalid data.
Sourcepub fn to_std_string_escaped(&self) -> String
pub fn to_std_string_escaped(&self) -> String
Sourcepub fn to_std_string_lossy(&self) -> String
pub fn to_std_string_lossy(&self) -> String
Sourcepub fn display_escaped(&self) -> JsStrDisplayEscaped<'a>
pub fn display_escaped(&self) -> JsStrDisplayEscaped<'a>
Gets a displayable escaped string.
This may be faster and has fewer
allocations than format!("{}", str.to_string_escaped()) when
displaying.
Sourcepub fn display_lossy(&self) -> JsStrDisplayLossy<'a>
pub fn display_lossy(&self) -> JsStrDisplayLossy<'a>
Gets a displayable lossy string.
This may be faster and has fewer
allocations than format!("{}", str.to_string_lossy()) when displaying.