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.
This commit is contained in:
Gary Benson 2015-03-06 09:42:06 +00:00
parent e80417caef
commit 61012eef84
77 changed files with 309 additions and 329 deletions

View file

@ -544,7 +544,7 @@ is_type_conversion_operator (struct type *type, int i, int j)
some other way, feel free to rewrite this function. */
const char *name = TYPE_FN_FIELDLIST_NAME (type, i);
if (strncmp (name, "operator", 8) != 0)
if (!startswith (name, "operator"))
return 0;
name += 8;
@ -560,9 +560,9 @@ is_type_conversion_operator (struct type *type, int i, int j)
/* If this doesn't look like the start of an identifier, then it
isn't a type conversion operator. */
return 0;
else if (strncmp (name, "new", 3) == 0)
else if (startswith (name, "new"))
name += 3;
else if (strncmp (name, "delete", 6) == 0)
else if (startswith (name, "delete"))
name += 6;
else
/* If it doesn't look like new or delete, it's a type conversion
@ -933,7 +933,7 @@ c_type_print_base (struct type *type, struct ui_file *stream,
enum}" tag for unnamed struct/union/enum's, which we don't
want to print. */
if (TYPE_TAG_NAME (type) != NULL
&& strncmp (TYPE_TAG_NAME (type), "{unnamed", 8))
&& !startswith (TYPE_TAG_NAME (type), "{unnamed"))
{
/* When printing the tag name, we are still effectively
printing in the outer context, hence the use of FLAGS
@ -1345,7 +1345,7 @@ c_type_print_base (struct type *type, struct ui_file *stream,
tag for unnamed struct/union/enum's, which we don't
want to print. */
if (TYPE_TAG_NAME (type) != NULL
&& strncmp (TYPE_TAG_NAME (type), "{unnamed", 8))
&& !startswith (TYPE_TAG_NAME (type), "{unnamed"))
{
print_name_maybe_canonical (TYPE_TAG_NAME (type), flags, stream);
if (show > 0)