Skip to content
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

Remove getEmbedDirection() #4

Merged
merged 1 commit into from
Jul 31, 2023
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
23 changes: 12 additions & 11 deletions src/embeddingLevels.js
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,12 @@ export function getEmbeddingLevels (string, baseDirection) {
// The next steps are done per isolating run sequence
for (let seqIdx = 0; seqIdx < isolatingRunSeqs.length; seqIdx++) {
const { _seqIndices: seqIndices, _sosType: sosType, _eosType: eosType } = isolatingRunSeqs[seqIdx]
/**
* All the level runs in an isolating run sequence have the same embedding level.
*
* DO NOT change any `embedLevels[i]` within the current scope.
*/
const embedDirection = ((embedLevels[seqIndices[0]]) & 1) ? TYPE_R : TYPE_L;

// === 3.3.4 Resolving Weak Types ===

Expand Down Expand Up @@ -510,7 +516,7 @@ export function getEmbeddingLevels (string, baseDirection) {
if (charTypes[i] & STRONG_TYPES_FOR_N_STEPS) {
foundStrongType = true
const lr = (charTypes[i] & R_TYPES_FOR_N_STEPS) ? TYPE_R : TYPE_L
if (lr === getEmbedDirection(i)) {
if (lr === embedDirection) {
useStrongType = lr
break
}
Expand All @@ -528,10 +534,10 @@ export function getEmbeddingLevels (string, baseDirection) {
const i = seqIndices[si]
if (charTypes[i] & STRONG_TYPES_FOR_N_STEPS) {
const lr = (charTypes[i] & R_TYPES_FOR_N_STEPS) ? TYPE_R : TYPE_L
if (lr !== getEmbedDirection(i)) {
if (lr !== embedDirection) {
useStrongType = lr
} else {
useStrongType = getEmbedDirection(i)
useStrongType = embedDirection
}
break
}
Expand All @@ -542,7 +548,7 @@ export function getEmbeddingLevels (string, baseDirection) {
// * Any number of characters that had original bidirectional character type NSM prior to the application
// of W1 that immediately follow a paired bracket which changed to L or R under N0 should change to match
// the type of their preceding bracket.
if (useStrongType !== getEmbedDirection(seqIndices[openSeqIdx])) {
if (useStrongType !== embedDirection) {
for (let si = openSeqIdx + 1; si < seqIndices.length; si++) {
if (!(charTypes[seqIndices[si]] & BN_LIKE_TYPES)) {
if (getBidiCharType(string[seqIndices[si]]) & TYPE_NSM) {
Expand All @@ -552,7 +558,7 @@ export function getEmbeddingLevels (string, baseDirection) {
}
}
}
if (useStrongType !== getEmbedDirection(seqIndices[closeSeqIdx])) {
if (useStrongType !== embedDirection) {
for (let si = closeSeqIdx + 1; si < seqIndices.length; si++) {
if (!(charTypes[seqIndices[si]] & BN_LIKE_TYPES)) {
if (getBidiCharType(string[seqIndices[si]]) & TYPE_NSM) {
Expand Down Expand Up @@ -590,7 +596,7 @@ export function getEmbeddingLevels (string, baseDirection) {
}
}
for (let sj = niRunStart; sj <= niRunEnd; sj++) {
charTypes[seqIndices[sj]] = prevType === nextType ? prevType : getEmbedDirection(seqIndices[sj])
charTypes[seqIndices[sj]] = prevType === nextType ? prevType : embedDirection
}
si = niRunEnd
}
Expand Down Expand Up @@ -679,9 +685,4 @@ export function getEmbeddingLevels (string, baseDirection) {
}
return -1
}

function getEmbedDirection (i) {
return (embedLevels[i] & 1) ? TYPE_R : TYPE_L
}

}
Loading