This is an archive of the discontinued LLVM Phabricator instance.

Add StringRef::find_lower and contains_lower
ClosedPublic

Authored by zturner on Oct 5 2016, 5:37 PM.

Details

Summary

These are replacements for the standard C api strcasestr().

I chose to implement this by allocating two copies on the heap and then using existing code. But I could also implement this using an M*N loop if you think that's preferable. Neither way is ideal, but there isn't exactly a fast way to implement this.

Diff Detail

Repository
rL LLVM

Event Timeline

zturner updated this revision to Diff 73714.Oct 5 2016, 5:37 PM
zturner retitled this revision from to Add StringRef::find_lower and contains_lower.
zturner updated this object.
zturner added a reviewer: chandlerc.
zturner added a subscriber: llvm-commits.
chandlerc edited edge metadata.Oct 5 2016, 11:51 PM

Why not implement find_lower the same way find is implemented? It doesn't seem too hard? Just define a local version of memcmp that does ascii_tolower on each character before comparing and doing the same thing prior to inserting into the skip table or looking up a skip distance in it?

Could try to share the code if you really want with a templated helper that calls a passed-in callable on each character, but doesn't really seem worth it to me.

zturner updated this revision to Diff 73821.Oct 6 2016, 10:44 AM
zturner edited edge metadata.

Actually I don't see why we shouldn't just use startswith_lower. It basically does exactly what you're saying. Updated the code to use this approach. While I'm in here, I think we might as well add rfind_lower to maintain API symmetry, so I went ahead and did that too.

This revision was automatically updated to reflect the committed changes.