Trait substring_replace::SubstringReplace
source · pub trait SubstringReplace {
// Required methods
fn substring(&self, start: usize, end: usize) -> &str;
fn substring_replace(
&self,
replacement: &str,
start: usize,
end: usize,
) -> String;
fn to_start_byte_index(&self, start: usize) -> usize;
fn to_end_byte_index(&self, start: usize) -> usize;
fn char_len(&self) -> usize;
// Provided methods
fn substring_start(&self, end: usize) -> &str { ... }
fn substring_end(&self, start: usize) -> &str { ... }
fn substring_replace_start(&self, replacement: &str, end: usize) -> String { ... }
fn substring_replace_end(&self, replacement: &str, start: usize) -> String { ... }
fn substring_offset(&self, position: usize, length: i32) -> &str { ... }
fn substring_insert(&self, replacement: &str, start: usize) -> String { ... }
}
Required Methods§
sourcefn substring(&self, start: usize, end: usize) -> &str
fn substring(&self, start: usize, end: usize) -> &str
Return a substring by start and end character index With multibyte characters this will not be the same as the byte indices used by str slices
fn substring_replace( &self, replacement: &str, start: usize, end: usize, ) -> String
sourcefn to_start_byte_index(&self, start: usize) -> usize
fn to_start_byte_index(&self, start: usize) -> usize
Convert character index to start byte index
sourcefn to_end_byte_index(&self, start: usize) -> usize
fn to_end_byte_index(&self, start: usize) -> usize
Convert character index to end byte index
Provided Methods§
sourcefn substring_start(&self, end: usize) -> &str
fn substring_start(&self, end: usize) -> &str
Return a substring from the start and to a specified end character index
sourcefn substring_end(&self, start: usize) -> &str
fn substring_end(&self, start: usize) -> &str
Return a substring from a specified start character index to a specified end If start index is greater than the max character index, the function will yield an empty string
sourcefn substring_replace_start(&self, replacement: &str, end: usize) -> String
fn substring_replace_start(&self, replacement: &str, end: usize) -> String
Replace the start of a string to specified end character index e.g. “brown”.substring_replace_start(“d”, 2); will replace the first two characters with “d”, yield “down”
sourcefn substring_replace_end(&self, replacement: &str, start: usize) -> String
fn substring_replace_end(&self, replacement: &str, start: usize) -> String
Replace the remainder of string from a specified start character index e.g. “blue”.substring_replace_last(“ack”, 2); will replace the last 2 characters with “ack”, yielding “black”
sourcefn substring_offset(&self, position: usize, length: i32) -> &str
fn substring_offset(&self, position: usize, length: i32) -> &str
Extract a substring from a start index for n characters to the right A negative length in the second parameter will start at the start index
sourcefn substring_insert(&self, replacement: &str, start: usize) -> String
fn substring_insert(&self, replacement: &str, start: usize) -> String
Insert a string at a given character index This differs from String::insert by using character rather than byte indices to work better with multibyte characters It also works directly with &str, while returning a new owned string
Implementations on Foreign Types§
source§impl SubstringReplace for str
impl SubstringReplace for str
source§fn substring(&self, start: usize, end: usize) -> &str
fn substring(&self, start: usize, end: usize) -> &str
Extract substring by character indices and hand overflow gracefully if the end index is equal or greater than start index, the function will yield an empty string
source§fn to_start_byte_index(&self, start: usize) -> usize
fn to_start_byte_index(&self, start: usize) -> usize
Translate the character start index to the start byte index to avoid boundary collisions with multibyte characters
source§fn to_end_byte_index(&self, end: usize) -> usize
fn to_end_byte_index(&self, end: usize) -> usize
Translate the character end index to the end byte index to avoid boundary collisions with multibyte characters