On Sun, Oct 27, 2019 at 11:43 PM Steven D'Aprano
On Sun, Oct 27, 2019 at 12:10:22AM -0700, Andrew Barnert via Python-ideas wrote:
If you redesign your find, re.search, etc. APIs to not return character indexes, then I think you can get away with not having character-indexable strings.
If string.index(c) doesn't return the index of c in string, then what does it return?
I think you are conflating the public API based on characters (to be precise: code points) for some underlying implementation based on bytes. Given zero-based indexing, and the string:
"abÇÐεф"
the index of "ф" better damn well be 5 rather than 8 (UTF-8), 10 (UTF-16) or 20 (UTF-32) or I'll be knocking on the API designer's door with a pitchfork and a flaming torch *wink*
And returning
is even worse.
And in response to the notion that you don't actually need the index,
just a position marker... consider this:
File "/home/rosuav/tmp/demo.py", line 1
print("Hello, world!')
^
SyntaxError: EOL while scanning string literal
Well, either that, or we need to make it so that " "*