From patchwork Mon Oct 28 17:22:19 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Simon Marchi (Code Review)" X-Patchwork-Id: 35401 Received: (qmail 106062 invoked by alias); 28 Oct 2019 17:22:27 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 105960 invoked by uid 89); 28 Oct 2019 17:22:26 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3 autolearn=ham version=3.3.1 spammy= X-HELO: mx1.osci.io Received: from polly.osci.io (HELO mx1.osci.io) (8.43.85.229) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 28 Oct 2019 17:22:25 +0000 Received: by mx1.osci.io (Postfix, from userid 994) id 72DCF20E95; Mon, 28 Oct 2019 13:22:23 -0400 (EDT) Received: from gnutoolchain-gerrit.osci.io (gnutoolchain-gerrit.osci.io [IPv6:2620:52:3:1:5054:ff:fe06:16ca]) by mx1.osci.io (Postfix) with ESMTP id BA92F20E5E; Mon, 28 Oct 2019 13:22:19 -0400 (EDT) Received: from localhost (localhost [127.0.0.1]) by gnutoolchain-gerrit.osci.io (Postfix) with ESMTP id A629F20AF6; Mon, 28 Oct 2019 13:22:19 -0400 (EDT) X-Gerrit-PatchSet: 5 Date: Mon, 28 Oct 2019 13:22:19 -0400 From: "Sourceware to Gerrit sync (Code Review)" To: Christian Biesinger , gdb-patches@sourceware.org Cc: Simon Marchi , Tom Tromey Auto-Submitted: auto-generated X-Gerrit-MessageType: merged Subject: [pushed] Add a string_view version of startswith X-Gerrit-Change-Id: I5389855de2fd70e7065a789a79374b0693651b71 X-Gerrit-Change-Number: 126 X-Gerrit-ChangeURL: X-Gerrit-Commit: 87f34879e5339be458505ca85f70cff346295140 In-Reply-To: References: Reply-To: noreply@gnutoolchain-gerrit.osci.io, simon.marchi@polymtl.ca, tromey@sourceware.org, cbiesinger@google.com, gdb-patches@sourceware.org MIME-Version: 1.0 Content-Disposition: inline User-Agent: Gerrit/3.0.3-74-g460fb0f7e9 Message-Id: <20191028172219.A629F20AF6@gnutoolchain-gerrit.osci.io> 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 * 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 + + * gdbsupport/common-utils.h (startswith): Add an overloaded version + that takes gdb::string_view arguments. + 2019-10-26 Tom de Vries * 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