Skip to content

Commit 267cc51

Browse files
committed
fix: move len 20 check up and remove basicLatin boolean
1 parent 3e609bf commit 267cc51

File tree

1 file changed

+11
-15
lines changed

1 file changed

+11
-15
lines changed

src/utils/latin.ts

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ export function tryLatin(uint8array: Uint8Array, start: number, end: number): st
2323
return '';
2424
}
2525

26+
if (stringByteLength > 20) {
27+
return null;
28+
}
29+
2630
if (stringByteLength === 1 && uint8array[start] < 128) {
2731
return String.fromCharCode(uint8array[start]);
2832
}
@@ -44,22 +48,14 @@ export function tryLatin(uint8array: Uint8Array, start: number, end: number): st
4448
);
4549
}
4650

47-
if (stringByteLength <= 20) {
48-
let basicLatin = true;
49-
const latinBytes = [];
50-
for (let i = start; i < end; i++) {
51-
const byte = uint8array[i];
52-
if (byte > 127) {
53-
basicLatin = false;
54-
break;
55-
}
56-
latinBytes.push(byte);
57-
}
58-
59-
if (basicLatin) {
60-
return String.fromCharCode(...latinBytes);
51+
const latinBytes = [];
52+
for (let i = start; i < end; i++) {
53+
const byte = uint8array[i];
54+
if (byte > 127) {
55+
return null;
6156
}
57+
latinBytes.push(byte);
6258
}
6359

64-
return null;
60+
return String.fromCharCode(...latinBytes);
6561
}

0 commit comments

Comments
 (0)