[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[groff] 08/13: src/libs/libgroff/string.cpp: Fix code style nits.
From: |
G. Branden Robinson |
Subject: |
[groff] 08/13: src/libs/libgroff/string.cpp: Fix code style nits. |
Date: |
Mon, 7 Oct 2024 08:00:15 -0400 (EDT) |
gbranden pushed a commit to branch master
in repository groff.
commit 4fbef69e5f1a55b23523069ba7f9f0994957c3ea
Author: G. Branden Robinson <g.branden.robinson@gmail.com>
AuthorDate: Sun Oct 6 12:15:13 2024 -0500
src/libs/libgroff/string.cpp: Fix code style nits.
* src/libs/libgroff/string.cpp (string::search): `const`-ify argument
and local variable. Use C++ `static_cast` operator instead of C-style
type cast. Explicitly compare variable of pointer type to null
pointer literal instead of letting it pun down to a Boolean.
Parenthesize complex expression.
Also annotate null pointer with `nullptr` comment to ease any future
transition to C++11, which defines it as a keyword.
---
ChangeLog | 6 ++++++
src/libs/libgroff/string.cpp | 8 +++++---
2 files changed, 11 insertions(+), 3 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index dd9e7bc9b..751d8681f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -3,6 +3,12 @@
* src/include/stringclass.h (class string): Fix code style nit:
`const`-ify argument to `search` public member function.
+ * src/libs/libgroff/string.cpp (string::search): `const`-ify
+ argument and local variable. Use C++ `static_cast` operator
+ instead of C-style type cast. Explicitly compare variable of
+ pointer type to null pointer literal instead of letting it pun
+ down to a Boolean. Parenthesize complex expression.
+
2024-10-05 G. Branden Robinson <g.branden.robinson@gmail.com>
* src/roff/troff/reg.cpp (dump_register): Remove garbage from
diff --git a/src/libs/libgroff/string.cpp b/src/libs/libgroff/string.cpp
index b62e131bb..d1bd97243 100644
--- a/src/libs/libgroff/string.cpp
+++ b/src/libs/libgroff/string.cpp
@@ -276,10 +276,12 @@ void string::clear()
len = 0;
}
-int string::search(char c) const
+int string::search(const char c) const
{
- char *p = ptr ? (char *)memchr(ptr, c, len) : 0;
- return p ? p - ptr : -1;
+ const char *p = ptr
+ ? static_cast<const char *>(memchr(ptr, c, len))
+ : 0 /* nullptr */;
+ return (p != 0 /* nullptr */) ? (p - ptr) : -1;
}
// we silently strip nuls
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [groff] 08/13: src/libs/libgroff/string.cpp: Fix code style nits.,
G. Branden Robinson <=