pub struct StringTable {
pub count: u32,
pub epoch: u64,
/* private fields */
}Expand description
interned strings of an arena
Fields§
§count: u32number of strings
epoch: u64identity of the ids: changed when the ids change (see StringTable::compact)
Implementations§
Source§impl StringTable
impl StringTable
pub fn new() -> Self
Sourcepub fn set_text(&mut self, source: usize, codes: CodeUnits)
pub fn set_text(&mut self, source: usize, codes: CodeUnits)
set the code units of a source: the strings of the source are ranges of it. the buffer is shared, not copied
Sourcepub fn release_codes(&mut self, _source: usize)
pub fn release_codes(&mut self, _source: usize)
kept for parity with typescript: the code units are the text, there is nothing to release
intern a shared string, without copying it
intern a shared string: a shared Rc<str> is kept as is, a range of a source is copied
pub fn intern_rc(&mut self, str: &Rc<str>) -> u32
Sourcepub fn intern_units(&mut self, codes: &[u16]) -> u32
pub fn intern_units(&mut self, codes: &[u16]) -> u32
intern utf-16 code units (copied to the pool when they are not interned yet)
Sourcepub fn intern_range(
&mut self,
codes: &CodeUnits,
start: usize,
end: usize,
source: i32,
) -> u32
pub fn intern_range( &mut self, codes: &CodeUnits, start: usize, end: usize, source: i32, ) -> u32
intern a range of the code units of a source (source >= 0, the range is kept) or of the canonical text
(StringSource::Canonical, codes is the canonical text). use StringTable::intern_units for the pool
Sourcepub fn intern_canonical(&mut self, start: u32, end: u32) -> u32
pub fn intern_canonical(&mut self, start: u32, end: u32) -> u32
intern a range of the canonical text
Sourcepub fn get(&mut self, id: u32) -> SharedStr
pub fn get(&mut self, id: u32) -> SharedStr
the string of an id. the string is created the first time it is read
Sourcepub fn with_str<R>(&self, id: u32, f: impl FnOnce(&str) -> R) -> R
pub fn with_str<R>(&self, id: u32, f: impl FnOnce(&str) -> R) -> R
run a function with the string of an id, without creating it when it is an ascii range of a source
Sourcepub fn with_units<R>(&self, id: u32, f: impl FnOnce(Units<'_>) -> R) -> R
pub fn with_units<R>(&self, id: u32, f: impl FnOnce(Units<'_>) -> R) -> R
the code units of a string, borrowed from where they are stored (the source text, the pool, the canonical text, the value): no copy
Sourcepub fn copy_into(&self, id: u32, target: &mut Vec<u16>) -> usize
pub fn copy_into(&self, id: u32, target: &mut Vec<u16>) -> usize
append the code units of a string to a buffer. the string is not created
Sourcepub fn flag(
&mut self,
id: u32,
flag: StringFlag,
compute: impl FnOnce(&str) -> bool,
) -> bool
pub fn flag( &mut self, id: u32, flag: StringFlag, compute: impl FnOnce(&str) -> bool, ) -> bool
a boolean property of a string, computed once per id from the string
Sourcepub fn cached(&self, id: u32) -> Option<SharedStr>
pub fn cached(&self, id: u32) -> Option<SharedStr>
the string of an id when it has been created (cache[id])
Sourcepub fn cached_flag(&self, id: u32, flag: StringFlag) -> Option<bool>
pub fn cached_flag(&self, id: u32, flag: StringFlag) -> Option<bool>
cached value of a flag, if it is computed
Sourcepub fn set_flag(&mut self, id: u32, flag: StringFlag, value: bool)
pub fn set_flag(&mut self, id: u32, flag: StringFlag, value: bool)
store the value of a flag
Sourcepub fn derived<T: Clone + 'static>(
&self,
id: u32,
slot: StringDerived,
) -> Option<T>
pub fn derived<T: Clone + 'static>( &self, id: u32, slot: StringDerived, ) -> Option<T>
a value derived from a string, if it is computed
Sourcepub fn set_derived<T: 'static>(
&mut self,
id: u32,
slot: StringDerived,
value: T,
)
pub fn set_derived<T: 'static>( &mut self, id: u32, slot: StringDerived, value: T, )
store a value derived from a string
Sourcepub fn copy_ascii(&self, id: u32, target: &mut Vec<u8>) -> isize
pub fn copy_ascii(&self, id: u32, target: &mut Vec<u8>) -> isize
append the bytes of a string to a buffer when it is ascii. returns the number of bytes, -1 when the string is not ascii (nothing is appended)
Sourcepub fn index_of_code(&self, id: u32, code: u32) -> isize
pub fn index_of_code(&self, id: u32, code: u32) -> isize
index of the first occurrence of a code unit, -1 when it is not found
Sourcepub fn equals(&self, id: u32, str: &str) -> bool
pub fn equals(&self, id: u32, str: &str) -> bool
true if the string of an id equals a string. the string is not created
Sourcepub fn lower(&mut self, id: u32) -> u32
pub fn lower(&mut self, id: u32) -> u32
id of the lowercase string: the id itself when the string has no uppercase letter
Sourcepub fn starts_with(&self, id: u32, str: &str) -> bool
pub fn starts_with(&self, id: u32, str: &str) -> bool
true if the string of an id starts with a string
Sourcepub fn equals_ignore_case(&self, id: u32, str: &str) -> bool
pub fn equals_ignore_case(&self, id: u32, str: &str) -> bool
true if the string of an id equals a string, ignoring the case of the ascii letters
Sourcepub fn compact(&mut self, used: &[u8]) -> Vec<u32>
pub fn compact(&mut self, used: &[u8]) -> Vec<u32>
drop the strings that are not used and renumber the others. returns the new id of each string
Sourcepub fn export(&self) -> StringTableData
pub fn export(&self) -> StringTableData
copy of the table
Sourcepub fn import(&mut self, data: &StringTableData)
pub fn import(&mut self, data: &StringTableData)
initialize the table from an exported copy