This is the mail archive of the libc-alpha@sources.redhat.com mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Implement REG_STARTEND extension to POSIX regex functions


This patch implements NetBSD's REG_STARTEND, which is an
extension to the POSIX functions that allows one to either
embed NULs in the string or to start matching from a point
different from the start of the subject.

Paolo

2004-01-15  Paolo Bonzini  <bonzini@gnu.org>

	* posix/regex.h (REG_STARTEND): Define.
	* posix/regexec.c (regexec): Check for REG_STARTEND.

diff -u save/regex.h ./regex.h
--- save/regex.h	2004-01-15 20:40:20.000000000 +0100
+++ ./regex.h	2004-01-15 20:41:08.000000000 +0100
@@ -298,6 +298,10 @@
 /* Like REG_NOTBOL, except for the end-of-line.  */
 #define REG_NOTEOL (1 << 1)
 
+/* Use PMATCH[0] to delimit the start and end of the search in the
+   buffer.  */
+#define REG_STARTEND (1 << 2)
+
 
 /* If any error codes are removed, changed, or added, update the
    `re_error_msg' table in regex.c.  */
diff -u save/regexec.c ./regexec.c
--- save/regexec.c	2004-01-15 20:40:20.000000000 +0100
+++ ./regexec.c	2004-01-15 20:50:02.000000000 +0100
@@ -209,13 +209,23 @@
     int eflags;
 {
   reg_errcode_t err;
-  int length = strlen (string);
+  int start, length;
+  if (eflags & REG_STARTEND)
+    {
+      start = pmatch[0].rm_so;
+      length = pmatch[0].rm_eo;
+    }
+  else
+    {
+      start = 0;
+      length = strlen (string);
+    }
   if (preg->no_sub)
-    err = re_search_internal (preg, string, length, 0, length, length, 0,
-			      NULL, eflags);
+    err = re_search_internal (preg, string, length, start, length - start,
+			      length, 0, NULL, eflags);
   else
-    err = re_search_internal (preg, string, length, 0, length, length, nmatch,
-			      pmatch, eflags);
+    err = re_search_internal (preg, string, length, start, length - start,
+			      length, nmatch, pmatch, eflags);
   return err != REG_NOERROR;
 }
 #ifdef _LIBC


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]