File tree Expand file tree Collapse file tree 2 files changed +15
-2
lines changed
Expand file tree Collapse file tree 2 files changed +15
-2
lines changed Original file line number Diff line number Diff line change @@ -366,14 +366,14 @@ class Utf16View {
366366 if (has_ascii_storage ()) {
367367 VERIFY (it.has_ascii_storage ());
368368 VERIFY (it.m_iterator .ascii >= m_string.ascii );
369- VERIFY (it.m_iterator .ascii <= m_string.ascii );
369+ VERIFY (it.m_iterator .ascii <= m_string.ascii + length_in_code_units () );
370370
371371 return it.m_iterator .ascii - m_string.ascii ;
372372 }
373373
374374 VERIFY (!it.has_ascii_storage ());
375375 VERIFY (it.m_iterator .utf16 >= m_string.utf16 );
376- VERIFY (it.m_iterator .utf16 <= m_string.utf16 );
376+ VERIFY (it.m_iterator .utf16 <= m_string.utf16 + length_in_code_units () );
377377
378378 return it.m_iterator .utf16 - m_string.utf16 ;
379379 }
Original file line number Diff line number Diff line change @@ -495,6 +495,19 @@ TEST_CASE(code_point_offset_of)
495495 EXPECT_EQ (view.code_point_offset_of (13 ), 11uz);
496496}
497497
498+ TEST_CASE (iterator_offset)
499+ {
500+ Utf16View view { u" 😂 foo 😀 bar" sv };
501+ size_t expected_offset = 0 ;
502+
503+ for (auto it = view.begin (); it != view.end (); ++it) {
504+ EXPECT_EQ (view.iterator_offset (it), expected_offset);
505+ expected_offset += it.length_in_code_units ();
506+ }
507+
508+ EXPECT_EQ (view.iterator_offset (view.end ()), view.length_in_code_units ());
509+ }
510+
498511TEST_CASE (replace)
499512{
500513 auto result = u" " sv.replace ({}, {}, ReplaceMode::FirstOnly);
You can’t perform that action at this time.
0 commit comments