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

Unambiguous char-to-number and char-to-digit conversions #227

Open
qurbonzoda opened this issue Dec 8, 2020 · 3 comments
Open

Unambiguous char-to-number and char-to-digit conversions #227

qurbonzoda opened this issue Dec 8, 2020 · 3 comments
Labels

Comments

@qurbonzoda
Copy link
Contributor

qurbonzoda commented Dec 8, 2020

This issue is to discuss the proposal to introduce new Char <-> Int conversion API to make conversions unambiguous.
The new API includes:

fun Char(code: Int): Char
val Char.code: Int
fun Char.digitToInt(radix: Int = 10): Int
fun Char.digitToIntOrNull(radix: Int = 10): Int?
fun Int.digitToChar(radix: Int = 10): Char

The proposal text is here: https://github.com/Kotlin/KEEP/blob/master/proposals/stdlib/char-int-conversions.md.

@ilya-g ilya-g changed the title Unambiguous Number to/from Char conversions Unambiguous char-to-number and char-to-digit conversions Dec 18, 2020
@ilya-g
Copy link
Member

ilya-g commented Dec 25, 2020

Alternative placement suggestion:

  • Char(code) function and Char.code property are so closely related to Char type that they could be placed into kotlin package, or even become members of the Char type itself.

@ilya-g
Copy link
Member

ilya-g commented Dec 25, 2020

Alternative API shape suggestion:

  • instead of providing default value for radix, the functions digitToInt, digitToIntOrNull, digitToChar could have overloads with and without radix, similar to String.toInt and String.toIntOrNull. The motivation is the same: the implementation with the constant radix equal to 10 can be made more efficient.

@qurbonzoda
Copy link
Contributor Author

The suggestions from @ilya-g were discussed and accepted. The KEEP document was updated.

ilya-g added a commit that referenced this issue May 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants