Skip to main content

JSStrBuilder

Struct JSStrBuilder 

Source
pub struct JSStrBuilder<'a> { /* private fields */ }
Expand description

Build a JSStr in an arena, preserving lone surrogates.

Appends concatenated UTF-16 values. A leading surrogate at the end of one append pairs with a trailing surrogate at the start of the next, including across empty appends. into_js_str returns canonical WTF-8 without copying the completed buffer.

use oxc_str::JSStrBuilder;

let mut builder = JSStrBuilder::new_in(&&allocator);
builder.push_code_unit(0xD800);
builder.push_str("");
builder.push_code_unit(0xDC00);
let s = builder.into_js_str();

assert_eq!(s.as_str(), Some("๐€€"));

Implementationsยง

Sourceยง

impl<'a> JSStrBuilder<'a>

Source

pub fn new_in(allocator: &impl GetAllocator<'a>) -> Self

Create an empty JSStrBuilder without allocating.

Source

pub fn with_capacity_in( capacity: usize, allocator: &impl GetAllocator<'a>, ) -> Self

Create an empty JSStrBuilder with reserved capacity.

If capacity is 0, does not allocate.

ยงPanics

Panics if capacity exceeds u32::MAX or isize::MAX.

Source

pub fn push_str(&mut self, value: &str)

Append a &str.

Source

pub fn push(&mut self, value: char)

Append a Unicode scalar value.

Source

pub fn push_js_char(&mut self, value: JSChar)

Append one JavaScript code point, pairing surrogates at the boundary.

Source

pub fn push_code_unit(&mut self, unit: u16)

Append one UTF-16 code unit.

Use this for input from a UTF-16 API. Use push_js_char for an already decoded JavaScript code point.

Source

pub fn push_utf16(&mut self, units: &[u16])

Append potentially ill-formed UTF-16.

This accepts code-unit buffers from UTF-16 APIs without replacing lone surrogates. A pair may span consecutive calls, including empty buffers.

Source

pub fn push_code_units(&mut self, units: impl IntoIterator<Item = u16>)

Append potentially ill-formed UTF-16 code units from an iterator, like push_utf16.

Source

pub fn push_js_str(&mut self, value: JSStr<'_>)

Append a JavaScript string, repairing a surrogate pair at the boundary.

UTF-8 inputs are copied without scanning. For inputs with lone surrogates, only the boundary encodings change; the interior is copied as bytes.

Source

pub fn into_js_str(self) -> JSStr<'a>

Consume the builder and return a string without copying or rescanning the buffer.

Auto Trait Implementationsยง

ยง

impl<'a> !RefUnwindSafe for JSStrBuilder<'a>

ยง

impl<'a> !Send for JSStrBuilder<'a>

ยง

impl<'a> !UnwindSafe for JSStrBuilder<'a>

ยง

impl<'a> Freeze for JSStrBuilder<'a>

ยง

impl<'a> Sync for JSStrBuilder<'a>

ยง

impl<'a> Unpin for JSStrBuilder<'a>

ยง

impl<'a> UnsafeUnpin for JSStrBuilder<'a>

Blanket Implementationsยง

Sourceยง

impl<T> Any for T
where T: 'static + ?Sized,

Sourceยง

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Sourceยง

impl<T> Borrow<T> for T
where T: ?Sized,

Sourceยง

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Sourceยง

impl<T> BorrowMut<T> for T
where T: ?Sized,

Sourceยง

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Sourceยง

impl<T> From<T> for T

Sourceยง

fn from(t: T) -> T

Returns the argument unchanged.

Sourceยง

impl<'a, T> FromIn<'a, T> for T

Sourceยง

fn from_in(t: T, _: &'a Allocator) -> T

Converts to this type from the input type within the given allocator.
Sourceยง

impl<T, U> Into<U> for T
where U: From<T>,

Sourceยง

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Sourceยง

impl<'a, T, U> IntoIn<'a, U> for T
where U: FromIn<'a, T>,

Sourceยง

fn into_in(self, allocator: &'a Allocator) -> U

Converts this type into the (usually inferred) input type within the given allocator.
Sourceยง

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Sourceยง

type Error = !

The type returned in the event of a conversion error.
Sourceยง

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Sourceยง

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Sourceยง

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Sourceยง

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.