Use the appropriate string search functions instead of strstr everywhere.

This mostly means using strchr, but I also found:
  option_parser.c:load_ini_file:
    - replace multiple calls to strstr with strpbrk
  notification.c:notification_init:
    - replace string_replace in a while loop with a single call to
      string_replace_char

redo string replace all
This commit is contained in:
Luke Shumaker 2013-09-18 21:08:57 -04:00 committed by Eizen
parent 187d3f9ab9
commit 2c93c7a277
3 changed files with 10 additions and 12 deletions

View File

@ -199,7 +199,7 @@ void closed(NotifyNotification *n, gpointer foo)
void add_action(NotifyNotification *n, char *str) void add_action(NotifyNotification *n, char *str)
{ {
char *action = str; char *action = str;
char *label = strstr(str, ","); char *label = strchr(str, ',');
if (!label || *(label+1) == '\0') { if (!label || *(label+1) == '\0') {
g_printerr("Malformed action. Excpected \"action,label\", got \"%s\"", str); g_printerr("Malformed action. Excpected \"action,label\", got \"%s\"", str);
@ -215,14 +215,14 @@ void add_action(NotifyNotification *n, char *str)
void add_hint(NotifyNotification *n, char *str) void add_hint(NotifyNotification *n, char *str)
{ {
char *type = str; char *type = str;
char *name = strstr(str, ":"); char *name = strchr(str, ':');
if (!name || *(name+1) == '\0') { if (!name || *(name+1) == '\0') {
g_printerr("Malformed hint. Expected \"type:name:value\", got \"%s\"", str); g_printerr("Malformed hint. Expected \"type:name:value\", got \"%s\"", str);
return; return;
} }
*name = '\0'; *name = '\0';
name++; name++;
char *value = strstr(name, ":"); char *value = strchr(name, ':');
if (!value || *(value+1) == '\0') { if (!value || *(value+1) == '\0') {
g_printerr("Malformed hint. Expected \"type:name:value\", got \"%s\"", str); g_printerr("Malformed hint. Expected \"type:name:value\", got \"%s\"", str);
return; return;

View File

@ -214,7 +214,7 @@ int load_ini_file(FILE * fp)
continue; continue;
if (*start == '[') { if (*start == '[') {
char *end = strstr(start + 1, "]"); char *end = strchr(start + 1, ']');
if (!end) { if (!end) {
printf printf
("Warning: invalid config file at line %d\n", ("Warning: invalid config file at line %d\n",
@ -232,7 +232,7 @@ int load_ini_file(FILE * fp)
continue; continue;
} }
char *equal = strstr(start + 1, "="); char *equal = strchr(start + 1, '=');
if (!equal) { if (!equal) {
printf("Warning: invalid config file at line %d\n", printf("Warning: invalid config file at line %d\n",
line_num); line_num);
@ -244,9 +244,9 @@ int load_ini_file(FILE * fp)
char *key = g_strstrip(start); char *key = g_strstrip(start);
char *value = g_strstrip(equal + 1); char *value = g_strstrip(equal + 1);
char *quote = strstr(value, "\""); char *quote = strchr(value, '"');
if (quote) { if (quote) {
char *closing_quote = strstr(quote + 1, "\""); char *closing_quote = strchr(quote + 1, '"');
if (!closing_quote) { if (!closing_quote) {
printf printf
("Warning: invalid config file at line %d\n", ("Warning: invalid config file at line %d\n",
@ -257,9 +257,7 @@ int load_ini_file(FILE * fp)
closing_quote = '\0'; closing_quote = '\0';
} else { } else {
char *comment = strstr(value, "#"); char *comment = strpbrk(value, "#;");
if (!comment)
comment = strstr(value, ";");
if (comment) if (comment)
comment = '\0'; comment = '\0';
} }
@ -291,7 +289,7 @@ int cmdline_find_option(char *key)
return -1; return -1;
} }
char *key1 = g_strdup(key); char *key1 = g_strdup(key);
char *key2 = strstr(key1, "/"); char *key2 = strchr(key1, '/');
if (key2) { if (key2) {
*key2 = '\0'; *key2 = '\0';

View File

@ -1383,7 +1383,7 @@ void x_shortcut_init(keyboard_shortcut * ks)
if (str == NULL) if (str == NULL)
die("Unable to allocate memory", EXIT_FAILURE); die("Unable to allocate memory", EXIT_FAILURE);
while (strstr(str, "+")) { while (strchr(str, '+')) {
char *mod = str; char *mod = str;
while (*str != '+') while (*str != '+')
str++; str++;