use of io.airlift.slice.SliceUtf8.offsetOfCodePoint in project presto by prestodb.
the class RcFileDecoderUtils method calculateTruncationLength.
private static int calculateTruncationLength(int maxCharacterCount, Slice slice, int offset, int length) {
requireNonNull(slice, "slice is null");
if (maxCharacterCount < 0) {
throw new IllegalArgumentException("Max length must be greater or equal than zero");
}
if (length <= maxCharacterCount) {
return length;
}
int indexEnd = offsetOfCodePoint(slice, offset, maxCharacterCount);
if (indexEnd < 0) {
return length;
}
return indexEnd - offset;
}
use of io.airlift.slice.SliceUtf8.offsetOfCodePoint in project presto by prestodb.
the class Varchars method truncateToLength.
public static Slice truncateToLength(Slice slice, int maxLength) {
requireNonNull(slice, "slice is null");
if (maxLength < 0) {
throw new IllegalArgumentException("Max length must be greater or equal than zero");
}
if (maxLength == 0) {
return Slices.EMPTY_SLICE;
}
// min codepoint size is 1 byte.
// if size in bytes is less than the max length
// we don't need to decode codepoints
int sizeInBytes = slice.length();
if (sizeInBytes <= maxLength) {
return slice;
}
int indexEnd = offsetOfCodePoint(slice, maxLength);
if (indexEnd < 0) {
return slice;
}
return slice.slice(0, indexEnd);
}
Aggregations