]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdb: add another overload of startswith
authorAndrew Burgess <aburgess@redhat.com>
Fri, 29 Dec 2023 09:00:51 +0000 (09:00 +0000)
committerAndrew Burgess <aburgess@redhat.com>
Sat, 7 Sep 2024 20:48:34 +0000 (21:48 +0100)
We already have one overload of the startswith function that takes a
std::string_view for both arguments.  A later patch in this series is
going to be improved by having an overload that takes one argument as
a std::string_view and the other argument as a plain 'char *'.

This commit adds the new overload, but doesn't make use of it (yet).
There should be no user visible changes after this commit.

gdbsupport/common-utils.h

index 23cd40c0207eeb9e089796dd0a0be75892b0a8ed..2fb2291640910c75aa4723546f7dd54ef7c85fd8 100644 (file)
@@ -100,6 +100,16 @@ startswith (std::string_view string, std::string_view pattern)
          && strncmp (string.data (), pattern.data (), pattern.length ()) == 0);
 }
 
+/* Version of startswith that takes a string_view for only one of its
+   arguments.  Return true if STR starts with PREFIX, otherwise return
+   false.  */
+
+static inline bool
+startswith (const char *str, const std::string_view &prefix)
+{
+  return strncmp (str, prefix.data (), prefix.length ()) == 0;
+}
+
 /* Return true if the strings are equal.  */
 
 static inline bool