Live data from Hacker News

Why can't you reverse a string with a flag emoji?

davidamos.dev

201–210 of 247 posts

Re: Why can't you reverse a string with a flag emoji?

#201

Earlier quoted context omitted.

> But then again, flags seem to be not only Unicode-hard but post-Unicode-hard. Flags are not that hard, they're a very specific block combining in very predictable way. They're little more than ligatures. Family emoji are much harder. And this is not "post-Unicode" in any way.

Consider you have to split a string with 20 flags in sequence at a given offset. That's 40 codepoints with no readily discernible boundaries. To parse that you have to scan backwards to find the first non-flag codepoint. Otherwise you could split the middle of a flag pair. You also have to handle rendering invalid combinations as two glyphs and unpaired codes. For normal codepoints with combining characters you can s…

> Consider you have to split a string with 20 flags in sequence at a given offset. That's 40 codepoints with no readily discernible boundaries.

So consider that you have [a really bad idea], it’s not convenient?

You do realise essentially the same issue occurs if you have a stack of diacritics right?

Re: Why can't you reverse a string with a flag emoji?

#202

Earlier quoted context omitted.

Consider you have to split a string with 20 flags in sequence at a given offset. That's 40 codepoints with no readily discernible boundaries. To parse that you have to scan backwards to find the first non-flag codepoint. Otherwise you could split the middle of a flag pair. You also have to handle rendering invalid combinations as two glyphs and unpaired codes. For normal codepoints with combining characters you can s…

> Consider you have to split a string with 20 flags in sequence at a given offset. That's 40 codepoints with no readily discernible boundaries. So consider that you have [a really bad idea], it’s not convenient? You do realise essentially the same issue occurs if you have a stack of diacritics right?

No it doesn't. You aren't forced to scan backwards.

Re: Why can't you reverse a string with a flag emoji?

#204

If you think the Unicode flag emoji take a lot of bytes, then consider the family emoji! ( https://unicode.org/emoji/charts/full-emoji-list.html#family ) I'm in the process of designing a scripting language and implementing it in C++. I plan to put together a YouTube series about it. (Doesn't everyone want to see Bison and Flex mixed with proper unit tests and C++20 code?) Due to my future intended use case, I needed…

It would actually be pretty interesting to see how you use Bison and Flex with utf-8. Most resources say to not bother due to lack of support for Unicode, but they're so ubiquitous

Re: Why can't you reverse a string with a flag emoji?

#205
post #190

Earlier quoted context omitted.

Swift, for example, does what you're saying. I thought that the reason many languages don't do it that way is that part of the definition of an array (or at least expected-by-convention) is constant-time operations. If you treat a string as an array, then having to deal with variable-length units breaks that rule. That's why, when there is an API for dealing with grapheme clusters, it is usually a special case that d…

CPython 3 does use UTF-32 under the hood for strings (there is bytes for plain sequence of bytes). As you say, it's the worst of both worlds. High memory usage, and not really useful if you are dealing with unicode characters (grapheme clusters). My impression is most modern languages that bother with unicode (swift, rust, nim) are using utf-8, and doing linear time operations to handle unicode. I think that's the ri…

Swift originally had UTF-32 strings (an upgrade from ObjC which uses UTF-16), but they redid String to be UTF-8. It's typically the best choice even for CJK text, because it has ASCII mixed in often enough to still be smallest.

I don't think reversing a string is a meaningful operation though; there's no reason to think of a string as a "list of characters" when it's also a "list of words" and several other things. Swift provides more than one kind of iteration for that reason.

Re: Why can't you reverse a string with a flag emoji?

#209

It's sad that Unicode doesn't include flags for dissolved countries. If it did, reversing an US flag would make a Soviet Union flag (code SU). This would make the text much more fun

The whole reason for handling the flag emojis that way was so that the Unicode Consortium wouldn't have to decide which countries should or should not be recognized. It is totally valid for you to configure your computer to display SU as a Soviet flag.

Re: Why can't you reverse a string with a flag emoji?

#210

If the US flag is 2 special symbols saying US, why doesn't reversing it just produce the flag of the Soviet Union?

Same reason why there is no Nazi Germany flag - they are not included in Unicode.

Quite unfortunate - the US/SU case would make a nice Unicode+political pun.
Post reply on HN