From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 123930 invoked by alias); 1 Oct 2019 19:10:46 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 123922 invoked by uid 89); 1 Oct 2019 19:10:46 -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: us-smtp-1.mimecast.com Received: from us-smtp-delivery-1.mimecast.com (HELO us-smtp-1.mimecast.com) (205.139.110.120) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 01 Oct 2019 19:10:44 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1569957043; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=W3aI+fNQ0E4K6EW2+NHWU07s1CE66VkowwbpWR7HbmM=; b=VPWbZCEdAJ9qWlCeTe+OQcLolqPm/wrN2zK4O7rOM2VAvtv3GrExAYfiyLdP5QnoZpd63t +CJ+9+IcLT8eIKnOYN4Iyow5ZQ6AjMc/aL1JOkUaH4Dh/Js7CZvB0+Ih3DALFEVX9YJ/Q/ C0kkT7awqFhRGEEOXKek56dIxtCDgM0= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-182-QqJMitpOP9CxaTmjhPN9JQ-1; Tue, 01 Oct 2019 15:10:39 -0400 Received: by mail-wr1-f72.google.com with SMTP id h6so6389393wrh.6 for ; Tue, 01 Oct 2019 12:10:39 -0700 (PDT) Return-Path: Received: from ?IPv6:2001:8a0:f913:f700:56ee:75ff:fe8d:232b? ([2001:8a0:f913:f700:56ee:75ff:fe8d:232b]) by smtp.gmail.com with ESMTPSA id h17sm3345189wmb.33.2019.10.01.12.10.37 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 01 Oct 2019 12:10:37 -0700 (PDT) Subject: Re: [PATCH] Add a string_view version of startswith To: Christian Biesinger , gdb-patches@sourceware.org References: <20191001184450.223945-1-cbiesinger@google.com> From: Pedro Alves Message-ID: Date: Tue, 01 Oct 2019 19:10:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.2.1 MIME-Version: 1.0 In-Reply-To: <20191001184450.223945-1-cbiesinger@google.com> X-Mimecast-Spam-Score: 0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-SW-Source: 2019-10/txt/msg00035.txt.bz2 On 10/1/19 7:44 PM, Christian Biesinger via gdb-patches wrote: > diff --git a/gdb/gdbsupport/common-utils.h b/gdb/gdbsupport/common-utils.h > index a5312cb0c4..c21c5e9603 100644 > --- a/gdb/gdbsupport/common-utils.h > +++ b/gdb/gdbsupport/common-utils.h > @@ -23,6 +23,7 @@ > #include > #include >=20=20 > +#include "gdb_string_view.h" > #include "poison.h" >=20=20 > /* If possible, define FUNCTION_NAME, a macro containing the name of > @@ -113,12 +114,22 @@ extern char *safe_strerror (int); > /* Return non-zero if the start of STRING matches PATTERN, zero > otherwise. */ non-zero -> true zero -> false >=20=20 > -static inline int > +static inline bool > startswith (const char *string, const char *pattern) > { > return strncmp (string, pattern, strlen (pattern)) =3D=3D 0; > } >=20=20 > +/* 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() >=3D pattern.length () && > + strncmp (string.data (), pattern.data (), pattern.length ()) =3D=3D = 0; && goes on next line. And then you need to wrap the multiline expression with (), so that emacs auto-tab-indents the && under "string". Like this: return (string.length() >=3D pattern.length () && strncmp (string.data (), pattern.data (), pattern.length ()) = =3D=3D 0); Otherwise OK. Thanks, Pedro Alves