Add StringRef::rsplit(StringRef Separator) to achieve the function of getting the tail substring according to the separator. A typical usage is to get data in std::basic_string::data.
Details
Diff Detail
- Repository
- rL LLVM
- Build Status
Buildable 18618 Build 18618: arc lint + arc unit
Event Timeline
Hi @MTC, thanks for the patch.
With this patch, the logic for split would be duplicated 3 times now in StringRef.h. I think it'd be nice to reuse some code by moving the core logic into a private method of StringRef, say, splitAtIndex(size_t). Then, each (r)split(char | StringRef) can use the common helper.
Relatedly, an rsplit(char) overload seems to be missing here.
rsplit(char) already exists. That said, another way to reuse code would be
to have rsplit(char) call the StringRef version
This update consists of two parts
- Make rsplit(char) reuse rsplit(StringRef).
- Make split(char) reuse split(StringRef).
Do I need to divide the patch into two parts? One is to add rsplit(StringRef), the other is to refactor rsplit(char) and split(char).
First of all, sorry for the long delay!
Thanks for your review, @vsk! I do agree with you that there is need some work to remove the duplicates code. However I think zturner's approach is more neat, what do you think?
Thanks for your advice, @zturner! I have refactored split(char) and rsplit(char) to use StringRef version. I think the code is more clean now.
include/llvm/ADT/StringRef.h | ||
---|---|---|
758 | I can't decide if it would make more sense to have the "not found" case return a pair (LHS, RHS) where (LHS == "") && (*this == RHS)? What do you think? |
LGTM. Please wait to see if Zachary has any further feedback. Thanks!
include/llvm/ADT/StringRef.h | ||
---|---|---|
758 | I think this makes sense, but would make more sense as a follow-up commit. I don't think it needs to be a prerequisite for adding an rsplit overload. |
include/llvm/ADT/StringRef.h | ||
---|---|---|
758 | Yeah, I also think this is more reasonable.
If you all think this is more reasonable, I will give another patch to implement this. After all, current patch is for adding rsplit(StringRef). What do you think? |
I can't decide if it would make more sense to have the "not found" case return a pair (LHS, RHS) where (LHS == "") && (*this == RHS)? What do you think?