Skip to main content

Crate oxc_str

Crate oxc_str 

Source
Expand description

String types for oxc.

This crate provides Str, Ident, and CompactStr for UTF-8 strings, and JSStr, JSChar, and JSStrBuilder for JavaScript strings, including lone surrogates.

§Naming

Types are named for what a value means in JavaScript, as with JSStr and JSChar. Storage, encoding, and ownership stay out of public names: WTF-8 is an implementation detail, and whether a name borrows or owns its text is the type’s concern rather than the caller’s.

§Consuming JSStr

A consumer that would otherwise need str decides what a lone surrogate means for its check:

  • Comparisons with fixed names use JSStr’s PartialEq<&str> directly and need no conversion. A value with a lone surrogate never equals one.
  • Searches for fixed text, such as a prefix or a substring, use the JSStrPattern methods (JSStr::contains, JSStr::starts_with, JSStr::find, and others), which search the value without converting it.
  • User-configured patterns, such as regexes and globs, take UTF-8 text, so they match only JSStr::as_str. A value with a lone surrogate matches no pattern.
  • A value shown to a person uses JSStr::display or the Debug form, which escape the surrogate instead of replacing it.

Declining when JSStr::as_str returns None is only safe where skipping the work is conservative, as for an optional optimization or a lookup that cannot match. Code that decides whether a program is valid, whether a rewrite is safe, or what code to emit must handle the value instead of skipping it.

Macros§

format_compact_str
Creates a CompactStr using interpolation of runtime expressions.
format_ident
Creates an Ident using interpolation of runtime expressions.
format_str
Creates a Str using interpolation of runtime expressions.
static_ident
Creates an Ident<'static> for a string literal, evaluated at compile time.
static_str
Create a Str<'static> for a string literal, evaluated at compile time.

Structs§

ArenaStr
An inlinable string for oxc_allocator.
CompactStr
Lifetimeless version of Str which owns its own string data allocation.
Ident
An identifier string for oxc_allocator with a precomputed hash.
IdentBuildHasher
A BuildHasher for Ident-keyed hash maps.
IdentHasher
A Hasher that handles both Ident (precomputed) and str (computed) hash paths.
JSChar
A JavaScript string code point, including lone surrogates.
JSStr
An immutable JavaScript string borrowed from source text or arena memory.
JSStrBuilder
Build a JSStr in an arena, preserving lone surrogates.
Str
An inlinable string for oxc_allocator.

Constants§

MAX_INLINE_LEN
Maximum length for inline string, which can be created with CompactStr::new_const.

Traits§

JSStrPattern
A search pattern for JSStr: &str, char, or FnMut(char) -> bool.

Type Aliases§

ArenaIdentHashMap
Arena-allocated hash map keyed by Ident, using precomputed ident hash.
ArenaIdentHashSet
Arena-allocated hash set of Ident, using precomputed ident hash.
IdentHashMap
Hash map keyed by Ident, using precomputed ident hash.
IdentHashSet
Hash set of Ident, using precomputed ident hash.