This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[pushed] Add a string_view version of startswith
- From: "Sourceware to Gerrit sync (Code Review)" <gerrit at gnutoolchain-gerrit dot osci dot io>
- To: Christian Biesinger <cbiesinger at google dot com>, gdb-patches at sourceware dot org
- Cc: Simon Marchi <simon dot marchi at polymtl dot ca>, Tom Tromey <tromey at sourceware dot org>
- Date: Mon, 28 Oct 2019 13:22:19 -0400
- Subject: [pushed] Add a string_view version of startswith
- Auto-submitted: auto-generated
- References: <gerrit.1571229547000.I5389855de2fd70e7065a789a79374b0693651b71@gnutoolchain-gerrit.osci.io>
- Reply-to: noreply at gnutoolchain-gerrit dot osci dot io, simon dot marchi at polymtl dot ca, tromey at sourceware dot org, cbiesinger at google dot com, gdb-patches at sourceware dot org
Sourceware to Gerrit sync has submitted this change.
Change URL: https://gnutoolchain-gerrit.osci.io/r/c/binutils-gdb/+/126
......................................................................
Add a string_view version of startswith
Makes sure that the string is longer than prefix, so that strncmp will
do the right thing even if the string is not null-terminated.
For use in my string_view conversion patch:
https://sourceware.org/ml/gdb-patches/2019-10/msg00030.html
https://gnutoolchain-gerrit.osci.io/r/c/binutils-gdb/+/125
gdb/ChangeLog:
2019-10-28 Christian Biesinger <cbiesinger@google.com>
* gdbsupport/common-utils.h (startswith): Add an overloaded version
that takes gdb::string_view arguments.
Change-Id: I5389855de2fd70e7065a789a79374b0693651b71
---
M gdb/ChangeLog
M gdb/gdbsupport/common-utils.h
2 files changed, 17 insertions(+), 0 deletions(-)
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index edf7c34..7059623 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,8 @@
+2019-10-28 Christian Biesinger <cbiesinger@google.com>
+
+ * gdbsupport/common-utils.h (startswith): Add an overloaded version
+ that takes gdb::string_view arguments.
+
2019-10-26 Tom de Vries <tdevries@suse.de>
* aarch64-linux-tdep.c: Fix typos in comments.
diff --git a/gdb/gdbsupport/common-utils.h b/gdb/gdbsupport/common-utils.h
index e96fc21..23bf354 100644
--- a/gdb/gdbsupport/common-utils.h
+++ b/gdb/gdbsupport/common-utils.h
@@ -43,6 +43,8 @@
#endif
#endif
+#include "gdb_string_view.h"
+
/* xmalloc(), xrealloc() and xcalloc() have already been declared in
"libiberty.h". */
@@ -118,6 +120,16 @@
return strncmp (string, pattern, strlen (pattern)) == 0;
}
+/* Version of startswith that takes string_view arguments. See comment
+ above. */
+
+static inline bool
+startswith (gdb::string_view string, gdb::string_view pattern)
+{
+ return (string.length () >= pattern.length ()
+ && strncmp (string.data (), pattern.data (), pattern.length ()) == 0);
+}
+
ULONGEST strtoulst (const char *num, const char **trailer, int base);
/* Skip leading whitespace characters in INP, returning an updated
--
Gerrit-Project: binutils-gdb
Gerrit-Branch: master
Gerrit-Change-Id: I5389855de2fd70e7065a789a79374b0693651b71
Gerrit-Change-Number: 126
Gerrit-PatchSet: 5
Gerrit-Owner: Christian Biesinger <cbiesinger@google.com>
Gerrit-Reviewer: Christian Biesinger <cbiesinger@google.com>
Gerrit-Reviewer: Tom Tromey <tromey@sourceware.org>
Gerrit-CC: Simon Marchi <simon.marchi@polymtl.ca>
Gerrit-MessageType: merged