From patchwork Tue Oct 22 22:14:40 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: 35236 Received: (qmail 72405 invoked by alias); 22 Oct 2019 22:14:45 -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 72396 invoked by uid 89); 22 Oct 2019 22:14:45 -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=20191001 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; Tue, 22 Oct 2019 22:14:44 +0000 Received: by mx1.osci.io (Postfix, from userid 994) id 7DF83204A2; Tue, 22 Oct 2019 18:14:42 -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 3A15120172; Tue, 22 Oct 2019 18:14:41 -0400 (EDT) Received: from localhost (localhost [127.0.0.1]) by gnutoolchain-gerrit.osci.io (Postfix) with ESMTP id 1015D2192E; Tue, 22 Oct 2019 18:14:41 -0400 (EDT) X-Gerrit-PatchSet: 3 Date: Tue, 22 Oct 2019 18:14:40 -0400 From: "Christian Biesinger (Code Review)" To: Christian Biesinger , gdb-patches@sourceware.org Auto-Submitted: auto-generated X-Gerrit-MessageType: newpatchset Subject: [review v3] Add a string_view version of startswith X-Gerrit-Change-Id: I5389855de2fd70e7065a789a79374b0693651b71 X-Gerrit-Change-Number: 126 X-Gerrit-ChangeURL: X-Gerrit-Commit: d441ce34f4d241a3a9cb4d246089af81b03cdacc In-Reply-To: References: Reply-To: cbiesinger@google.com, cbiesinger@google.com, gdb-patches@sourceware.org MIME-Version: 1.0 Content-Disposition: inline User-Agent: Gerrit/3.0.3 Message-Id: <20191022221441.1015D2192E@gnutoolchain-gerrit.osci.io> 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 * 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