[ekg2-commit] ekg2: dynstuff.c (HEAD) [peres]

CVS commit cvs w toxygen.net
Nie, 6 Maj 2007, 15:21:54 CEST


Module name:	ekg2
Changes by:	peres	2007-05-06 15:21:52

Modified files:
	dynstuff.c

Log message:
cssfind() rewritten to use less-exact matching (i.e. we can use spaces
now).

Index: dynstuff.c
===================================================================
RCS file: /home/cvs/ekg2/ekg/dynstuff.c,v
diff -d -u -r1.40 -r1.41
--- dynstuff.c	21 Apr 2007 07:01:41 -0000	1.40
+++ dynstuff.c	6 May 2007 13:21:52 -0000	1.41
@@ -942,6 +942,25 @@
  * @return Pointer to found element on success, or NULL on failure.
  */
 const char *cssfind(const char *haystack, const char *needle, const char sep, int caseinsensitive) {
+	const char *comma = haystack-1;
+	const int needlelen = xstrlen(needle);
+
+	do {
+		comma += xstrspn(comma+1, " \f\n\r\t\v")+1;
+		if (!(caseinsensitive ? xstrncasecmp(comma, needle, needlelen) : xstrncmp(comma, needle, needlelen))) {
+			const char *p, *q;
+
+			p = comma + needlelen;
+			if (!(q = xstrchr(p, sep)))
+				q = p + xstrlen(p);
+			if (q-p <= xstrspn(p, " \f\n\r\t\v")) /* '<' shouldn't happen */
+				return comma;
+		}
+	} while ((comma = xstrchr(comma, sep)));
+
+	return NULL;
+#if 0 /* old, exact-match code; uncomment when needed */
+{
 	const char *r = haystack-1;
 	const int needlelen = xstrlen(needle);
 
@@ -960,6 +979,8 @@
 
 	return r;
 }
+#endif
+}
 
 /*
  * Local Variables:


Więcej informacji o liście dyskusyjnej ekg2-commit