aboutsummaryrefslogtreecommitdiff
path: root/gdb/linespec.c
diff options
context:
space:
mode:
authorGary Benson <gbenson@redhat.com>2015-03-06 09:42:06 +0000
committerGary Benson <gbenson@redhat.com>2015-03-06 09:42:06 +0000
commit61012eef8463764ccd9117dc1c9bc43cc452b7cc (patch)
treef576a77bcb77e71cc60e6592b56d2aa915b50c36 /gdb/linespec.c
parente80417caef36c7d5e3d1da6a3b396a872d9d7201 (diff)
downloadgdb-61012eef8463764ccd9117dc1c9bc43cc452b7cc.zip
gdb-61012eef8463764ccd9117dc1c9bc43cc452b7cc.tar.gz
gdb-61012eef8463764ccd9117dc1c9bc43cc452b7cc.tar.bz2
New common function "startswith"
This commit introduces a new inline common function "startswith" which takes two string arguments and returns nonzero if the first string starts with the second. It also updates the 295 places where this logic was written out longhand to use the new function. gdb/ChangeLog: * common/common-utils.h (startswith): New inline function. All places where this logic was used updated to use the above.
Diffstat (limited to 'gdb/linespec.c')
-rw-r--r--gdb/linespec.c11
1 files changed, 5 insertions, 6 deletions
diff --git a/gdb/linespec.c b/gdb/linespec.c
index 0d012b4..7d7c58d 100644
--- a/gdb/linespec.c
+++ b/gdb/linespec.c
@@ -454,8 +454,7 @@ is_ada_operator (const char *string)
for (mapping = ada_opname_table;
mapping->encoded != NULL
- && strncmp (mapping->decoded, string,
- strlen (mapping->decoded)) != 0; ++mapping)
+ && !startswith (string, mapping->decoded); ++mapping)
;
return mapping->decoded == NULL ? 0 : strlen (mapping->decoded);
@@ -1122,9 +1121,9 @@ find_methods (struct type *t, const char *name,
const char *method_name = TYPE_FN_FIELDLIST_NAME (t, method_counter);
char dem_opname[64];
- if (strncmp (method_name, "__", 2) == 0 ||
- strncmp (method_name, "op", 2) == 0 ||
- strncmp (method_name, "type", 4) == 0)
+ if (startswith (method_name, "__") ||
+ startswith (method_name, "op") ||
+ startswith (method_name, "type"))
{
if (cplus_demangle_opname (method_name, dem_opname, DMGL_ANSI))
method_name = dem_opname;
@@ -1210,7 +1209,7 @@ find_toplevel_string (const char *haystack, const char *needle)
if (s != NULL)
{
/* Found first char in HAYSTACK; check rest of string. */
- if (strncmp (s, needle, strlen (needle)) == 0)
+ if (startswith (s, needle))
return s;
/* Didn't find it; loop over HAYSTACK, looking for the next