mbutrovich commented on code in PR #4903:
URL: https://github.com/apache/datafusion-comet/pull/4903#discussion_r3590176131
##########
native/spark-expr/src/kernels/strings.rs:
##########
@@ -60,3 +57,230 @@ pub fn substring(array: &dyn Array, start: i64, length:
u64) -> Result<ArrayRef,
dt => panic!("Unsupported input type for function 'substring':
{dt:?}"),
}
}
+
+/// Byte bounds of the `length`-codepoint window starting at codepoint `start`
of an ASCII
+/// string, where one codepoint is one byte.
+#[inline]
+fn ascii_bounds(value: &str, start: i64, length: usize) -> (usize, usize) {
+ let byte_len = value.len();
+ let begin = if start >= 0 {
+ (start as usize).min(byte_len)
+ } else {
+ byte_len.saturating_sub(start.unsigned_abs() as usize)
+ };
+ (begin, begin.saturating_add(length).min(byte_len))
+}
+
+/// Byte bounds of the `length`-codepoint window starting at codepoint `start`
of an
+/// arbitrary UTF-8 string, where a negative `start` counts back from the end.
+#[inline]
Review Comment:
This feels more complex than what I'm used to seeing out of an `#[inline]`.
However, it only has one call site so I'm not terrified of code size explosion.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]