Skip to content

Commit

Permalink
cli: loose string comparison helper
Browse files Browse the repository at this point in the history
  • Loading branch information
biot committed May 29, 2012
1 parent 2d6ff32 commit 432de70
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
33 changes: 33 additions & 0 deletions parsers.c
Original file line number Diff line number Diff line change
Expand Up @@ -181,3 +181,36 @@ struct sr_dev *parse_devstring(const char *devstring)

return dev;
}

char *strcanon(char *str)
{
int p0, p1;
char *s;

/* Returns newly allocated string. */
s = g_ascii_strdown(str, -1);
for (p0 = p1 = 0; str[p0]; p0++) {
if ((s[p0] >= 'a' && s[p0] <= 'z')
|| (s[p0] >= '0' && s[p0] <= '9'))
s[p1++] = s[p0];
}
s[p1] = '\0';

return s;
}


int canon_cmp(char *str1, char *str2)
{
int ret;
char *s1, *s2;

s1 = strcanon(str1);
s2 = strcanon(str2);
ret = g_ascii_strcasecmp(s1, s2);
g_free(s2);
g_free(s1);

return ret;
}

2 changes: 2 additions & 0 deletions sigrok-cli.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ char **sr_parse_triggerstring(struct sr_dev *dev, const char *triggerstring);
GHashTable *parse_generic_arg(const char *arg);
struct sr_dev *parse_devstring(const char *devstring);
uint64_t sr_parse_timestring(const char *timestring);
char *strcanon(char *str);
int canon_cmp(char *str1, char *str2);

/* anykey.c */
void add_anykey(void);
Expand Down

0 comments on commit 432de70

Please sign in to comment.