File: RegexEmptyMatch.cmake

package info (click to toggle)
cmake 4.2.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 152,344 kB
  • sloc: ansic: 403,894; cpp: 303,807; sh: 4,097; python: 3,582; yacc: 3,106; lex: 1,279; f90: 538; asm: 471; lisp: 375; cs: 270; java: 266; fortran: 239; objc: 215; perl: 213; xml: 198; makefile: 108; javascript: 83; pascal: 63; tcl: 55; php: 25; ruby: 22
file content (143 lines) | stat: -rw-r--r-- 3,095 bytes parent folder | download
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
cmake_policy(SET CMP0186 NEW)

function(check_output name expected)
  set(output "${${name}}")
  if(NOT output STREQUAL expected)
    message(FATAL_ERROR "\"string(REGEX)\" set ${name} to \"${output}\", expected \"${expected}\"")
  endif()
endfunction()

# Zero-length matches in REGEX MATCH

string(REGEX MATCH "" out "")
check_output(out "")

string(REGEX MATCH "" out "a")
check_output(out "")

string(REGEX MATCH "a*" out "")
check_output(out "")

string(REGEX MATCH "a*" out "a")
check_output(out "a")

string(REGEX MATCH "a*" out "b")
check_output(out "")

string(REGEX MATCH "a*" out "ba")
check_output(out "")

# Zero-length matches in REGEX MATCHALL

string(REGEX MATCHALL "" out "")
check_output(out "")

string(REGEX MATCHALL "" out "ab")
check_output(out ";;")

string(REGEX MATCHALL "^" out "ab")
check_output(out "")

string(REGEX MATCHALL "(^|,)" out "a,b")
check_output(out ";,")

string(REGEX MATCHALL "(,|^)" out "a,b")
check_output(out ";,")

string(REGEX MATCHALL "(^|)" out "")
check_output(out "")

string(REGEX MATCHALL "(^|)" out "ab")
check_output(out ";;")

string(REGEX MATCHALL "a|^" out "ab")
check_output(out "a")

string(REGEX MATCHALL "$" out "ab")
check_output(out "")

string(REGEX MATCHALL "($|,)" out "a,b")
check_output(out ",;")

string(REGEX MATCHALL "(,|$)" out "a,b")
check_output(out ",;")

string(REGEX MATCHALL "(|$)" out "")
check_output(out "")

string(REGEX MATCHALL "(|$)" out "ab")
check_output(out ";;")

string(REGEX MATCHALL "(b|)" out "abc")
check_output(out ";b;;")

string(REGEX MATCHALL "(|b)" out "abc")
check_output(out ";;b;;")

string(REGEX MATCHALL "a*" out "aaa")
check_output(out "aaa;")

string(REGEX MATCHALL "(a)?(b)?" out "")
check_output(out "")

string(REGEX MATCHALL "(a)?(b)?" out "abba")
check_output(out "ab;b;a;")

# Zero-length matches in REGEX REPLACE

string(REGEX REPLACE "" "" out "")
check_output(out "")

string(REGEX REPLACE "" "x" out "")
check_output(out "x")

string(REGEX REPLACE "" "x" out "ab")
check_output(out "xaxbx")

string(REGEX REPLACE "^" "x" out "ab")
check_output(out "xab")

string(REGEX REPLACE "(^|,)" "x" out "a,b")
check_output(out "xaxb")

string(REGEX REPLACE "(,|^)" "x" out "a,b")
check_output(out "xaxb")

string(REGEX REPLACE "(^|)" "x" out "")
check_output(out "x")

string(REGEX REPLACE "(^|)" "x" out "ab")
check_output(out "xaxbx")

string(REGEX REPLACE "a|^" "x" out "ab")
check_output(out "xb")

string(REGEX REPLACE "$" "x" out "ab")
check_output(out "abx")

string(REGEX REPLACE "($|,)" "x" out "a,b")
check_output(out "axbx")

string(REGEX REPLACE "(,|$)" "x" out "a,b")
check_output(out "axbx")

string(REGEX REPLACE "(|$)" "x" out "")
check_output(out "x")

string(REGEX REPLACE "(|$)" "x" out "ab")
check_output(out "xaxbx")

string(REGEX REPLACE "(b|)" "x" out "abc")
check_output(out "xaxxcx")

string(REGEX REPLACE "(|b)" "x" out "abc")
check_output(out "xaxxxcx")

string(REGEX REPLACE "a*" "x" out "aaa")
check_output(out "xx")

string(REGEX REPLACE "(a)?(b)?" "x" out "")
check_output(out "x")

string(REGEX REPLACE "(a)?(b)?" "x" out "abba")
check_output(out "xxxx")