目的
文字列のエンコーディングと「1 文字」の表現を決める。f-string (#18) / split / strip / find (#39) の戻り値・添字を確定するために必要。
現状
検討事項
- エンコーディング: UTF-8 を確定 (Go / Rust と同じ)
- char 型:
rune = i32 (Go 風) or char = u32 codepoint (Rust)
- 添字アクセス:
str[i] はバイト位置か codepoint 位置か grapheme か
- Rust は禁止 (
bytes() / chars() を明示)
- Go は byte index
- Python は codepoint
- イテレーション:
for c in str の c の型は?
提案 (drafting)
- UTF-8 を確定
char (4-byte codepoint) を追加
str[i] は 禁止または警告(曖昧)→ 代わりに str_codepoints(s) / str_bytes(s) のような明示 API
for c in str は codepoint イテレーション
受け入れ条件
関連
目的
文字列のエンコーディングと「1 文字」の表現を決める。f-string (#18) / split / strip / find (#39) の戻り値・添字を確定するために必要。
現状
stringは内部的に UTF-8 (docs/specs/07-string-builtins.md参照のはず)str[0]の戻り値型が未定義Bytes(言語: dict[K, V] 型と hashable プロトコル #8 既存) とstringのキャスト境界が薄い検討事項
rune = i32(Go 風) orchar = u32 codepoint(Rust)str[i]はバイト位置か codepoint 位置か grapheme かbytes()/chars()を明示)for c in strのcの型は?提案 (drafting)
char(4-byte codepoint) を追加str[i]は 禁止または警告(曖昧)→ 代わりにstr_codepoints(s)/str_bytes(s)のような明示 APIfor c in strは codepoint イテレーション受け入れ条件
docs/specs/に追加charリテラル構文 ('a','\u{1F600}') を決定関連