From: Pedro Alves <palves@redhat.com>
To: Christian Biesinger <cbiesinger@google.com>, gdb-patches@sourceware.org
Subject: Re: [PATCH] Add a string_view version of startswith
Date: Tue, 01 Oct 2019 19:10:00 -0000 [thread overview]
Message-ID: <d91daa4c-b4ce-4ad6-8ebf-f10245881431@redhat.com> (raw)
In-Reply-To: <20191001184450.223945-1-cbiesinger@google.com>
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 <string>
> #include <vector>
>
> +#include "gdb_string_view.h"
> #include "poison.h"
>
> /* 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
>
> -static inline int
> +static inline bool
> startswith (const char *string, const char *pattern)
> {
> 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;
&& 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() >= pattern.length ()
&& strncmp (string.data (), pattern.data (), pattern.length ()) == 0);
Otherwise OK.
Thanks,
Pedro Alves
next prev parent reply other threads:[~2019-10-01 19:10 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-10-01 18:44 Christian Biesinger via gdb-patches
2019-10-01 19:10 ` Pedro Alves [this message]
2019-10-01 19:17 ` Christian Biesinger via gdb-patches
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=d91daa4c-b4ce-4ad6-8ebf-f10245881431@redhat.com \
--to=palves@redhat.com \
--cc=cbiesinger@google.com \
--cc=gdb-patches@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