-
Notifications
You must be signed in to change notification settings - Fork 206
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
format: use character semantics for length and index operations on st…
…rings (#2921) Conceptually, strings (as in Python) are sequences of characters. Use character-based semantics when computing the length of a string or looking up what is in a string at a particular offset. This more closely matches Python's behaviour for these operations: ``` Python 3.10.12 (main, Jun 11 2023, 05:26:28) [GCC 11.4.0] on linux Type "help", "copyright", "credits" or "license" for more information. >>> print(len("line")) 4 >>> print(len("línea")) 6 >>> print(len("линия")) 5 >>> print(len("خط")) 2 ``` Fixes #2920.
- Loading branch information
1 parent
c97dc5b
commit 1643b23
Showing
5 changed files
with
74 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# U+006C : LATIN SMALL LETTER L | ||
# U+0069 : LATIN SMALL LETTER I | ||
# U+006E : LATIN SMALL LETTER N | ||
# U+0065 : LATIN SMALL LETTER E | ||
s1 = "line" | ||
c1 = s1[0] | ||
|
||
# U+006C : LATIN SMALL LETTER L | ||
# U+0069 : LATIN SMALL LETTER I | ||
# U+0301 : COMBINING ACUTE ACCENT {stress mark; Greek oxia, tonos} | ||
# U+006E : LATIN SMALL LETTER N | ||
# U+0065 : LATIN SMALL LETTER E | ||
# U+0061 : LATIN SMALL LETTER A | ||
s2 = "línea" | ||
c2 = s2[3] | ||
|
||
# U+043B : CYRILLIC SMALL LETTER EL | ||
# U+0438 : CYRILLIC SMALL LETTER I | ||
# U+043D : CYRILLIC SMALL LETTER EN | ||
# U+0438 : CYRILLIC SMALL LETTER I | ||
# U+044F : CYRILLIC SMALL LETTER YA | ||
s3 = "линия" | ||
c3 = s3[2] | ||
|
||
# U+062E : ARABIC LETTER KHAH | ||
# U+0637 : ARABIC LETTER TAH | ||
s4 = "خط" | ||
c4 = s4[1] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,31 @@ | ||
x = 'golang.org/x/sync' | ||
y = x[len('golang.org/x/'):] | ||
|
||
# U+006C : LATIN SMALL LETTER L | ||
# U+0069 : LATIN SMALL LETTER I | ||
# U+006E : LATIN SMALL LETTER N | ||
# U+0065 : LATIN SMALL LETTER E | ||
s1 = "line" | ||
l1 = len(s1) | ||
|
||
# U+006C : LATIN SMALL LETTER L | ||
# U+0069 : LATIN SMALL LETTER I | ||
# U+0301 : COMBINING ACUTE ACCENT {stress mark; Greek oxia, tonos} | ||
# U+006E : LATIN SMALL LETTER N | ||
# U+0065 : LATIN SMALL LETTER E | ||
# U+0061 : LATIN SMALL LETTER A | ||
s2 = "línea" | ||
l2 = len(s2) | ||
|
||
# U+043B : CYRILLIC SMALL LETTER EL | ||
# U+0438 : CYRILLIC SMALL LETTER I | ||
# U+043D : CYRILLIC SMALL LETTER EN | ||
# U+0438 : CYRILLIC SMALL LETTER I | ||
# U+044F : CYRILLIC SMALL LETTER YA | ||
s3 = "линия" | ||
l3 = len(s3) | ||
|
||
# U+062E : ARABIC LETTER KHAH | ||
# U+0637 : ARABIC LETTER TAH | ||
s4 = "خط" | ||
l4 = len(s4) |