Hi,
On Mon, 2012-06-11 at 18:28 +0800, Feng Wei wrote:
[snip]
> >> +static int ucm_port_contain(const char *port_name, const char *dev_name) {
> >> + int ret=0;
> >> + char *r;
> >> + const char *state=NULL;
> >> +
> >> + if (!port_name || !dev_name)
> >> + return FALSE;
> >> +
> >> + while ((r = pa_split(port_name, "+", &state))) {
> >> + if (!strcmp(r, dev_name)) {
> >> + pa_xfree(r);
> >> + ret = 1;
> >> + break;
> >> + }
> >> + pa_xfree(r);
> >> + }
> >> + return ret;
> >> +}
> >
> > Better to use strstr() here. Avoids some unnecessary allocation +
> > deallocation.
> Is it possible that we have sub string matching in error?
I'm attaching a patch snippet of something that might be useful instead.
Untested, but should work -- if it looks fine, I can commit this.
One comment that I missed, I think -- I see that you've called
structures pa_alsa_ucm_* and functions pa_ucm_*. Could you make them all
pa_alsa_ucm_*?
Thanks for all the efforts,
Arun
diff --git a/src/pulsecore/core-util.c b/src/pulsecore/core-util.c
index dc9412f..e2e1ec7 100644
--- a/src/pulsecore/core-util.c
+++ b/src/pulsecore/core-util.c
@@ -947,6 +947,27 @@ char *pa_split(const char *c, const char *delimiter, const char**state) {
return pa_xstrndup(current, l);
}
+/* Split the specified string wherever one of the strings in delimiter
+ * occurs. Each time it is called returns a pointer to the substring within the
+ * string and the length in n. The variable state points to, should be
+ * initialized to NULL before the first call. */
+const char *pa_split_in_place(const char *c, const char *delimiter, int *n, const char**state) {
+ const char *current = *state ? *state : c;
+ size_t l;
+
+ if (!*current)
+ return NULL;
+
+ l = strcspn(current, delimiter);
+ *state = current+l;
+
+ if (**state)
+ (*state)++;
+
+ *n = l;
+ return current;
+}
+
/* Split a string into words. Otherwise similar to pa_split(). */
char *pa_split_spaces(const char *c, const char **state) {
const char *current = *state ? *state : c;
diff --git a/src/pulsecore/core-util.h b/src/pulsecore/core-util.h
index 4a1c096..a3c2247 100644
--- a/src/pulsecore/core-util.h
+++ b/src/pulsecore/core-util.h
@@ -100,6 +100,7 @@ static inline const char *pa_strna(const char *x) {
}
char *pa_split(const char *c, const char*delimiters, const char **state);
+const char *pa_split_in_place(const char *c, const char*delimiters, int *n, const char **state);
char *pa_split_spaces(const char *c, const char **state);
char *pa_strip_nl(char *s);
_______________________________________________
pulseaudio-discuss mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/pulseaudio-discuss