This is an automated email from the ASF dual-hosted git repository.

wwbmmm pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/brpc.git


The following commit(s) were added to refs/heads/master by this push:
     new 9f9b62f6 Refactor NULL with nullptr in butil/strings (#3442)
9f9b62f6 is described below

commit 9f9b62f68369326d970d484493b5165deec75516
Author: Bright Chen <[email protected]>
AuthorDate: Sat Aug 15 13:56:33 2026 +0800

    Refactor NULL with nullptr in butil/strings (#3442)
---
 src/butil/strings/safe_sprintf.cc                  |  8 ++++----
 src/butil/strings/string_number_conversions.cc     |  2 +-
 src/butil/strings/string_piece.h                   | 12 ++++++------
 src/butil/strings/string_util.cc                   |  4 ++--
 src/butil/strings/string_util.h                    |  6 +++---
 src/butil/strings/stringprintf.cc                  |  2 +-
 src/butil/strings/sys_string_conversions.h         |  2 +-
 src/butil/strings/sys_string_conversions_mac.mm    |  8 ++++----
 src/butil/strings/sys_string_conversions_posix.cc  |  4 ++--
 src/butil/strings/utf_offset_string_conversions.cc |  2 +-
 src/butil/strings/utf_offset_string_conversions.h  |  2 +-
 11 files changed, 26 insertions(+), 26 deletions(-)

diff --git a/src/butil/strings/safe_sprintf.cc 
b/src/butil/strings/safe_sprintf.cc
index 09c5abd8..cb54f730 100644
--- a/src/butil/strings/safe_sprintf.cc
+++ b/src/butil/strings/safe_sprintf.cc
@@ -315,7 +315,7 @@ bool Buffer::IToASCII(bool sign, bool upcase, int64_t i, 
int base,
   // We cannot choose the easier approach of just reversing the number, as that
   // fails in situations where we need to truncate numbers that have padding
   // and/or prefixes.
-  const char* reverse_prefix = NULL;
+  const char* reverse_prefix = nullptr;
   if (prefix && *prefix) {
     if (pad == '0') {
       while (*prefix) {
@@ -324,13 +324,13 @@ bool Buffer::IToASCII(bool sign, bool upcase, int64_t i, 
int base,
         }
         Out(*prefix++);
       }
-      prefix = NULL;
+      prefix = nullptr;
     } else {
       for (reverse_prefix = prefix; *reverse_prefix; ++reverse_prefix) {
       }
     }
   } else
-    prefix = NULL;
+    prefix = nullptr;
   const size_t prefix_length = reverse_prefix - prefix;
 
   // Loop until we have converted the entire number. Output at least one
@@ -527,7 +527,7 @@ ssize_t SafeSNPrintf(char* buf, size_t sz, const char* fmt, 
const Arg* args,
 
         const Arg& arg = args[cur_arg++];
         int64_t i;
-        const char* prefix = NULL;
+        const char* prefix = nullptr;
         if (ch != 'p') {
           // Check that the argument has the expected type.
           if (arg.type != Arg::INT && arg.type != Arg::UINT) {
diff --git a/src/butil/strings/string_number_conversions.cc 
b/src/butil/strings/string_number_conversions.cc
index bcf3f49c..0b6cd4ea 100644
--- a/src/butil/strings/string_number_conversions.cc
+++ b/src/butil/strings/string_number_conversions.cc
@@ -437,7 +437,7 @@ bool StringToDouble(const std::string& input, double* 
output) {
   // Thread-safe?  It is on at least Mac, Linux, and Windows.
   ScopedClearErrno clear_errno;
 
-  char* endptr = NULL;
+  char* endptr = nullptr;
   *output = dmg_fp::strtod(input.c_str(), &endptr);
 
   // Cases to return false:
diff --git a/src/butil/strings/string_piece.h b/src/butil/strings/string_piece.h
index 808ccbb1..d0e01730 100644
--- a/src/butil/strings/string_piece.h
+++ b/src/butil/strings/string_piece.h
@@ -187,10 +187,10 @@ template <typename STRING_TYPE> class BasicStringPiece {
   // We provide non-explicit singleton constructors so users can pass
   // in a "const char*" or a "string" wherever a "StringPiece" is
   // expected (likewise for char16, string16, StringPiece16).
-  BasicStringPiece() : ptr_(NULL), length_(0) {}
+  BasicStringPiece() : ptr_(nullptr), length_(0) {}
   BasicStringPiece(const value_type* str)
       : ptr_(str),
-        length_((str == NULL) ? 0 : STRING_TYPE::traits_type::length(str)) {}
+        length_((str == nullptr) ? 0 : STRING_TYPE::traits_type::length(str)) 
{}
 #if __cplusplus >= 201703L
   BasicStringPiece(
     const std::basic_string_view<value_type, typename 
STRING_TYPE::traits_type>& str)
@@ -204,7 +204,7 @@ template <typename STRING_TYPE> class BasicStringPiece {
       : ptr_(str.data() + pos), length_(std::min(len, str.length() - pos)) {}
   BasicStringPiece(const typename STRING_TYPE::const_iterator& begin,
                     const typename STRING_TYPE::const_iterator& end)
-      : ptr_((end > begin) ? &(*begin) : NULL),
+      : ptr_((end > begin) ? &(*begin) : nullptr),
         length_((end > begin) ? (size_type)(end - begin) : 0) {}
 
   // data() may return a pointer to a buffer with embedded NULs, and the
@@ -217,7 +217,7 @@ template <typename STRING_TYPE> class BasicStringPiece {
   bool empty() const { return length_ == 0; }
 
   void clear() {
-    ptr_ = NULL;
+    ptr_ = nullptr;
     length_ = 0;
   }
   BasicStringPiece& assign(const BasicStringPiece& str, size_type pos, 
size_type len = npos) {
@@ -266,7 +266,7 @@ template <typename STRING_TYPE> class BasicStringPiece {
   }
 
   STRING_TYPE as_string() const {
-    // std::string doesn't like to take a NULL pointer even with a 0 size.
+    // std::string doesn't like to take a nullptr pointer even with a 0 size.
     return empty() ? STRING_TYPE() : STRING_TYPE(data(), size());
   }
 
@@ -391,7 +391,7 @@ template <typename STRING_TYPE> class BasicStringPiece {
 
   // Converts to `std::basic_string`.
   explicit operator STRING_TYPE() const {
-    if (NULL == data()) {
+    if (nullptr == data()) {
       return {};
     }
     return STRING_TYPE(data(), size());
diff --git a/src/butil/strings/string_util.cc b/src/butil/strings/string_util.cc
index b7ec353d..ed0a632c 100644
--- a/src/butil/strings/string_util.cc
+++ b/src/butil/strings/string_util.cc
@@ -733,7 +733,7 @@ template <typename CHAR, typename NEXT>
 static void EatSameChars(const CHAR** pattern, const CHAR* pattern_end,
                          const CHAR** string, const CHAR* string_end,
                          NEXT next) {
-  const CHAR* escape = NULL;
+  const CHAR* escape = nullptr;
   while (*pattern != pattern_end && *string != string_end) {
     if (!escape && IsWildcard(**pattern)) {
       // We don't want to match wildcard here, except if it's escaped.
@@ -768,7 +768,7 @@ static void EatSameChars(const CHAR** pattern, const CHAR* 
pattern_end,
       return;
     }
 
-    escape = NULL;
+    escape = nullptr;
   }
 }
 
diff --git a/src/butil/strings/string_util.h b/src/butil/strings/string_util.h
index bd3328a7..1c2c120d 100644
--- a/src/butil/strings/string_util.h
+++ b/src/butil/strings/string_util.h
@@ -394,7 +394,7 @@ inline Char HexDigitToInt(Char c) {
 
 // Returns true if it's a whitespace character.
 inline bool IsWhitespace(wchar_t c) {
-  return wcschr(butil::kWhitespaceWide, c) != NULL;
+  return wcschr(butil::kWhitespaceWide, c) != nullptr;
 }
 
 inline bool IsBlankString(const butil::StringPiece &s) {
@@ -497,7 +497,7 @@ BUTIL_EXPORT butil::string16 JoinString(
 // Replace $1-$2-$3..$9 in the format string with |a|-|b|-|c|..|i| 
respectively.
 // Additionally, any number of consecutive '$' characters is replaced by that
 // number less one. Eg $$->$, $$$->$$, etc. The offsets parameter here can be
-// NULL. This only allows you to use up to nine replacements.
+// nullptr. This only allows you to use up to nine replacements.
 BUTIL_EXPORT butil::string16 ReplaceStringPlaceholders(
     const butil::string16& format_string,
     const std::vector<butil::string16>& subst,
@@ -508,7 +508,7 @@ BUTIL_EXPORT std::string ReplaceStringPlaceholders(
     const std::vector<std::string>& subst,
     std::vector<size_t>* offsets);
 
-// Single-string shortcut for ReplaceStringHolders. |offset| may be NULL.
+// Single-string shortcut for ReplaceStringHolders. |offset| may be nullptr.
 BUTIL_EXPORT butil::string16 ReplaceStringPlaceholders(
     const butil::string16& format_string,
     const butil::string16& a,
diff --git a/src/butil/strings/stringprintf.cc 
b/src/butil/strings/stringprintf.cc
index 0ca6366c..3c8dbba8 100644
--- a/src/butil/strings/stringprintf.cc
+++ b/src/butil/strings/stringprintf.cc
@@ -10,7 +10,7 @@
 #include "butil/strings/string_util.h"
 #include "butil/strings/utf_string_conversions.h"
 
-// gcc7 reports that the first arg to vsnprintfT in StringAppendVT is NULL,
+// gcc7 reports that the first arg to vsnprintfT in StringAppendVT is nullptr,
 // which I can't figure out why, turn off the warning right now.
 #if defined(__GNUC__) && __GNUC__ >= 7
 #pragma GCC diagnostic warning "-Wformat-truncation=0"
diff --git a/src/butil/strings/sys_string_conversions.h 
b/src/butil/strings/sys_string_conversions.h
index 7316c5e7..03be67ee 100644
--- a/src/butil/strings/sys_string_conversions.h
+++ b/src/butil/strings/sys_string_conversions.h
@@ -59,7 +59,7 @@ BUTIL_EXPORT std::string SysWideToMultiByte(const 
std::wstring& wide,
 // Converts between STL strings and CFStringRefs/NSStrings.
 
 // Creates a string, and returns it with a refcount of 1. You are responsible
-// for releasing it. Returns NULL on failure.
+// for releasing it. Returns nullptr on failure.
 BUTIL_EXPORT CFStringRef SysUTF8ToCFStringRef(const std::string& utf8);
 BUTIL_EXPORT CFStringRef SysUTF16ToCFStringRef(const string16& utf16);
 
diff --git a/src/butil/strings/sys_string_conversions_mac.mm 
b/src/butil/strings/sys_string_conversions_mac.mm
index 804b6142..26151f99 100644
--- a/src/butil/strings/sys_string_conversions_mac.mm
+++ b/src/butil/strings/sys_string_conversions_mac.mm
@@ -34,7 +34,7 @@ static StringType 
CFStringToSTLStringWithEncodingT(CFStringRef cfstring,
                                        encoding,
                                        0,      // lossByte
                                        false,  // isExternalRepresentation
-                                       NULL,   // buffer
+                                       nullptr,   // buffer
                                        0,      // maxBufLen
                                        &out_size);
   if (converted == 0 || out_size == 0)
@@ -56,7 +56,7 @@ static StringType 
CFStringToSTLStringWithEncodingT(CFStringRef cfstring,
                                false,  // isExternalRepresentation
                                reinterpret_cast<UInt8*>(&out_buffer[0]),
                                out_size,
-                               NULL);  // usedBufLen
+                               nullptr);  // usedBufLen
   if (converted == 0)
     return StringType();
 
@@ -79,7 +79,7 @@ static OutStringType STLStringToSTLStringWithEncodingsT(
     return OutStringType();
 
   butil::ScopedCFTypeRef<CFStringRef> cfstring(CFStringCreateWithBytesNoCopy(
-      NULL,
+      nullptr,
       reinterpret_cast<const UInt8*>(in.data()),
       in_length * sizeof(typename InStringType::value_type),
       in_encoding,
@@ -93,7 +93,7 @@ static OutStringType STLStringToSTLStringWithEncodingsT(
 }
 
 // Given an STL string |in| with an encoding specified by |in_encoding|,
-// return it as a CFStringRef.  Returns NULL on failure.
+// return it as a CFStringRef.  Returns nullptr on failure.
 template<typename StringType>
 static CFStringRef STLStringToCFStringWithEncodingsT(
     const StringType& in,
diff --git a/src/butil/strings/sys_string_conversions_posix.cc 
b/src/butil/strings/sys_string_conversions_posix.cc
index 1255b4d6..b678a72c 100644
--- a/src/butil/strings/sys_string_conversions_posix.cc
+++ b/src/butil/strings/sys_string_conversions_posix.cc
@@ -48,7 +48,7 @@ std::string SysWideToNativeMB(const std::wstring& wide) {
   memset(&ps, 0, sizeof(ps));
   for (size_t i = 0; i < wide.size(); ++i) {
     const wchar_t src = wide[i];
-    // Use a temp buffer since calling wcrtomb with an output of NULL does not
+    // Use a temp buffer since calling wcrtomb with an output of nullptr does 
not
     // calculate the output length.
     char buf[16];
     // Skip NULLs to avoid wcrtomb's special handling of them.
@@ -108,7 +108,7 @@ std::wstring SysNativeMBToWide(const StringPiece& 
native_mb) {
   memset(&ps, 0, sizeof(ps));
   for (size_t i = 0; i < native_mb.size(); ) {
     const char* src = native_mb.data() + i;
-    size_t res = mbrtowc(NULL, src, native_mb.size() - i, &ps);
+    size_t res = mbrtowc(nullptr, src, native_mb.size() - i, &ps);
     switch (res) {
       // Handle any errors and return an empty string.
       case static_cast<size_t>(-2):
diff --git a/src/butil/strings/utf_offset_string_conversions.cc 
b/src/butil/strings/utf_offset_string_conversions.cc
index 2981059b..75994208 100644
--- a/src/butil/strings/utf_offset_string_conversions.cc
+++ b/src/butil/strings/utf_offset_string_conversions.cc
@@ -176,7 +176,7 @@ void OffsetAdjuster::MergeSequentialAdjustments(
 // Converts the given source Unicode character type to the given destination
 // Unicode character type as a STL string. The given input buffer and size
 // determine the source, and the given output STL string will be replaced by
-// the result.  If non-NULL, |adjustments| is set to reflect the all the
+// the result.  If non-nullptr, |adjustments| is set to reflect the all the
 // alterations to the string that are not one-character-to-one-character.
 // It will always be sorted by increasing offset.
 template<typename SrcChar, typename DestStdString>
diff --git a/src/butil/strings/utf_offset_string_conversions.h 
b/src/butil/strings/utf_offset_string_conversions.h
index 4984900f..80abb262 100644
--- a/src/butil/strings/utf_offset_string_conversions.h
+++ b/src/butil/strings/utf_offset_string_conversions.h
@@ -85,7 +85,7 @@ class BUTIL_EXPORT OffsetAdjuster {
 
 // Like the conversions in utf_string_conversions.h, but also fills in an
 // |adjustments| parameter that reflects the alterations done to the string.
-// It may be NULL.
+// It may be nullptr.
 BUTIL_EXPORT bool UTF8ToUTF16WithAdjustments(
     const char* src,
     size_t src_len,


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to