MCPcopy Create free account
hub / github.com/apache/arrow-rs / get_start_end_offset

Function get_start_end_offset

arrow-string/src/substring.rs:234–250  ·  view source on GitHub ↗

`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>)

Source from the content-addressed store, hash-verified

232///
233/// Return the `start` and `end` offset (by byte) of the substring
234fn 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
252fn byte_substring<T: ByteArrayType>(
253 array: &GenericByteArray<T>,

Callers 1

substring_by_charFunction · 0.85

Calls 2

lenMethod · 0.45
nthMethod · 0.45

Tested by

no test coverage detected