Module: sip-router
Branch: master
Commit: 8c2a2826f5f6954b4a38405fd04f128078e98e0f
URL:
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=8c2a282…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: Sat Mar 26 23:44:01 2011 +0100
core: added function to search a str inside a str
- str_search(text, needle) added to return the position of str needle
when it is found inside str text
---
ut.c | 23 +++++++++++++++++++++++
ut.h | 4 ++++
2 files changed, 27 insertions(+), 0 deletions(-)
diff --git a/ut.c b/ut.c
index b011fda..7dd7373 100644
--- a/ut.c
+++ b/ut.c
@@ -274,3 +274,26 @@ char* get_abs_pathname(str* base, str* file)
}
return res;
}
+
+
+/**
+ * @brief search for occurence of needle in text
+ * @return pointer to start of needle in text or NULL if the needle
+ * is not found
+ */
+char *str_search(str *text, str *needle)
+{
+ char *p;
+
+ if(text==NULL || text->s==NULL || needle==NULL || needle->s==NULL
+ || text->len<needle->len)
+ return NULL;
+
+ for (p = text->s; p <= text->s + text->len - needle->len; p++) {
+ if (*p == *needle->s && memcmp(p, needle->s, needle->len)==0) {
+ return p;
+ }
+ }
+
+ return NULL;
+}
diff --git a/ut.h b/ut.h
index 1e4b2b4..da40ebc 100644
--- a/ut.h
+++ b/ut.h
@@ -824,4 +824,8 @@ unsigned int get_sys_version(int* major, int* minor, int* minor2);
*/
char* get_abs_pathname(str* base, str* file);
+/**
+ * search for needle in text
+ */
+char *str_search(str *text, str *needle);
#endif