File tree Expand file tree Collapse file tree 3 files changed +33
-0
lines changed
Expand file tree Collapse file tree 3 files changed +33
-0
lines changed Original file line number Diff line number Diff line change @@ -219,6 +219,7 @@ class Utf16StringBase {
219219
220220 [[nodiscard]] ALWAYS_INLINE bool contains (char16_t needle) const { return find_code_unit_offset (needle).has_value (); }
221221 [[nodiscard]] ALWAYS_INLINE bool contains (Utf16View const & needle) const { return find_code_unit_offset (needle).has_value (); }
222+ [[nodiscard]] ALWAYS_INLINE bool contains_any_of (ReadonlySpan<u32 > needles) const { return utf16_view ().contains_any_of (needles); }
222223
223224 [[nodiscard]] ALWAYS_INLINE size_t count (Utf16View const & needle) const { return utf16_view ().count (needle); }
224225
Original file line number Diff line number Diff line change @@ -480,6 +480,16 @@ class Utf16View {
480480 [[nodiscard]] constexpr bool contains (char16_t needle) const { return find_code_unit_offset (needle).has_value (); }
481481 [[nodiscard]] constexpr bool contains (Utf16View const & needle) const { return find_code_unit_offset (needle).has_value (); }
482482
483+ [[nodiscard]] constexpr bool contains_any_of (ReadonlySpan<u32 > needles) const
484+ {
485+ for (auto code_point : *this ) {
486+ if (needles.contains_slow (code_point))
487+ return true ;
488+ }
489+
490+ return false ;
491+ }
492+
483493 [[nodiscard]] constexpr size_t count (Utf16View const & needle) const
484494 {
485495 if (needle.is_empty ())
Original file line number Diff line number Diff line change @@ -564,6 +564,28 @@ TEST_CASE(contains)
564564 EXPECT (u" ab😀" sv.contains (u" 😀" sv));
565565}
566566
567+ TEST_CASE (contains_any_of)
568+ {
569+ EXPECT (!u" " sv.contains_any_of ({}));
570+ EXPECT (!u" a" sv.contains_any_of ({}));
571+
572+ EXPECT (u" a" sv.contains_any_of ({ { ' a' } }));
573+ EXPECT (u" a" sv.contains_any_of ({ { ' a' , ' b' } }));
574+ EXPECT (u" b" sv.contains_any_of ({ { ' a' , ' b' } }));
575+ EXPECT (!u" a" sv.contains_any_of ({ { ' b' } }));
576+ EXPECT (!u" b" sv.contains_any_of ({ { ' a' } }));
577+
578+ EXPECT (u" ab" sv.contains_any_of ({ { ' a' } }));
579+ EXPECT (u" ab" sv.contains_any_of ({ { ' b' } }));
580+ EXPECT (u" ab" sv.contains_any_of ({ { ' a' , ' b' } }));
581+ EXPECT (!u" ab" sv.contains_any_of ({ { ' c' } }));
582+
583+ EXPECT (!u" 😀" sv.contains_any_of ({ { 0xd83d } }));
584+ EXPECT (!u" 😀" sv.contains_any_of ({ { 0xde00 } }));
585+ EXPECT (u" 😀" sv.contains_any_of ({ { 0x1f600 } }));
586+ EXPECT (u" ab😀" sv.contains_any_of ({ { 0x1f600 } }));
587+ }
588+
567589TEST_CASE (count)
568590{
569591 EXPECT_EQ (u" " sv.count ({}), 0uz);
You can’t perform that action at this time.
0 commit comments