Comments (3)
(As discussed internally with @connorg):
This is a bit tricky. I see and agree with the argument, but I do worry about being inconsistent between these two fundamental types. If folks get used to codepoint-based indexing with String
and then start to use StringSlice
, the could easily be confused and write incorrect code without realizing it.
For folks who want to work on raw bytes, they can use StringSlice.as_bytes_slice()[idx]
to be explicit about it.
from mojo.
they can use StringSlice.as_bytes_slice()[idx] to be explicit about it
you're right, totally forgot that existed
I'll leave the issue open until we get the utf32 indexing done. If somebody else wants to tackle it be my guest. I was thinking if nobody takes it on by this weekend to give it a go and try to setup something faster for counting utf8 continuation bytes with SIMD since it is used in other places.
from mojo.
@JoeLoser opened PR #3295 but there are some issues with other functions such as String.format
, String.rfind
, and some others may have an issue but might not be well tested. I'm worried that too many places assume string is indexed by byte offset directly.
I think it might be worth it to rethink if we really want utf32 indexing in a utf8 encoded String. It might be better to just build a PythonString that uses utf32. Or to just let indexing be by byte offset and provide an explicit method for python style indexing (this is my favorite one tbh.).
from mojo.
Related Issues (20)
- [BUG] REPL help example code fails to interpret HOT 2
- [Feature Request] Command line option for generating LLVM IR files
- [Feature Request] Command line option to generate object files instead of binaries
- [Feature Request] no-mangle decorator HOT 5
- [Feature Request] Command line option to disable the standard library HOT 1
- [BUG] Using a param `__getattr__()` breaks `__setattr__()` HOT 1
- [Feature Request] Have the LSP filter the auto completion list based on conditional conformance HOT 1
- [Modular CLI] cannot create account with gmail ? HOT 4
- [BUG] Unexpected constructor resolution due to implicit type casting
- DTypepointer scatter fails to compile inside an object
- [Docs] Install Mojo SSL Error HOT 2
- [BUG] `0! == 0` HOT 5
- [BUG] Wrong type conversion HOT 2
- [Feature Request] Gradual adoption into python project
- [Feature Request] Align Mojo `alias` with `type` HOT 1
- [Feature Request] `--free-standing` option in command line to make embedded systems
- [BUG] mojo test: couldn't build the test executable in current nightlies HOT 3
- [BUG] .mojopkg files do not support nested package directory structures HOT 1
- [BUG] REPL incorrectly displays boolean SIMD vector contents
- [Modular CLI] Running `modular auth` fails with the error message: http error: response code 404 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mojo.