Skip to content

fix type conversions for isFinalSigma #1173

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 15, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions std/assembly/util/string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ export function isCaseIgnorable(c: u32): bool {

// @ts-ignore: decorator
@inline
export function isFinalSigma(buffer: usize, index: i32, len: i32): bool {
export function isFinalSigma(buffer: usize, index: isize, len: isize): bool {
const lookaheadLimit = 30; // max lookahead limit
var found = false;
var pos = index;
Expand All @@ -565,34 +565,34 @@ export function isFinalSigma(buffer: usize, index: i32, len: i32): bool {
return false;
}
}
pos -= i32(c >= 0x10000) + 1;
pos -= isize(c >= 0x10000) + 1;
}
if (!found) return false;
pos = index + 1;
var maxPos = min(pos + lookaheadLimit, len);
while (pos < maxPos) {
let c = <u32>load<u16>(buffer + (<usize>pos << 1));
let c = <u32>load<u16>(buffer + (pos << 1));
if (u32((c & 0xFC00) == 0xD800) & u32(pos + 1 != len)) {
let c1 = <u32>load<u16>(buffer + (<usize>pos << 1), 2);
let c1 = <u32>load<u16>(buffer + (pos << 1), 2);
if ((c1 & 0xFC00) == 0xDC00) {
c = (c - 0xD800 << 10) + (c1 - 0xDC00) + 0x10000;
}
}
if (!isCaseIgnorable(c)) {
return !isCased(c);
}
pos += i32(c >= 0x10000) + 1;
pos += isize(c >= 0x10000) + 1;
}
return true;
}

// @ts-ignore: decorator
@inline
function codePointBefore(buffer: usize, index: i32): i32 {
function codePointBefore(buffer: usize, index: isize): i32 {
if (index <= 0) return -1;
var c = <u32>load<u16>(buffer + (<usize>index - 1 << 1));
var c = <u32>load<u16>(buffer + (index - 1 << 1));
if (u32((c & 0xFC00) == 0xDC00) & u32(index - 2 >= 0)) {
let c1 = <u32>load<u16>(buffer + (<usize>index - 2 << 1));
let c1 = <u32>load<u16>(buffer + (index - 2 << 1));
if ((c1 & 0xFC00) == 0xD800) {
return ((c1 & 0x3FF) << 10) + (c & 0x3FF) + 0x10000;
}
Expand Down