Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

str.starts_withとstr.ends_withを追加 #652

Merged
merged 4 commits into from
May 12, 2024

Conversation

salano-ym
Copy link
Member

@salano-ym salano-ym commented May 9, 2024

What

str.starts_withstr.ends_withを追加

  • @(v: str).starts_with(prefix: str, start_index?: num): bool
  • @(v: str).ends_with(suffix: str, end_index?: num): bool

### @(_v_: str).starts_with(_prefix_: str, _start\_index_?: num): bool
文字列が _prefix_ で始まっていれば`true`、そうでなければ`false`を返します。\
_prefix_ が空文字列の場合は常に`true`を返します。\
_start\_index_ が指定されている場合、そのインデックスから始めます。\
_start\_index_`v_.len`より大きいか`-v.len`より小さい場合は`false`を返します。\
_start\_index_ が負の場合は末尾から数えます。
### @(_v_: str).ends_with(_suffix_: str, _end\_index_?: num): bool
文字列が _suffix_ で終わっていれば`true`、そうでなければ`false`を返します。\
_suffix_ が空文字列の場合は常に`true`を返します。\
_end\_index_ が指定されている場合、そのインデックスの直前を末尾とします。\
_end\_index_`v_.len`より大きいか`-v.len`より小さい場合は`false`を返します。\
_end\_index_ が負の場合は末尾から数えます。

Why

#640

Additional info (optional)

@salano-ym salano-ym mentioned this pull request May 9, 2024
6 tasks
@salano-ym salano-ym requested review from uzmoi and FineArchs May 9, 2024 18:49
Copy link
Member

@uzmoi uzmoi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

str.ends_with(suffix, -0)が出来たほうが嬉しい気持ちあります。
ただ、0と-0の区別すると混乱の元なので、もしやるなら正負を反転して+を末尾からのカウントにするのがおそらく一番自然。

"abcdef".ends_with("bcd", 2) == true
"abcdef".ends_with("bcd", -4) == true

わかりにくくなるので今のままでも良いと思います。

@salano-ym
Copy link
Member Author

str.ends_with(suffix, -0)が出来たほうが嬉しい気持ちあります。

js側の仕様やstr.sliceなどとの一貫性のためにこの末尾判定を選びました。
js以外のendsWithはインデックス指定の無いものが多いのでいっそ無くしてしまうというのもあるかと思いますがどうでしょう?

@FineArchs
Copy link
Member

str.ends_with(suffix, -0)が出来たほうが嬉しい気持ちあります。
ただ、0と-0の区別すると混乱の元なので、もしやるなら正負を反転して+を末尾からのカウントにするのがおそらく一番自然。

インデックス系の仕様は統一したいので私的には今のままがいいなあ…という気持ちがあります。

js側の仕様やstr.sliceなどとの一貫性のためにこの末尾判定を選びました。
js以外のendsWithはインデックス指定の無いものが多いのでいっそ無くしてしまうというのもあるかと思いますがどうでしょう?

私としてはあった方が便利なので欲しいです。

@uzmoi
Copy link
Member

uzmoi commented May 10, 2024

js側の仕様やstr.sliceなどとの一貫性のためにこの末尾判定を選びました。

一貫性がなくなるのはそうなので、今のままでいいかと思います。

@salano-ym salano-ym merged commit c90a098 into aiscript-dev:master May 12, 2024
4 checks passed
@salano-ym salano-ym deleted the str-startswith-endswith branch May 13, 2024 02:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants