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] Compiler seg fault (recursion related?) HOT 4
- [BUG] Parser accepts single `main` function without body
- [BUG] Mojo should block mutating `__getitem__ -> ref ...` call on `alias` HOT 2
- [BUG] Using a default value for a List of functions attribute of a struct leads to an OOB error upon access.
- [BUG][compiler] immediate variable reassignment back of transferred mutated `String` value segfaults when mutation value is a `StringLiteral` that isn't copied first using `String.__copyinit__` HOT 6
- [Feature Request] FreeBSD ports collection HOT 1
- [BUG] Cannot bind to trait with missing parameters for unbound types to check trait conformance HOT 5
- [Docs] Suggestion: link to python types docs in module | Dict
- [BUG]Mojo doesnt recognise main function HOT 5
- [BUG] Errors with optional recursive struct definitions HOT 1
- [Feature Request] Make `StringRef.find` call `StringSlice.find`
- [BUG] [stdlib] Fix `String.format()` to use explicit byte indexing and not assume `String.__getitem__` indexes directly to byte offset.
- [BUG] Mojo SDK post-install test failures
- [BUG] Mojo SDK post-install test failures
- [BUG] Jupyter Notebook fails to load mojo kernel
- [Feature Request] Add functionality like `@classmethod` to enforce conditional conformance on struct static methods
- [Docs] Mojo URL leads to 404 HOT 3
- [BUG] Type checker is failing to compare two function types HOT 1
- [BUG] global variable initialized from num_performance_cores() become 0 after compile HOT 5
- [BUG] `parallelize` should abort if num_workers < 0, currently it has weird behavior HOT 2
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.