Stream: ideas

Topic: ✔ Trim functions and bidirectional text


view this post on Zulip Hannes (May 18 2023 at 06:42):

I don't speak any RTL languages, but I know UI frameworks like GTK don't use "left" and "right" for layout because they want the layout to be reversed for RTL languages like Arabic, instead they use words like "start" and "end". Do the Str.trimLeft and Str.trimRight functions make sense for Arabic text?

For example, if I have the string " رخ", i.e. the graphemes " " then " " then "ر"then "خ" and I want to remove the leading spaces, my terminal (and Zulip) renders them as being on the left, but web browsers and text editors that have the language set to Arabic will render them on the right.

Could Str.trimStart or Str.trimLeading and the opposite Str.trimEnd or Str.trimTrailing be better names?

view this post on Zulip Hannes (May 18 2023 at 06:51):

Interestingly, I originally copied the graphemes from the Roc REPL and couldn't figure out why it was different in Zulip, turns out Zulip rendered the ", " in between the two Arabic letters in RTL mode, so I had to separate them with the English word "then" so it would be clear what order I meant.
image.png
image.png

view this post on Zulip port19 (May 18 2023 at 07:07):

Idk, a note in the docs should be sufficient

view this post on Zulip Hannes (May 18 2023 at 07:12):

Yeah, it's not a particularly common situation I'll admit, you're right that there could be something in the docs about it.

view this post on Zulip Brendan Hansknecht (May 18 2023 at 13:17):

If different surfaces render them differently, will start and leading even be clear?

view this post on Zulip Brendan Hansknecht (May 18 2023 at 13:19):

Also, if it renders in reverse, does that mean if you copy from your browser into a txt file and then render again, it reverses the text a second time? Just curious how this works out.

view this post on Zulip Hannes (May 18 2023 at 13:37):

The start is the part of text where you begin reading, that is the left for LTR text and the right for RTL text. To get a better understanding you can go to Arabic Wikipedia and try playing with the search bar, leading spaces will appear on the right, and pasting in Arabic text will be RTL, then trailing spaces will be on the left.

view this post on Zulip Hannes (May 18 2023 at 13:40):

The data is always the same, so if you then copy the same text to a text field that's set to LTR like English Wikipedia or Zulip, then leading spaces will be interpreted as LTR, then the Arabic text will be RTL, then trailing spaces as LTR again.

view this post on Zulip Ajai Nelson (May 18 2023 at 15:06):

It looks like Rust originally had trim_left and trim_right but later deprecated them and renamed them to trim_start and trim_end

view this post on Zulip Brendan Hansknecht (May 18 2023 at 18:19):

That's good to know. Yeah, probably worth changing this.

view this post on Zulip Richard Feldman (May 18 2023 at 23:24):

yeah so I asked a friend of mine who:

and she said she would prefer trimLeft and trimRight over trimStart and trimEnd, contrary to my expectation :big_smile:

view this post on Zulip Richard Feldman (May 18 2023 at 23:24):

back in the day - that was why we went with trimStart and trimEnd in the first place

view this post on Zulip Brendan Hansknecht (May 18 2023 at 23:54):

Would she expect trimLeft to actually trim the spaces on the left side of the text? If so, that means it would need to know the language to pick what to trim.

view this post on Zulip Richard Feldman (May 19 2023 at 00:11):

hm that's a good point, I don't remember if I asked

view this post on Zulip Richard Feldman (May 19 2023 at 00:26):

I talked to another friend who is both a programmer and speaks Hebrew, and he sold me on trimStart/trimEnd :big_smile:

view this post on Zulip Richard Feldman (May 19 2023 at 00:26):

if anyone wants to make a PR, I'm open to it!

view this post on Zulip Hannes (Jun 19 2023 at 04:25):

Opened issue #5571 for this :)

view this post on Zulip Hannes (Jun 19 2023 at 04:28):

And opened PR #5572 to address it :) It's my first attempt at contributing to the compiler, so I haven't managed to get all the tests passing yet, if someone can tell me what I'm missing that would be very helpful :)

view this post on Zulip Brendan Hansknecht (Jun 19 2023 at 04:30):

My guess not seeing the specific tests failing is that they are mono or ui tests and you just need to check in the files they are modifying.

view this post on Zulip Brendan Hansknecht (Jun 19 2023 at 04:45):

Oh, actually, looking at failures, I think you still have more uses of StrTrimLeft/Right to update to the new names

view this post on Zulip Hannes (Jun 19 2023 at 05:09):

Ah, thanks @Brendan Hansknecht I'm running the tests again now

view this post on Zulip Notification Bot (Jun 19 2023 at 09:16):

Anton has marked this topic as resolved.


Last updated: Jun 16 2026 at 16:19 UTC