summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYi Kong2018-07-16 20:11:34 -0500
committerYi Kong2018-07-16 20:11:34 -0500
commite1731a4f2e05f1abb4a45602067708851eaf1e14 (patch)
tree339c0ce3d3de7d6f5e0fb9bdada9b6210d1d470f /libutils/String8.cpp
parent895acebe946e34d2626716c5c4d7d7f2cc28c39d (diff)
downloadplatform-system-core-e1731a4f2e05f1abb4a45602067708851eaf1e14.tar.gz
platform-system-core-e1731a4f2e05f1abb4a45602067708851eaf1e14.tar.xz
platform-system-core-e1731a4f2e05f1abb4a45602067708851eaf1e14.zip
[libutils] Modernize codebase by replacing NULL with nullptr
Fixes -Wzero-as-null-pointer-constant warning. Test: m Bug: 68236239 Change-Id: I5e89ec8c42151875439d2656475a8739ab9cb7dc
Diffstat (limited to 'libutils/String8.cpp')
-rw-r--r--libutils/String8.cpp30
1 files changed, 15 insertions, 15 deletions
diff --git a/libutils/String8.cpp b/libutils/String8.cpp
index 580e870c7..8d318f77f 100644
--- a/libutils/String8.cpp
+++ b/libutils/String8.cpp
@@ -58,7 +58,7 @@ static char* allocFromUTF8(const char* in, size_t len)
58{ 58{
59 if (len > 0) { 59 if (len > 0) {
60 if (len == SIZE_MAX) { 60 if (len == SIZE_MAX) {
61 return NULL; 61 return nullptr;
62 } 62 }
63 SharedBuffer* buf = SharedBuffer::alloc(len+1); 63 SharedBuffer* buf = SharedBuffer::alloc(len+1);
64 ALOG_ASSERT(buf, "Unable to allocate shared buffer"); 64 ALOG_ASSERT(buf, "Unable to allocate shared buffer");
@@ -68,7 +68,7 @@ static char* allocFromUTF8(const char* in, size_t len)
68 str[len] = 0; 68 str[len] = 0;
69 return str; 69 return str;
70 } 70 }
71 return NULL; 71 return nullptr;
72 } 72 }
73 73
74 return getEmptyString(); 74 return getEmptyString();
@@ -126,7 +126,7 @@ String8::String8()
126} 126}
127 127
128String8::String8(StaticLinkage) 128String8::String8(StaticLinkage)
129 : mString(0) 129 : mString(nullptr)
130{ 130{
131 // this constructor is used when we can't rely on the static-initializers 131 // this constructor is used when we can't rely on the static-initializers
132 // having run. In this case we always allocate an empty string. It's less 132 // having run. In this case we always allocate an empty string. It's less
@@ -147,7 +147,7 @@ String8::String8(const String8& o)
147String8::String8(const char* o) 147String8::String8(const char* o)
148 : mString(allocFromUTF8(o, strlen(o))) 148 : mString(allocFromUTF8(o, strlen(o)))
149{ 149{
150 if (mString == NULL) { 150 if (mString == nullptr) {
151 mString = getEmptyString(); 151 mString = getEmptyString();
152 } 152 }
153} 153}
@@ -155,7 +155,7 @@ String8::String8(const char* o)
155String8::String8(const char* o, size_t len) 155String8::String8(const char* o, size_t len)
156 : mString(allocFromUTF8(o, len)) 156 : mString(allocFromUTF8(o, len))
157{ 157{
158 if (mString == NULL) { 158 if (mString == nullptr) {
159 mString = getEmptyString(); 159 mString = getEmptyString();
160 } 160 }
161} 161}
@@ -319,7 +319,7 @@ status_t String8::appendFormatV(const char* fmt, va_list args)
319 * second vsnprintf access undefined args. 319 * second vsnprintf access undefined args.
320 */ 320 */
321 va_copy(tmp_args, args); 321 va_copy(tmp_args, args);
322 n = vsnprintf(NULL, 0, fmt, tmp_args); 322 n = vsnprintf(nullptr, 0, fmt, tmp_args);
323 va_end(tmp_args); 323 va_end(tmp_args);
324 324
325 if (n != 0) { 325 if (n != 0) {
@@ -360,7 +360,7 @@ char* String8::lockBuffer(size_t size)
360 mString = str; 360 mString = str;
361 return str; 361 return str;
362 } 362 }
363 return NULL; 363 return nullptr;
364} 364}
365 365
366void String8::unlockBuffer() 366void String8::unlockBuffer()
@@ -512,7 +512,7 @@ String8 String8::getPathLeaf(void) const
512 const char*const buf = mString; 512 const char*const buf = mString;
513 513
514 cp = strrchr(buf, OS_PATH_SEPARATOR); 514 cp = strrchr(buf, OS_PATH_SEPARATOR);
515 if (cp == NULL) 515 if (cp == nullptr)
516 return String8(*this); 516 return String8(*this);
517 else 517 else
518 return String8(cp+1); 518 return String8(cp+1);
@@ -524,7 +524,7 @@ String8 String8::getPathDir(void) const
524 const char*const str = mString; 524 const char*const str = mString;
525 525
526 cp = strrchr(str, OS_PATH_SEPARATOR); 526 cp = strrchr(str, OS_PATH_SEPARATOR);
527 if (cp == NULL) 527 if (cp == nullptr)
528 return String8(""); 528 return String8("");
529 else 529 else
530 return String8(str, cp - str); 530 return String8(str, cp - str);
@@ -543,7 +543,7 @@ String8 String8::walkPath(String8* outRemains) const
543 cp = strchr(buf, OS_PATH_SEPARATOR); 543 cp = strchr(buf, OS_PATH_SEPARATOR);
544 } 544 }
545 545
546 if (cp == NULL) { 546 if (cp == nullptr) {
547 String8 res = buf != str ? String8(buf) : *this; 547 String8 res = buf != str ? String8(buf) : *this;
548 if (outRemains) *outRemains = String8(""); 548 if (outRemains) *outRemains = String8("");
549 return res; 549 return res;
@@ -567,15 +567,15 @@ char* String8::find_extension(void) const
567 567
568 // only look at the filename 568 // only look at the filename
569 lastSlash = strrchr(str, OS_PATH_SEPARATOR); 569 lastSlash = strrchr(str, OS_PATH_SEPARATOR);
570 if (lastSlash == NULL) 570 if (lastSlash == nullptr)
571 lastSlash = str; 571 lastSlash = str;
572 else 572 else
573 lastSlash++; 573 lastSlash++;
574 574
575 // find the last dot 575 // find the last dot
576 lastDot = strrchr(lastSlash, '.'); 576 lastDot = strrchr(lastSlash, '.');
577 if (lastDot == NULL) 577 if (lastDot == nullptr)
578 return NULL; 578 return nullptr;
579 579
580 // looks good, ship it 580 // looks good, ship it
581 return const_cast<char*>(lastDot); 581 return const_cast<char*>(lastDot);
@@ -586,7 +586,7 @@ String8 String8::getPathExtension(void) const
586 char* ext; 586 char* ext;
587 587
588 ext = find_extension(); 588 ext = find_extension();
589 if (ext != NULL) 589 if (ext != nullptr)
590 return String8(ext); 590 return String8(ext);
591 else 591 else
592 return String8(""); 592 return String8("");
@@ -598,7 +598,7 @@ String8 String8::getBasePath(void) const
598 const char* const str = mString; 598 const char* const str = mString;
599 599
600 ext = find_extension(); 600 ext = find_extension();
601 if (ext == NULL) 601 if (ext == nullptr)
602 return String8(*this); 602 return String8(*this);
603 else 603 else
604 return String8(str, ext - str); 604 return String8(str, ext - str);