Skip to content

Commit 7232c34

Browse files
committed
Improve function name
1 parent 488b2bf commit 7232c34

3 files changed

Lines changed: 23 additions & 23 deletions

File tree

datafusion/functions/src/unicode/common.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -88,26 +88,26 @@ pub(crate) fn byte_offset_of_char(string: &str, n: usize) -> usize {
8888
.map_or(string.len(), |(i, _)| i)
8989
}
9090

91-
/// Measures the character length of `string` in a single pass, returning
92-
/// early with the truncation byte offset if the string exceeds `n` chars.
91+
/// If `string` has more than `n` codepoints, returns the byte offset of
92+
/// the `n`-th codepoint boundary. Otherwise returns the total codepoint count.
9393
#[inline]
94-
pub(crate) fn measure_char_count(string: &str, n: usize) -> StringCharLen {
94+
pub(crate) fn char_count_or_boundary(string: &str, n: usize) -> StringCharLen {
9595
let mut count = 0;
9696
for (byte_idx, _) in string.char_indices() {
9797
if count == n {
98-
return StringCharLen::TruncateAt(byte_idx);
98+
return StringCharLen::ByteOffset(byte_idx);
9999
}
100100
count += 1;
101101
}
102102
StringCharLen::CharCount(count)
103103
}
104104

105-
/// Result of [`measure_char_count`].
105+
/// Result of [`char_count_or_boundary`].
106106
pub(crate) enum StringCharLen {
107-
/// The string has more than `n` chars; contains the byte offset at the
108-
/// `n`-th character boundary (suitable for slicing `&string[..offset]`).
109-
TruncateAt(usize),
110-
/// The string has `n` or fewer chars; contains the exact character count.
107+
/// The string has more than `n` codepoints; contains the byte offset
108+
/// at the `n`-th codepoint boundary.
109+
ByteOffset(usize),
110+
/// The string has `n` or fewer codepoints; contains the exact count.
111111
CharCount(usize),
112112
}
113113

datafusion/functions/src/unicode/lpad.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ impl ScalarUDFImpl for LPadFunc {
178178
}
179179

180180
use super::common::{
181-
StringCharLen, measure_char_count, try_as_scalar_i64, try_as_scalar_str,
181+
StringCharLen, char_count_or_boundary, try_as_scalar_i64, try_as_scalar_str,
182182
};
183183

184184
/// Optimized lpad for constant target_len and fill arguments.
@@ -275,8 +275,8 @@ fn lpad_scalar_unicode<'a, V: StringArrayType<'a> + Copy, T: OffsetSizeTrait>(
275275
for maybe_string in string_array.iter() {
276276
match maybe_string {
277277
Some(string) => {
278-
match measure_char_count(string, target_len) {
279-
StringCharLen::TruncateAt(offset) => {
278+
match char_count_or_boundary(string, target_len) {
279+
StringCharLen::ByteOffset(offset) => {
280280
builder.append_value(&string[..offset]);
281281
}
282282
StringCharLen::CharCount(char_count) => {
@@ -427,8 +427,8 @@ where
427427
fill_chars_buf.clear();
428428
fill_chars_buf.extend(fill.chars());
429429

430-
match measure_char_count(string, target_len) {
431-
StringCharLen::TruncateAt(offset) => {
430+
match char_count_or_boundary(string, target_len) {
431+
StringCharLen::ByteOffset(offset) => {
432432
builder.append_value(&string[..offset]);
433433
}
434434
StringCharLen::CharCount(char_count) => {
@@ -484,8 +484,8 @@ where
484484
builder.append_value(string);
485485
}
486486
} else {
487-
match measure_char_count(string, target_len) {
488-
StringCharLen::TruncateAt(offset) => {
487+
match char_count_or_boundary(string, target_len) {
488+
StringCharLen::ByteOffset(offset) => {
489489
builder.append_value(&string[..offset]);
490490
}
491491
StringCharLen::CharCount(char_count) => {

datafusion/functions/src/unicode/rpad.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ impl ScalarUDFImpl for RPadFunc {
178178
}
179179

180180
use super::common::{
181-
StringCharLen, measure_char_count, try_as_scalar_i64, try_as_scalar_str,
181+
StringCharLen, char_count_or_boundary, try_as_scalar_i64, try_as_scalar_str,
182182
};
183183

184184
/// Optimized rpad for constant target_len and fill arguments.
@@ -276,8 +276,8 @@ fn rpad_scalar_unicode<'a, V: StringArrayType<'a> + Copy, T: OffsetSizeTrait>(
276276
for maybe_string in string_array.iter() {
277277
match maybe_string {
278278
Some(string) => {
279-
match measure_char_count(string, target_len) {
280-
StringCharLen::TruncateAt(offset) => {
279+
match char_count_or_boundary(string, target_len) {
280+
StringCharLen::ByteOffset(offset) => {
281281
builder.append_value(&string[..offset]);
282282
}
283283
StringCharLen::CharCount(char_count) => {
@@ -427,8 +427,8 @@ where
427427
fill_chars_buf.clear();
428428
fill_chars_buf.extend(fill.chars());
429429

430-
match measure_char_count(string, target_len) {
431-
StringCharLen::TruncateAt(offset) => {
430+
match char_count_or_boundary(string, target_len) {
431+
StringCharLen::ByteOffset(offset) => {
432432
builder.append_value(&string[..offset]);
433433
}
434434
StringCharLen::CharCount(char_count) => {
@@ -486,8 +486,8 @@ where
486486
builder.append_value("");
487487
}
488488
} else {
489-
match measure_char_count(string, target_len) {
490-
StringCharLen::TruncateAt(offset) => {
489+
match char_count_or_boundary(string, target_len) {
490+
StringCharLen::ByteOffset(offset) => {
491491
builder.append_value(&string[..offset]);
492492
}
493493
StringCharLen::CharCount(char_count) => {

0 commit comments

Comments
 (0)