pub struct TwoDA {
pub file_type: FixedSizeString<4>,
pub file_version: FixedSizeString<4>,
pub default_value: Option<String>,
/* private fields */
}Expand description
2DA table file
Fields§
§file_type: FixedSizeString<4>File type (2DA)
file_version: FixedSizeString<4>File version
default_value: Option<String>Implementations§
Source§impl TwoDA
impl TwoDA
Sourcepub fn from_str(
input: &str,
repair: bool,
) -> IResult<&str, Self, VerboseError<&str>>
pub fn from_str( input: &str, repair: bool, ) -> IResult<&str, Self, VerboseError<&str>>
Parse 2DA data an input str
§Args:
- input: data to parse
- repair: true to repair inconsistent 2DA data (bad column count, row indices, …)
Sourcepub fn to_string(&self, compact: bool) -> String
pub fn to_string(&self, compact: bool) -> String
Serializes the 2DA table
§Args:
- compact: true will generate minified 2DA data. NWN2 will be able to parse this table, but this parser will require repair=true to be set when parsing
Sourcepub fn get_columns(&self) -> &Vec<String>
pub fn get_columns(&self) -> &Vec<String>
Returns the columns list
Sourcepub fn resize_rows(&mut self, len: usize)
pub fn resize_rows(&mut self, len: usize)
Resize the 2DA table to be able to contain len rows
Sourcepub fn get_row(&self, row: usize) -> Option<&[Option<String>]>
pub fn get_row(&self, row: usize) -> Option<&[Option<String>]>
Returns a row as a list of 2DA fields
Sourcepub fn get_row_mut(&mut self, row: usize) -> Option<&mut [Option<String>]>
pub fn get_row_mut(&mut self, row: usize) -> Option<&mut [Option<String>]>
Returns a row as a list of 2DA fields
Sourcepub fn get_row_col(&self, row: usize, column: usize) -> &Option<String>
pub fn get_row_col(&self, row: usize, column: usize) -> &Option<String>
Returns a field using its row index and column index
Sourcepub fn get_row_label(&self, row: usize, label: &str) -> &Option<String>
pub fn get_row_label(&self, row: usize, label: &str) -> &Option<String>
Returns a field using its row index and column name. Column names are case-insensitive
Sourcepub fn field_encoded_len<S: AsRef<str>>(field: &Option<S>) -> usize
pub fn field_encoded_len<S: AsRef<str>>(field: &Option<S>) -> usize
Returns the length of a 2DA field when encoded (using quotes and escape sequences when needed)
Sourcepub fn encode_field<S: AsRef<str>>(field: &Option<S>) -> String
pub fn encode_field<S: AsRef<str>>(field: &Option<S>) -> String
Encode a 2DA field, adding quotes when needed, and returns the resulting string
Sourcepub fn parse_row(
input: &str,
) -> IResult<&str, Vec<Option<String>>, VerboseError<&str>>
pub fn parse_row( input: &str, ) -> IResult<&str, Vec<Option<String>>, VerboseError<&str>>
Parses a 2DA row returning a list of fields (including the row index number)
Sourcepub fn encode_row<S: AsRef<str>>(
row_index: usize,
row_data: &[Option<S>],
column_sizes: Option<&[usize]>,
compact: bool,
) -> String
pub fn encode_row<S: AsRef<str>>( row_index: usize, row_data: &[Option<S>], column_sizes: Option<&[usize]>, compact: bool, ) -> String
Serializes a row to string
§Args:
- row_index: Row index number
- row_data: List of row fields (without the row index)
- column_sizes: If Some, the sizes will be used for padding the different fields, to align multiple columns together
- compact: true to minify the row by removing empty trailing fields. Note: column_sizes is used even if compact is true
Sourcepub fn encode_rows<S1: AsRef<str>, S2: AsRef<str>>(
rows: &[(usize, &[Option<S1>])],
columns: Option<&[S2]>,
compact: bool,
) -> String
pub fn encode_rows<S1: AsRef<str>, S2: AsRef<str>>( rows: &[(usize, &[Option<S1>])], columns: Option<&[S2]>, compact: bool, ) -> String
Serializes a list of row to string
§Args:
- rows: List of tuples containing the row index + fields list
- columns: If Some, adds the columns list atop if the rows
- compact: true to minify the output by not aligning columns and removing trailing empty fields
Sourcepub fn get_row_merge_actions(&self, row_index: usize) -> Option<&[MergeAction]>
pub fn get_row_merge_actions(&self, row_index: usize) -> Option<&[MergeAction]>
Returns the merge mask for the given row, if set. Only useful if it was parsed as a 2DAM file