Skip to content

Match letters longer than one code unit when reading Brahmic scripts - #71

Merged
vvasuki merged 1 commit into
indic-transliteration:masterfrom
bardrop-oss:fix-brahmic-multi-unit-letters
Nov 26, 2026
Merged

vvasuki merged 1 commit into
indic-transliteration:masterfrom
bardrop-oss:fix-brahmic-multi-unit-letters

Conversation

@bardrop

@bardrop bardrop commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

Fixes #26, fixes #63.

transliterateBrahmic reads one UTF-16 code unit at a time, so letters outside the BMP never match. Text in Grantha, Sharada, Brahmi, Newa, Siddham etc. comes back unchanged:

Sanscript.t("𑆓𑆼𑆖𑇀𑆗𑆠𑆴", "sharada", "iast") // '𑆓𑆼𑆖𑇀𑆗𑆠𑆴', now 'gecchati'

The same happens to letters made of two characters, like க³ in tamil_superscripted or a letter with nukta.

It now takes the longest token from the map at each position, like transliterateRoman and the Python version do.

I ran 3000 random Devanagari words through Devanagari → script → Devanagari. Grantha, Sharada and Newa go from 3000 mismatches to 0, Javanese from 1543 to 0, tamil_superscripted from 2603 to 0, Siddham from 3000 to 6. No scheme got worse. What is left in other scripts are letters that share a sign in the map.

One old test value changes: Devanagari → Gurmukhi expected ਕ੍षੇ, with a Devanagari ष left in. The map has an entry for क्ष, which is used now (ਕ੍ਸ਼ੇ, same as the Python version).

The new test fails without the change. A text of 215,000 characters takes 30 ms instead of 13 ms here.

@vvasuki
vvasuki merged commit 2d65f76 into indic-transliteration:master Nov 26, 2026
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.

Conversion from shaaradaa is broken transliterateBrahmic doesn't recognize multi-byte characters

2 participants