Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: "Tom Tromey (Code Review)" <gerrit@gnutoolchain-gerrit.osci.io>
To: Christian Biesinger <cbiesinger@google.com>,	gdb-patches@sourceware.org
Cc: Simon Marchi <simon.marchi@polymtl.ca>
Subject: [review v4] Add a string_view version of startswith
Date: Sun, 27 Oct 2019 21:44:00 -0000	[thread overview]
Message-ID: <20191027214424.15FAE20AF6@gnutoolchain-gerrit.osci.io> (raw)
In-Reply-To: <gerrit.1571229547000.I5389855de2fd70e7065a789a79374b0693651b71@gnutoolchain-gerrit.osci.io>

The original change was created by Christian Biesinger.

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

gdb/ChangeLog:

2019-10-01  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/gdbsupport/common-utils.h
1 file changed, 12 insertions(+), 0 deletions(-)



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: 4
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: newpatchset


  parent reply	other threads:[~2019-10-27 21:44 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-16 12:39 [review] " Christian Biesinger (Code Review)
2019-10-22 19:12 ` [review v2] " Christian Biesinger (Code Review)
2019-10-22 22:14 ` [review v3] " Christian Biesinger (Code Review)
2019-10-25 17:35 ` Tom Tromey (Code Review)
2019-10-26 23:11 ` Tom Tromey (Code Review)
2019-10-27  1:46   ` Simon Marchi
2019-10-27  1:46 ` Simon Marchi (2) (Code Review)
2019-10-27  1:49 ` Simon Marchi (Code Review)
2019-10-27 18:23 ` Christian Biesinger (Code Review)
2019-10-27 21:44 ` Tom Tromey (Code Review) [this message]
2019-10-27 22:10 ` [review v4] " Simon Marchi (Code Review)
2019-10-28 17:20 ` Christian Biesinger (Code Review)
2019-10-28 17:22 ` [pushed] " Sourceware to Gerrit sync (Code Review)
2019-10-28 17:22 ` Sourceware to Gerrit sync (Code Review)

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20191027214424.15FAE20AF6@gnutoolchain-gerrit.osci.io \
    --to=gerrit@gnutoolchain-gerrit.osci.io \
    --cc=cbiesinger@google.com \
    --cc=gdb-patches@sourceware.org \
    --cc=simon.marchi@polymtl.ca \
    --cc=tromey@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox