Skip to content

Leave characters removed by X9 out of the results and show their level as x - #19

Merged
isaranga merged 1 commit into
mainfrom
leave-x9-removed-out-of-results
Nov 29, 2026
Merged

isaranga merged 1 commit into
mainfrom
leave-x9-removed-out-of-results

Conversation

@isaranga

Copy link
Copy Markdown
Owner

Rule X9 removes the embedding and override controls (LRE, RLE, LRO, RLO, PDF) and BN, but apply_bidi_algorithm still returned them. Example 6 ended with:

Embedding levels: [0, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 0]
Visual order:     [0, 1, 2, 3, 4, 5, 6, 10, 9, 8, 7, 11]
Reordered text:   '[LRE]Hello םולש[PDF]'

It now ends with:

Embedding levels: [x, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, x]
Visual order:     [1, 2, 3, 4, 5, 6, 10, 9, 8, 7]
Reordered text:   'Hello םולש'

Changes

  • Results (bidi.py): reordered_text and visual_order leave out the removed characters, as the _apply_l2 docstring already said the caller would. logical_levels still has one entry per input character, but a removed character's entry is None. The demo prints it as x, the marker the Unicode conformance files use.
  • Verbose tables (verbose_table.py): from I1 on, the tables show x as a removed character's level, and the L2 table shows x as its position after reordering. This is done by a new format_level_for_table helper and an after_x9 flag on print_table. The P and X tables still show the levels the X rules assigned.
  • Test runners: they now compare levels and visual order directly with the files, instead of filtering out the X9 types themselves.
  • Docs: README.md, CLAUDE.md and example 6's "Watch for" note are updated to match.

API change

Library callers get None in levels for removed characters, and visual_order / reordered are shorter than the input when it contains embedding controls or BN.

Testing

  • Both conformance suites pass in full: 91,707 BidiCharacterTest cases and 770,241 BidiTest cases.
  • python bidi.py --all runs without errors.

…l as x

Rule X9 removes the embedding and override controls (LRE, RLE, LRO,
RLO, PDF) and BN, but apply_bidi_algorithm still returned them:
- reordered_text and visual_order now leave them out, as the _apply_l2
  docstring already promised. Example 6 now ends with 'Hello םולש'
  instead of '[LRE]Hello םולש[PDF]'.
- logical_levels keeps one entry per input character, but a removed
  character's entry is now None. The demo prints it as x, as the
  Unicode conformance files do.

Verbose mode shows x for the removed characters' level in the tables
from I1 on, and for their position after L2 (format_level_for_table
and a new after_x9 flag on print_table). The P and X tables still show
the levels the X rules assigned.

The conformance runners now compare levels and visual order directly
with the files, without filtering out the X9 types themselves.
README.md, CLAUDE.md and example 6's note are updated to match.

Both conformance suites still pass in full.
@isaranga
isaranga merged commit 7de3e6a into main Nov 29, 2026
6 checks passed
@isaranga
isaranga deleted the leave-x9-removed-out-of-results branch November 29, 2026 15:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant