Re:TIL the assumption that string length does not change whe...
by s_gourichon on Monday November 22, 2021 @01:22AM
(#29303421)
Since you ask for an example: moving the cursor in a terminal-based text editor requires #2 string length. That said I understand your point about focusing on what is actually needed.
Re:TIL the assumption that string length does not change whe...
by yorwba on Monday November 22, 2021 @04:55AM
(#29304678)
Moving the cursor doesn't require string length, it requires finding the new cursor position. You can compute #2 length by moving the cursor one grapheme cluster at a time until you hit the end, but if you only need to move the cursor once, the length is irrelevant. (Also, cursor positions in a terminal-based text editor don't necessarily correspond to graphemes.)
Re:TIL the assumption that string length does not change whe...
by tshaddox on Monday November 22, 2021 @02:32AM
(#29303806)
It’s pretty crucial to the game Hangman.
Re:TIL the assumption that string length does not change whe...
by kaetemi on Monday November 22, 2021 @12:55AM
(#29303263)
Not length directly in itself, but the abstraction seems applicable to text editing controls.
Re:TIL the assumption that string length does not change whe...
by arcticbull on Monday November 22, 2021 @01:27AM
(#29303446)
That’s both #2 and #3, because Unicode characters can have various widths including zero. Gotta find out how far to move the cursor.
Re:TIL the assumption that string length does not change whe...
by ygra on Monday November 22, 2021 @06:34AM
(#29305289)
The Unicode character doesn't really have an intrinsic width; the font will define one (and I think a font could define a glyph even for things like zero-width spaces). But as soon as you want to display text you'll get into all sorts of fun problems and string length is most likely never applicable in any way. At that point the Unicode string becomes a sequence of glyphs from a font with their respective placements and there's no guaranteed relationship between the number of glyphs and the original number of code points, anyway.
Re:TIL the assumption that string length does not change whe...
by 3np on Monday November 22, 2021 @03:44AM
(#29304234)
“Full name” has a minimum length of 1.
Re:TIL the assumption that string length does not change whe...
by dodobirdlord on Monday November 22, 2021 @02:44PM
(#29310792)
Even for this you probably wouldn't want to use #2, because some grapheme clusters are composed to create ligatures and wouldn't be used outside of composing to create a ligature, so they shouldn't ever form a valid string by themselves. But by the #2 analysis this would read as "length 1".
Re:TIL the assumption that string length does not change whe...
by 3np on Monday November 22, 2021 @03:38PM
(#29311325)
Can you think of a way to do stricter while still not rejecting valid names?
I don’t have one.
(Except the airline model of “only A-Z” but it seems silly to stay there just because people could slip ligatures through the form)
The reason this isn't an issue is because it's nearly impossible to think of a legit use case.