File: rexp4.c

package info (click to toggle)
mawk 1.3.4.20250131-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,224 kB
  • sloc: ansic: 19,901; sh: 4,600; yacc: 1,177; awk: 853; makefile: 290
file content (57 lines) | stat: -rw-r--r-- 1,020 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/*
rexp4.c
copyright 2024 Thomas E. Dickey

This is a source file for mawk, an implementation of
the AWK programming language.

Mawk is distributed without warranty under the terms of
the GNU General Public License, version 2, 1991.
 */

/*
 * $MawkId: rexp4.c,v 1.12 2024/09/05 17:44:48 tom Exp $
 */
#include <field.h>

char *
is_string_split(PTR q, size_t *lenp)
{
    if (q != NULL) {
	STRING *s = ((RE_NODE *) q)->sval;
	char *result = s->str;

	/* if we have only one character, it cannot be a regex */
	if (s->len == 1) {
	    *lenp = s->len;
	    return result;
	} else {
	    size_t n;
	    for (n = 0; n < s->len; ++n) {
		/* if we have a meta character, it probably is a regex */
		switch (result[n]) {
		case '\\':
		case '$':
		case '(':
		case ')':
		case '*':
		case '+':
		case '.':
		case '?':
		case '[':
		case ']':
		case '^':
		case '|':
#ifndef NO_INTERVAL_EXPR
		case L_CURL:
		case R_CURL:
#endif
		    return NULL;
		}
	    }
	    *lenp = s->len;
	    return result;
	}
    }
    return NULL;
}