mirror of
https://github.com/morluto/rea.git
synced 2026-12-05 14:31:22 +00:00
refactor(sqlite): reuse text decoding for ASCII identifiers (#16848)
This commit is contained in:
1 parent
218ae34dca
commit
d2342c949d
1 file changed
+2
-23
@@ -360,29 +360,8 @@ const asciiLower = (
|
||||
bytes: Uint8Array,
|
||||
encoding: DatabaseEncoding,
|
||||
): string | undefined => {
|
||||
if (encoding === "UTF-8") {
|
||||
let text = "";
|
||||
for (const byte of bytes) {
|
||||
if (byte >= 0x80) return undefined;
|
||||
text += String.fromCharCode(
|
||||
byte >= 0x41 && byte <= 0x5a ? byte + 0x20 : byte,
|
||||
);
|
||||
}
|
||||
return text;
|
||||
}
|
||||
if (bytes.length % 2 !== 0) return undefined;
|
||||
const lowFirst = encoding === "UTF-16le";
|
||||
let text = "";
|
||||
for (let index = 0; index < bytes.length; index += 2) {
|
||||
const unit = lowFirst
|
||||
? bytes[index]! | (bytes[index + 1]! << 8)
|
||||
: (bytes[index]! << 8) | bytes[index + 1]!;
|
||||
if (unit >= 0x80) return undefined;
|
||||
text += String.fromCharCode(
|
||||
unit >= 0x41 && unit <= 0x5a ? unit + 0x20 : unit,
|
||||
);
|
||||
}
|
||||
return text;
|
||||
const text = LENIENT_TEXT_DECODERS[encoding].decode(bytes);
|
||||
return /\P{ASCII}/u.test(text) ? undefined : text.toLowerCase();
|
||||
};
|
||||
|
||||
const readPrimaryKeyIndexName = (
|
||||
|
||||
Reference in new issue
Block a user