docs: clarify UTF-8 indexing explanation and fix punctuation in string and values documentation
This commit is contained in:
@@ -10,8 +10,8 @@ get involved, it's important to understand the distinction.
|
||||
|
||||
In UTF-8, a single Unicode code point (very roughly a single "character") may
|
||||
be encoded as one or more bytes. This means you can't directly index by code
|
||||
point. There's no way to find, say, the fifth code unit in a string without
|
||||
walking the string from the beginning and counting them as you go.
|
||||
point. There's no way to jump directly to, say, the fifth code unit in a string
|
||||
without walking the string from the beginning and counting them as you go.
|
||||
|
||||
Because counting code units is relatively slow, string methods generally index
|
||||
by *byte*, not *code unit*. When you do:
|
||||
@@ -28,8 +28,8 @@ on string *return* byte indices too. So, for example, this does what you want:
|
||||
var hPosition = metalBand.indexOf("h")
|
||||
IO.print(metalBand[hPosition]) // "h"
|
||||
|
||||
In general, methods on strings will work in terms of code units if they can do
|
||||
so efficiently, and will otherwise deal in bytes.
|
||||
In general, methods on strings work in terms of code units if they can do so
|
||||
efficiently, and otherwise deal in bytes.
|
||||
|
||||
## Static Methods
|
||||
|
||||
@@ -37,12 +37,12 @@ so efficiently, and will otherwise deal in bytes.
|
||||
|
||||
Creates a new string containing the UTF-8 encoding of `codePoint`.
|
||||
|
||||
It is a runtime error if `codePoint` is not an integer between `0` and
|
||||
`0x10ffff`, inclusive.
|
||||
|
||||
:::dart
|
||||
String.fromCodePoint(8225) // "‡"
|
||||
|
||||
It is a runtime error if `codePoint` is not an integer between `0` and
|
||||
`0x10ffff`, inclusive.
|
||||
|
||||
## Methods
|
||||
|
||||
### **byteAt**(index)
|
||||
|
||||
Reference in New Issue
Block a user