Skip to content

Commit

Permalink
edit changelog
Browse files Browse the repository at this point in the history
Signed-off-by: martinvuyk <martin.vuyklop@gmail.com>
  • Loading branch information
martinvuyk committed Feb 1, 2025
1 parent ae53225 commit b63da92
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 25 deletions.
24 changes: 3 additions & 21 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -217,29 +217,11 @@ what we publish.
- `b16encode()`
- `b16decode()`
- Added new `String.chars()` and `String.char_slices()` iterator methods, and
deprecated the existing `String.__iter__()` method.
- Added new `String.chars()` and `String.char_slices()` iterator methods.
Different use-cases may prefer iterating over the `Char`s encoded in a string,
or iterating over subslices containing single characters. Neither iteration
semantics is an obvious default, so the existing `__iter__()` method has been
deprecated in favor of writing explicit iteration methods for the time being.
Code of the form:
```mojo
var s: String = ...
for c in s:
# ...
```

can be migrated to using the `.char_slices()` method:

```mojo
var s: String = ...
for c in s.char_slices():
# ...
```
or iterating over subslices containing single characters. The existing
`__iter__()` method defaults to `String.char_slices()`.
- The `String.__len__()` and `StringSlice.__len__()` methods now return the
length of the string in bytes.
Expand Down
8 changes: 4 additions & 4 deletions stdlib/test/collections/string/test_string.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -1152,7 +1152,7 @@ def test_string_char_slices_iter():
# Borrow immutably
fn conc(vs: String) -> String:
var c = String("")
for v in vs.char_slices():
for v in vs:
c += v
return c

Expand All @@ -1163,11 +1163,11 @@ def test_string_char_slices_iter():
concat += v
assert_equal(321, atol(concat))

for v in vs.char_slices():
for v in vs:
v.unsafe_ptr().origin_cast[mut=True]()[] = ord("1")

# Borrow immutably
for v in vs.char_slices():
for v in vs:
concat += v

assert_equal(321111, atol(concat))
Expand Down Expand Up @@ -1224,7 +1224,7 @@ def test_string_char_slices_iter():
var ptr = item.unsafe_ptr()
var amnt_characters = 0
var byte_idx = 0
for v in item.char_slices():
for v in item:
var byte_len = v.byte_length()
for i in range(byte_len):
assert_equal(ptr[byte_idx + i], v.unsafe_ptr()[i])
Expand Down

0 comments on commit b63da92

Please sign in to comment.