Narrow string is not a random access range
Jonathan M Davis
jmdavisProg at gmx.com
Wed Oct 24 12:38:41 PDT 2012
On Wednesday, October 24, 2012 14:37:33 mist wrote:
> Wait. So you consider commonPrefix returning malformed string to
> be fine? I have lost you here. For example, for code sample given
> above, output is:
>
> ==========
> Пи
> П[\D0]
> ==========
>
> Problem is if you use == on code unit you can match only part of
> valid symbol.
Hmmm. Let me think this through for a moment. Every code point starts with a
code unit that tells you how many code units are in the code point, and each
code point should have only one sequence of code units which represents it, so
something like find or startsWith should be able to just use code units.
commonPrefix is effectively doing a startsWith/find, but it's shortcutted once
there's a difference, and that _could_ be in the middle of a code point, since
you could have a code point with 3 code units where the first 2 match but no
the third one. So, yes. There is a bug here.
Now, a full decode still isn't necessary. It just has to keep track of how
long the code point is and return a slice starting at the end of the code
previous code point if not all of a code point matches, but you've definitely
found a bug.
- Jonathan M Davis
More information about the Digitalmars-d-learn
mailing list