Struct kerbalobjects::ko::sections::StringTable
source · pub struct StringTable { /* private fields */ }
Expand description
A string table section in a KerbalObject file.
A module describing a string table section in a Kerbal Object file. This section stores a list of strings, which other Kerbal Object constructs can index into.
Each section contains as its first index (index 0) an empty string.
Implementations§
source§impl StringTable
impl StringTable
sourcepub fn new(section_index: SectionIdx) -> Self
pub fn new(section_index: SectionIdx) -> Self
Creates a new string table section with the provided section index
sourcepub fn with_capacity(amount: usize, section_index: SectionIdx) -> Self
pub fn with_capacity(amount: usize, section_index: SectionIdx) -> Self
Creates a new string table section with the provided section index, with internal data structures pre-allocated for the provided number of strings, +1 for the null string at index 0.
sourcepub fn get(&self, index: StringIdx) -> Option<&String>
pub fn get(&self, index: StringIdx) -> Option<&String>
Gets the string at the index into this string table, or None if it doesn’t exist
sourcepub fn position(&self, s: impl AsRef<str>) -> Option<StringIdx>
pub fn position(&self, s: impl AsRef<str>) -> Option<StringIdx>
Locates a given string in this string table and returns the index if it does exist, or None if it doesn’t
sourcepub fn strings(&self) -> Iter<'_, String>
pub fn strings(&self) -> Iter<'_, String>
Returns an iterator over all of the strings contained in this string table
sourcepub fn add_checked(&mut self, new_str: impl Into<String>) -> StringIdx
pub fn add_checked(&mut self, new_str: impl Into<String>) -> StringIdx
Adds a string to this string table, but checks if it is already in this table. Returns the index of the string, if it already existed, the index is just found and returned. If it doesn’t, it is inserted and the new index is returned.
sourcepub fn add(&mut self, new_str: impl Into<String>) -> StringIdx
pub fn add(&mut self, new_str: impl Into<String>) -> StringIdx
Unconditionally adds a string to this string table and returns the index of it
sourcepub fn section_index(&self) -> SectionIdx
pub fn section_index(&self) -> SectionIdx
The index of this section’s section header
sourcepub fn parse(
source: &mut BufferIterator<'_>,
size: u32,
section_index: SectionIdx
) -> Result<Self, StringTableParseError>
pub fn parse( source: &mut BufferIterator<'_>, size: u32, section_index: SectionIdx ) -> Result<Self, StringTableParseError>
Parses a StringTable using the provided buffer, its expected size, and the section’s section index
sourcepub fn write(&self, buf: &mut impl WritableBuffer)
pub fn write(&self, buf: &mut impl WritableBuffer)
Writes the binary representation of this string table to the provided buffer