Skip to content

Keep word boundaries when stripping unrenderable emoji - #714

Open
einanderson wants to merge 1 commit into
anxdpanic:masterfrom
einanderson:fix/tofu-word-boundaries
Open

Keep word boundaries when stripping unrenderable emoji#714
einanderson wants to merge 1 commit into
anxdpanic:masterfrom
einanderson:fix/tofu-word-boundaries

Conversation

@einanderson

Copy link
Copy Markdown
Contributor

strip_tofu() removes unrenderable emoji and symbols so they do not show up as tofu boxes in the
skin font. It deleted them without replacement, so when a title used an emoji as a separator the
surrounding words were glued together:

WEEKEND<emoji>Type   ->  WEEKENDType

Reported against a community build by a user who noticed titles losing their word boundaries.

The change

A run of unrenderable characters is replaced by a single space instead of being dropped. Runs
collapse to one space, horizontal whitespace is smoothed afterwards, whitespace around line breaks
is trimmed while the line breaks themselves are kept (they matter for plots), and the result is
stripped.

Verification

Checked against the real function with 11 cases (word boundary, emoji run, ZWJ sequence, emoji at
the edges, blank line, accents and CJK untouched, non-string passthrough), and live against Twitch
titles:

raw:      ALARMA <emoji> GAMEPLAY DE GTA 6 FILTRADO <emoji> DESEMPLEADOS ASSEMBLE <emoji>
label:    ALARMA GAMEPLAY DE GTA 6 FILTRADO DESEMPLEADOS ASSEMBLE

raw:      [593/730] <emoji> DAY 2 <emoji> PLAYING THE LAST OF US PART 1 & 2 <emoji>
label:    [593/730] DAY 2 PLAYING THE LAST OF US PART 1 & 2

Accents, CJK and non-emoji symbols such as U+25AB and U+2192 are unaffected.

strip_tofu() removed emoji/symbols outright, which glued the surrounding
words together whenever a title used one as a separator, e.g.
"WEEKEND<emoji>Type" was shown as "WEEKENDType".

Replace a run of unrenderable characters with a single space instead, then
tidy up: collapse horizontal whitespace, drop whitespace around line breaks
(line breaks themselves are still kept, they matter for plots) and trim the
result.

Reported by kuraikaze.
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