summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZachary Turner <zturner@google.com>2016-09-19 15:34:51 +0000
committerZachary Turner <zturner@google.com>2016-09-19 15:34:51 +0000
commit47d5614967e9b756d4fb3408c8eae99b980fc7af (patch)
tree46ed6a03802aafc82b63eedcc490cd5cff669c22
parent9be72675169ba3644b5e004e4ba9e704e5651585 (diff)
downloadbcm5719-llvm-47d5614967e9b756d4fb3408c8eae99b980fc7af.tar.gz
bcm5719-llvm-47d5614967e9b756d4fb3408c8eae99b980fc7af.zip
[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
-rw-r--r--llvm/include/llvm/ADT/StringRef.h4
1 files changed, 4 insertions, 0 deletions
diff --git a/llvm/include/llvm/ADT/StringRef.h b/llvm/include/llvm/ADT/StringRef.h
index 37c214cdff7..5d0aafc4683 100644
--- a/llvm/include/llvm/ADT/StringRef.h
+++ b/llvm/include/llvm/ADT/StringRef.h
@@ -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
/// @{
OpenPOWER on IntegriCloud