aiscript icon indicating copy to clipboard operation
aiscript copied to clipboard

文字列系・ユニコード系APIの変更の提案 (Draft 2)

Open marihachi opened this issue 1 year ago • 0 comments

APIの名前を変更します。 (#566 の次の案です)

方針

  • 全般的な文字列操作はプリミティブプロパティに置く
  • Unicode特有の機能やutf8などのエンコーディング関係はstdに名前空間を作って置く

検討点

  • あえて、名前空間Unicodeに置く必要があるのか。Strに置いてもよい?
  • 名前空間Utf8Utf16Encoding:Utf8Encoding:Utf16にそれぞれ置いたほうが分かりやすい?

変更案

1行目は元の名前 2行目は変更後の名前

Unicodeのコードポイントから文字

@Str:from_codepoint(codepoint: num): str
@Unicode:from_codepoint(codepoint: num): str

Unicodeのコードポイント配列から文字列

@Str:from_unicode_codepoints(codePoints: arr<num>): str
@Unicode:from_codepoint_arr(codePoints: arr<num>): str

UTF-8バイト配列から文字列

@Str:from_utf8_bytes(bytes: arr<num>): str
@Utf8:from_byte_arr(bytes: arr<num>): str

書記素クラスタ毎に分割

@(v: str).to_arr(): arr<str>
変更なし

コードポイント毎に分割、文字配列を取得

@(v: str).to_unicode_arr(): arr<str>
変更なし

コードポイント毎に分割、コードポイントの数値配列を取得

@(v: str).to_unicode_codepoint_arr(): arr<num>
@Unicode:to_codepoint_arr(v: str): arr<num>

UTF-16 コード単位毎に分割、UTF-16 コード単位の文字配列を取得

@(v: str).to_char_arr(): arr<str>
@Utf16:to_char_arr(v: str): arr<num>

UTF-16 コード単位毎に分割、UTF-16 コード単位の数値配列を取得

@(v: str).to_charcode_arr(): arr<num>
@Utf16:to_charcode_arr(v: str): arr<num>

文字列をUTF-8バイト配列へ

@(v: str).to_utf8_byte_arr(): arr<num>
@Utf8:to_byte_arr(v: str): arr<num>

i 番目のにある UTF-16 コード単位の数値を取得

@(v: str).charcode_at(i: num): num | null
@Utf16:charcode_at(v: str, i: num): num | null

i 番目の文字のコードポイントの数値を取得

@(v: str).codepoint_at(i: num): num | null
@Unicode:codepoint_at(v: str, i: num): num | null

marihachi avatar Feb 11 '24 01:02 marihachi