svn commit: r368356 - head/lib/libc/regex

Kyle Evans kevans at FreeBSD.org
Sat Dec 5 02:23:11 UTC 2020


Author: kevans
Date: Sat Dec  5 02:23:11 2020
New Revision: 368356
URL: https://svnweb.freebsd.org/changeset/base/368356

Log:
  libc: regex: factor out ISBOW/ISEOW macros
  
  These will be reused for \b (word boundary, which matches both sides).
  
  No functional change.

Modified:
  head/lib/libc/regex/engine.c

Modified: head/lib/libc/regex/engine.c
==============================================================================
--- head/lib/libc/regex/engine.c	Sat Dec  5 02:21:58 2020	(r368355)
+++ head/lib/libc/regex/engine.c	Sat Dec  5 02:23:11 2020	(r368356)
@@ -589,6 +589,17 @@ dissect(struct match *m,
 	return(sp);
 }
 
+#define	ISBOW(m, sp)					\
+    (sp < m->endp && ISWORD(*sp) &&			\
+    ((sp == m->beginp && !(m->eflags&REG_NOTBOL)) ||	\
+    (sp > m->offp && !ISWORD(*(sp-1)))))
+#define	ISEOW(m, sp)					\
+    (((sp == m->endp && !(m->eflags&REG_NOTEOL)) ||	\
+    (sp < m->endp && *sp == '\n' &&			\
+    (m->g->cflags&REG_NEWLINE)) ||			\
+    (sp < m->endp && !ISWORD(*sp)) ) &&			\
+    (sp > m->beginp && ISWORD(*(sp-1))))		\
+
 /*
  - backref - figure out what matched what, figuring in back references
  == static const char *backref(struct match *m, const char *start, \
@@ -663,19 +674,13 @@ backref(struct match *m,
 				return(NULL);
 			break;
 		case OBOW:
-			if (sp < m->endp && ISWORD(*sp) &&
-			    ((sp == m->beginp && !(m->eflags&REG_NOTBOL)) ||
-			    (sp > m->offp && !ISWORD(*(sp-1)))))
+			if (ISBOW(m, sp))
 				{ /* yes */ }
 			else
 				return(NULL);
 			break;
 		case OEOW:
-			if (( (sp == m->endp && !(m->eflags&REG_NOTEOL)) ||
-					(sp < m->endp && *sp == '\n' &&
-						(m->g->cflags&REG_NEWLINE)) ||
-					(sp < m->endp && !ISWORD(*sp)) ) &&
-					(sp > m->beginp && ISWORD(*(sp-1))) )
+			if (ISEOW(m, sp))
 				{ /* yes */ }
 			else
 				return(NULL);


More information about the svn-src-head mailing list