mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-24 03:33:20 +01:00
[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 llvm-svn: 281906
This commit is contained in:
parent
99a8836600
commit
d6c1a8aec3
@ -88,6 +88,10 @@ namespace llvm {
|
||||
/*implicit*/ StringRef(const std::string &Str)
|
||||
: Data(Str.data()), Length(Str.length()) {}
|
||||
|
||||
static StringRef withNullAsEmpty(const char *data) {
|
||||
return StringRef(data ? data : "");
|
||||
}
|
||||
|
||||
/// @}
|
||||
/// @name Iterators
|
||||
/// @{
|
||||
|
Loading…
Reference in New Issue
Block a user