This is an archive of the discontinued LLVM Phabricator instance.

Add support for three more string_view functions
ClosedPublic

Authored by jeffbailey on Jul 12 2022, 11:02 PM.

Details

Summary

Add support for three more string_view functions

  1. starts_with(char)
  2. ends_with(char)
  3. find_first_of(char, size_t)

Reimplemented trim in terms of the new starts_with and ends_with.

Tested:
New unit tests.

Diff Detail

Event Timeline

jeffbailey created this revision.Jul 12 2022, 11:02 PM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptJul 12 2022, 11:02 PM
jeffbailey requested review of this revision.Jul 12 2022, 11:02 PM
gchatelet added inline comments.Jul 13 2022, 1:33 AM
libc/src/__support/CPP/StringView.h
127–130

once we have starts_with and ends_with this can be rewritten as:

while (Copy.starts_with(C))
  Copy = Copy.drop_front();
while (Copy.ends_with(C))
  Copy = Copy.drop_back();
140–143

Let's express this as !empty() && front() == Prefix

155

Do you want to add the ends_with function for symmetry?

Add new ends_with, unit tests, reimplement trim.

jeffbailey retitled this revision from Add support for two more string_view functions to Add support for three more string_view functions.Jul 13 2022, 10:43 PM
jeffbailey edited the summary of this revision. (Show Details)
jeffbailey marked 3 inline comments as done.

PTAL

gchatelet accepted this revision.Jul 14 2022, 1:10 AM
This revision is now accepted and ready to land.Jul 14 2022, 1:10 AM
This revision was automatically updated to reflect the committed changes.

Suggestion for next time: When the patch touches only the libc directory, we should prefix the subject line with [libc] . Sorry for not noticing it on this patch.

Suggestion for next time: When the patch touches only the libc directory, we should prefix the subject line with [libc] . Sorry for not noticing it on this patch.

Will do. Is there any way to add that in a presubmit? That seems like something that might be difficult to remember as we scale.