Skip to content
This repository was archived by the owner on Mar 28, 2020. It is now read-only.

Commit 781fb6e

Browse files
author
Zachary Turner
committed
[Support] Add StringRef::withNullAsEmpty()
When porting large bodies of code from using const char* to StringRef, it is helpful to be able to treat nullptr as an empty string, since that it is often what it is used to indicate in C-style code. Differential Revision: https://reviews.llvm.org/D24697 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@281906 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent ebd2807 commit 781fb6e

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

include/llvm/ADT/StringRef.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,10 @@ namespace llvm {
8888
/*implicit*/ StringRef(const std::string &Str)
8989
: Data(Str.data()), Length(Str.length()) {}
9090

91+
static StringRef withNullAsEmpty(const char *data) {
92+
return StringRef(data ? data : "");
93+
}
94+
9195
/// @}
9296
/// @name Iterators
9397
/// @{

0 commit comments

Comments
 (0)