Skip to content

Commit

Permalink
fix detail
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 ecb237f commit 6b76669
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
4 changes: 2 additions & 2 deletions stdlib/src/collections/string/string_slice.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ fn _utf8_first_byte_sequence_length(b: Byte) -> Int:
this does not work correctly if given a continuation byte."""

debug_assert(
(b & 0b1100_0000) != 0b1000_0000,
not _is_continuation_byte(b),
"Function does not work correctly if given a continuation byte.",
)
return Int(count_leading_zeros(~b)) + Int(b < 0b1000_0000)
Expand Down Expand Up @@ -1154,7 +1154,7 @@ struct StringSlice[mut: Bool, //, origin: Origin[mut]](
# overall length in bytes.
# For a visual explanation of how this UTF-8 codepoint counting works:
# https://connorgray.com/ephemera/project-log#2025-01-13
var continuation_count = _count_utf8_continuation_bytes(self)
var continuation_count = _count_utf8_continuation_bytes(self.as_bytes())
return self.byte_length() - continuation_count

fn get_immutable(
Expand Down
3 changes: 1 addition & 2 deletions stdlib/test/collections/string/test_string_slice.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -552,8 +552,7 @@ def test_count_utf8_continuation_bytes():
def _test(amnt: Int, items: List[UInt8]):
var p = items.unsafe_ptr()
var span = Span[Byte, StaticConstantOrigin](ptr=p, length=len(items))
var str_slice = StringSlice(unsafe_from_utf8=span)
assert_equal(amnt, _count_utf8_continuation_bytes(str_slice))
assert_equal(amnt, _count_utf8_continuation_bytes(span))

_test(5, List[UInt8](c, c, c, c, c))
_test(2, List[UInt8](b2, c, b2, c, b1))
Expand Down

0 comments on commit 6b76669

Please sign in to comment.