aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorEli Zaretskii2021-11-07 14:22:15 +0200
committerEli Zaretskii2021-11-07 14:22:15 +0200
commit75f4af0b303418f7bf107741684ea50b8c52b7f7 (patch)
tree1bb12abfdad3873168884811b605a3bbd6314ddd /src
parente9a5084c455e7f62c416a05841a6b51f69dd786b (diff)
downloademacs-75f4af0b303418f7bf107741684ea50b8c52b7f7.tar.gz
emacs-75f4af0b303418f7bf107741684ea50b8c52b7f7.zip
Improve detection of suspiciously reordered text segments
* src/bidi.c (bidi_find_first_overridden): Detect reordered weak and neutral characters as well. * lisp/international/mule-cmds.el (highlight-confusing-reorderings): Count and announce how many instances were found. * test/src/xdisp-tests.el (xdisp-tests--find-directional-overrides-case-3): New test. (xdisp-tests--find-directional-overrides-case-2): Adjust expected result.
Diffstat (limited to 'src')
-rw-r--r--src/bidi.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/src/bidi.c b/src/bidi.c
index 511b4602fec..890a60acc43 100644
--- a/src/bidi.c
+++ b/src/bidi.c
@@ -3575,6 +3575,8 @@ bidi_find_first_overridden (struct bidi_it *bidi_it)
3575 overrides, and isolates, i.e. before resolving implicit levels. */ 3575 overrides, and isolates, i.e. before resolving implicit levels. */
3576 int max_l2r = bidi_it->paragraph_dir == L2R ? 0 : 2; 3576 int max_l2r = bidi_it->paragraph_dir == L2R ? 0 : 2;
3577 int max_r2l = 1; 3577 int max_r2l = 1;
3578 /* Same for WEAK and NEUTRAL_ON types. */
3579 int max_weak = bidi_it->paragraph_dir == L2R ? 1 : 2;
3578 3580
3579 do 3581 do
3580 { 3582 {
@@ -3582,6 +3584,8 @@ bidi_find_first_overridden (struct bidi_it *bidi_it)
3582 because the directional overrides are applied by the 3584 because the directional overrides are applied by the
3583 former. */ 3585 former. */
3584 bidi_type_t type = bidi_resolve_weak (bidi_it); 3586 bidi_type_t type = bidi_resolve_weak (bidi_it);
3587 unsigned level = bidi_it->level_stack[bidi_it->stack_idx].level;
3588 bidi_category_t category = bidi_get_category (bidi_it->orig_type);
3585 3589
3586 /* Detect strong L or R types that have been overridden by 3590 /* Detect strong L or R types that have been overridden by
3587 explicit overrides. */ 3591 explicit overrides. */
@@ -3594,10 +3598,14 @@ bidi_find_first_overridden (struct bidi_it *bidi_it)
3594 reorder) by explicit embeddings and isolates. */ 3598 reorder) by explicit embeddings and isolates. */
3595 || ((bidi_it->orig_type == STRONG_L 3599 || ((bidi_it->orig_type == STRONG_L
3596 || bidi_it->orig_type == WEAK_EN) 3600 || bidi_it->orig_type == WEAK_EN)
3597 && bidi_it->level_stack[bidi_it->stack_idx].level > max_l2r) 3601 && level > max_l2r)
3598 || ((bidi_it->orig_type == STRONG_R 3602 || ((bidi_it->orig_type == STRONG_R
3599 || bidi_it->orig_type == STRONG_AL) 3603 || bidi_it->orig_type == STRONG_AL)
3600 && bidi_it->level_stack[bidi_it->stack_idx].level > max_r2l)) 3604 && level > max_r2l)
3605 /* Detect other weak or neutral types whose level was
3606 tweaked by explicit embeddings and isolates. */
3607 || ((category == WEAK || bidi_it->orig_type == NEUTRAL_ON)
3608 && level > max_weak))
3601 found_pos = bidi_it->charpos; 3609 found_pos = bidi_it->charpos;
3602 } while (found_pos == ZV 3610 } while (found_pos == ZV
3603 && bidi_it->charpos < ZV 3611 && bidi_it->charpos < ZV