A simple function to get a char from a string based on the byte position #270
Replies: 3 comments 4 replies
-
I have a question for skilled devs and/or for Mojo team, what will be cheaper: Mojo implementation or __mlir_op external_call to libc mbstowcs or whatever? It is general question not only for this case. |
Beta Was this translation helpful? Give feedback.
-
@mzaks this is cool. Are you expecting it to always return a valid code point though? Seems like this might get tripped up between pre-composed / decomposed where you're treating Also, just a naming nit-pick. I'd consider naming this something like I'm definitely looking forward to an Iterator trait that allows iterating over a string a code point at a time |
Beta Was this translation helpful? Give feedback.
-
Strings in Mojo are backed by a utf-8 buffer and the subscription into a string might be confusing as it works on byte level, where a char in utf-8 can be represented in up to 4 bytes. This function will return a char even if the provided byte position is in the middle of the char code.
Beta Was this translation helpful? Give feedback.
All reactions