tree-wide: replace strstr(a, b) == a with spa_strstartswith()

spa_strstartswith() is more immediately understandable.

Coccinelle spatch file:
	@@
	expression E1, E2;
	@@
	- strstr(E1, E2) != E1
	+ !spa_strstartswith(E1, E2)

	@@
	expression E1, E2;
	@@
	- strstr(E1, E2) == E1
	+ spa_strstartswith(E1, E2)

Applied to the tree except for alsa/acp/compat.h because it looks like
that header is still mostly as-is from PA.
This commit is contained in:
Peter Hutterer 2021-08-02 14:05:45 +10:00 committed by Wim Taymans
parent 60c510d766
commit 51a177eb6d
20 changed files with 48 additions and 48 deletions

View file

@ -679,7 +679,7 @@ handle_device(struct impl *impl, struct sm_object *obj)
pw_log_debug(NAME" %p: device "PW_KEY_MEDIA_CLASS":%s api:%s", impl, media_class, str);
if (strstr(media_class, "Audio/") != media_class)
if (!spa_strstartswith(media_class, "Audio/"))
return 0;
if (!spa_streq(str, "alsa"))
return 0;

View file

@ -321,9 +321,9 @@ static struct node *alsa_create_node(struct device *device, uint32_t id,
priority -= atol(dev) * 16;
priority -= atol(subdev);
if (strstr(profile, "analog-") == profile)
if (spa_strstartswith(profile, "analog-"))
priority += 9;
else if (strstr(profile, "iec958-") == profile)
else if (spa_strstartswith(profile, "iec958-"))
priority += 8;
if (pw_properties_get(node->props, PW_KEY_PRIORITY_DRIVER) == NULL) {
@ -356,7 +356,7 @@ static struct node *alsa_create_node(struct device *device, uint32_t id,
if ((devname = pw_properties_get(device->props, SPA_KEY_DEVICE_NAME)) == NULL)
devname = "unnamed-device";
if (strstr(devname, "alsa_card.") == devname)
if (spa_strstartswith(devname, "alsa_card."))
devname += 10;
pw_properties_set(node->props, SPA_KEY_NODE_NAME,

View file

@ -616,7 +616,7 @@ handle_device(struct impl *impl, struct sm_object *obj)
pw_log_debug(NAME" %p: device "PW_KEY_MEDIA_CLASS":%s api:%s", impl, media_class, str);
if (strstr(media_class, "Audio/") != media_class)
if (!spa_strstartswith(media_class, "Audio/"))
return 0;
if (!spa_streq(str, "bluez5"))
return 0;

View file

@ -405,7 +405,7 @@ static int update_device_props(struct device *device)
snprintf(temp, sizeof(temp), "%d", device->id);
s = temp;
}
if (strstr(s, "bluez_card.") == s)
if (spa_strstartswith(s, "bluez_card."))
s += strlen("bluez_card.");
pw_properties_set(p, PW_KEY_DEVICE_NAME,

View file

@ -130,14 +130,14 @@ handle_endpoint(struct impl *impl, struct sm_object *object)
ep->enabled = true;
spa_list_append(&impl->endpoint_list, &ep->link);
if (strstr(media_class, "Stream/") == media_class) {
if (spa_strstartswith(media_class, "Stream/")) {
media_class += strlen("Stream/");
if (strstr(media_class, "Output/") == media_class) {
if (spa_strstartswith(media_class, "Output/")) {
direction = PW_DIRECTION_OUTPUT;
media_class += strlen("Output/");
}
else if (strstr(media_class, "Input/") == media_class) {
else if (spa_strstartswith(media_class, "Input/")) {
direction = PW_DIRECTION_INPUT;
media_class += strlen("Input/");
}
@ -151,11 +151,11 @@ handle_endpoint(struct impl *impl, struct sm_object *object)
}
else {
const char *media;
if (strstr(media_class, "Audio/") == media_class) {
if (spa_strstartswith(media_class, "Audio/")) {
media_class += strlen("Audio/");
media = "Audio";
}
else if (strstr(media_class, "Video/") == media_class) {
else if (spa_strstartswith(media_class, "Video/")) {
media_class += strlen("Video/");
media = "Video";
}

View file

@ -294,21 +294,21 @@ handle_node(struct impl *impl, struct sm_object *object)
if (role && spa_streq(role, "DSP"))
node->active = node->configured = true;
if (strstr(media_class, "Stream/") == media_class) {
if (spa_strstartswith(media_class, "Stream/")) {
media_class += strlen("Stream/");
if (strstr(media_class, "Output/") == media_class) {
if (spa_strstartswith(media_class, "Output/")) {
direction = PW_DIRECTION_OUTPUT;
media_class += strlen("Output/");
}
else if (strstr(media_class, "Input/") == media_class) {
else if (spa_strstartswith(media_class, "Input/")) {
direction = PW_DIRECTION_INPUT;
media_class += strlen("Input/");
}
else
return 0;
if (strstr(media_class, "Video") == media_class) {
if (spa_strstartswith(media_class, "Video")) {
if (direction == PW_DIRECTION_OUTPUT) {
if ((str = pw_properties_get(object->props, PW_KEY_NODE_PLUGGED)) != NULL)
node->plugged = pw_properties_parse_uint64(str);
@ -317,7 +317,7 @@ handle_node(struct impl *impl, struct sm_object *object)
}
node->active = node->configured = true;
}
else if (strstr(media_class, "Unknown") == media_class) {
else if (spa_strstartswith(media_class, "Unknown")) {
node->active = node->configured = true;
}
@ -330,11 +330,11 @@ handle_node(struct impl *impl, struct sm_object *object)
const char *media;
bool virtual = false;
if (strstr(media_class, "Audio/") == media_class) {
if (spa_strstartswith(media_class, "Audio/")) {
media_class += strlen("Audio/");
media = "Audio";
}
else if (strstr(media_class, "Video/") == media_class) {
else if (spa_strstartswith(media_class, "Video/")) {
media_class += strlen("Video/");
media = "Video";
node->active = node->configured = true;

View file

@ -244,7 +244,7 @@ static int metadata_property(void *object, uint32_t subject,
pw_properties_clear(impl->props);
changed = 1;
}
else if (strstr(key, PREFIX) == key) {
else if (spa_strstartswith(key, PREFIX)) {
changed += pw_properties_set(impl->props, key, value);
}
}
@ -472,12 +472,12 @@ static void session_create(void *data, struct sm_object *object)
(media_class = pw_properties_get(object->props, PW_KEY_MEDIA_CLASS)) == NULL)
return;
if (strstr(media_class, "Stream/") == media_class) {
if (spa_strstartswith(media_class, "Stream/")) {
media_class += strlen("Stream/");
pw_log_debug(NAME " %p: add stream '%d' %s", impl, object->id, media_class);
} else if (strstr(media_class, "Audio/") == media_class &&
((routes = pw_properties_get(object->props, "device.routes")) == NULL ||
atoi(routes) == 0)) {
} else if (spa_strstartswith(media_class, "Audio/") &&
((routes = pw_properties_get(object->props, "device.routes")) == NULL ||
atoi(routes) == 0)) {
pw_log_debug(NAME " %p: add node '%d' %s", impl, object->id, media_class);
} else {
return;

View file

@ -516,16 +516,16 @@ handle_node(struct impl *impl, struct sm_object *obj)
if (media_class == NULL)
return 0;
if (strstr(media_class, "Stream/") != media_class)
if (!spa_strstartswith(media_class, "Stream/"))
return 0;
media_class += strlen("Stream/");
if (strstr(media_class, "Output/") == media_class) {
if (spa_strstartswith(media_class, "Output/")) {
direction = PW_DIRECTION_OUTPUT;
media_class += strlen("Output/");
}
else if (strstr(media_class, "Input/") == media_class) {
else if (spa_strstartswith(media_class, "Input/")) {
direction = PW_DIRECTION_INPUT;
media_class += strlen("Input/");
}

View file

@ -178,8 +178,8 @@ handle_node(struct impl *impl, struct sm_object *object)
if (media_class == NULL)
return 0;
if (strstr(media_class, "Audio/") != media_class &&
(strstr(media_class, "Video/") != media_class))
if (!spa_strstartswith(media_class, "Audio/") &&
(!spa_strstartswith(media_class, "Video/")))
return 0;
node = sm_object_add_data(object, SESSION_KEY, sizeof(struct node));

View file

@ -563,7 +563,7 @@ handle_device(struct impl *impl, struct sm_object *obj)
pw_log_debug(NAME" %p: device "PW_KEY_MEDIA_CLASS":%s api:%s", impl, media_class, str);
if (strstr(media_class, "Video/") != media_class)
if (!spa_strstartswith(media_class, "Video/"))
return 0;
if (!spa_streq(str, "v4l2"))
return 0;

View file

@ -154,7 +154,7 @@ static struct node *v4l2_create_node(struct device *dev, uint32_t id,
str = pw_properties_get(dev->props, SPA_KEY_DEVICE_ALIAS);
if (str == NULL)
str = "v4l2-device";
if (strstr(str, "v4l2_device.") == str)
if (spa_strstartswith(str, "v4l2_device."))
str += 12;
if (strstr(info->factory_name, "sink") != NULL)