`val` - string `start` - the start char index of the substring `length` - the char length of the substring Return the `start` and `end` offset (by byte) of the substring
(val: &str, start: usize, length: Option<usize>)
| 232 | /// |
| 233 | /// Return the `start` and `end` offset (by byte) of the substring |
| 234 | fn get_start_end_offset(val: &str, start: usize, length: Option<usize>) -> (usize, usize) { |
| 235 | let len = val.len(); |
| 236 | let mut offset_char_iter = val.char_indices(); |
| 237 | let start_offset = offset_char_iter |
| 238 | .nth(start) |
| 239 | .map_or(len, |(offset, _)| offset); |
| 240 | let end_offset = length.map_or(len, |length| { |
| 241 | if length > 0 { |
| 242 | offset_char_iter |
| 243 | .nth(length - 1) |
| 244 | .map_or(len, |(offset, _)| offset) |
| 245 | } else { |
| 246 | start_offset |
| 247 | } |
| 248 | }); |
| 249 | (start_offset, end_offset) |
| 250 | } |
| 251 | |
| 252 | fn byte_substring<T: ByteArrayType>( |
| 253 | array: &GenericByteArray<T>, |
no test coverage detected