···11-import { getUtf8Length } from '@atcute/uint8array';
22-import { getGraphemeLength } from '@atcute/util-text';
11+import { isUtf8LengthInRange } from '@atcute/uint8array';
22+import { isGraphemeLengthInRange } from '@atcute/util-text';
3344import type { StandardSchemaV1 } from '@standard-schema/spec';
55···817817 minLength: minLength,
818818 maxLength: maxLength,
819819 '~run'(input, _flags) {
820820- // UTF-8 conversion can be expensive, so we're going to do some safe naive
821821- // checks where we assume an upper-bound of the UTF-16 to UTF-8 conversion
822822-823823- const utf16Len = input.length;
824824- const maybeUtf8Len = utf16Len * 3;
825825-826826- // fail early if estimated upper bound is too small
827827- if (maybeUtf8Len < minLength) {
828828- return issue;
829829- }
830830-831831- // skip calculation if UTF-16 length already satisfies both constraints
832832- if (utf16Len >= minLength && maybeUtf8Len <= maxLength) {
833833- return undefined;
834834- }
835835-836836- const utf8Len = getUtf8Length(input);
837837-838838- if (utf8Len < minLength) {
839839- return issue;
840840- }
841841-842842- if (utf8Len > maxLength) {
820820+ if (!isUtf8LengthInRange(input, minLength, maxLength)) {
843821 return issue;
844822 }
845823···881859 minGraphemes: minGraphemes,
882860 maxGraphemes: maxGraphemes,
883861 '~run'(input, _flags) {
884884- // grapheme conversion is expensive, so we're going to do some safe naive
885885- // checks where we assume 1 UTF-16 character = 1 grapheme.
886886-887887- const utf16Len = input.length;
888888-889889- // fail early if UTF-16 length is too small
890890- if (utf16Len < minGraphemes) {
891891- return issue;
892892- }
893893-894894- // if there is no minimum bounds, we can safely skip when UTF-16 is
895895- // within the maximum bounds.
896896- if (minGraphemes === 0 && utf16Len <= maxGraphemes) {
897897- return undefined;
898898- }
899899-900900- const graphemeLen = getGraphemeLength(input);
901901-902902- if (graphemeLen < minGraphemes) {
903903- return issue;
904904- }
905905-906906- if (graphemeLen > maxGraphemes) {
862862+ if (!isGraphemeLengthInRange(input, minGraphemes, maxGraphemes)) {
907863 return issue;
908864 }
909865