Skip to content

Commit 5bc982f

Browse files
Regex(pattern::String,flags::String) & better PCRE flag defaults.
Closes #1797.
1 parent f989c96 commit 5bc982f

File tree

1 file changed

+15
-14
lines changed

1 file changed

+15
-14
lines changed

base/regex.jl

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
include("pcre.jl")
44

5+
const DEFAULT_OPTS = PCRE.UTF8
6+
57
type Regex
68
pattern::ByteString
79
options::Int32
@@ -18,31 +20,30 @@ type Regex
1820
new(pat, opts, re, ex)
1921
end
2022
end
21-
Regex(p::String, s::Bool) = Regex(p, 0, s)
22-
Regex(p::String, o::Integer) = Regex(p, o, false)
23-
Regex(p::String) = Regex(p, 0, false)
24-
25-
copy(r::Regex) = r
26-
27-
# TODO: make sure thing are escaped in a way PCRE
28-
# likes so that Julia all the Julia string quoting
29-
# constructs are correctly handled.
3023

31-
macro r_str(pattern, flags...)
32-
options = PCRE.UTF8
33-
for fx in flags, f in fx
24+
function Regex(pattern::String, flags::String, study::Bool)
25+
options = DEFAULT_OPTS
26+
for f in flags
3427
options |= f=='i' ? PCRE.CASELESS :
3528
f=='m' ? PCRE.MULTILINE :
3629
f=='s' ? PCRE.DOTALL :
3730
f=='x' ? PCRE.EXTENDED :
3831
error("unknown regex flag: $f")
3932
end
40-
Regex(pattern, options)
33+
Regex(pattern, options, study)
4134
end
35+
Regex(p::String, o::Integer) = Regex(p, o, false)
36+
Regex(p::String, f::String) = Regex(p, f, false)
37+
Regex(p::String, s::Bool) = Regex(p, DEFAULT_OPTS, s)
38+
Regex(p::String) = Regex(p, DEFAULT_OPTS, false)
39+
40+
macro r_str(pattern, flags...) Regex(pattern, flags...) end
41+
42+
copy(r::Regex) = r
4243

4344
function show(io, re::Regex)
4445
imsx = PCRE.CASELESS|PCRE.MULTILINE|PCRE.DOTALL|PCRE.EXTENDED
45-
if (re.options & ~imsx) == PCRE.UTF8
46+
if (re.options & ~imsx) == DEFAULT_OPTS
4647
print(io, 'r')
4748
print_quoted_literal(io, re.pattern)
4849
if (re.options & PCRE.CASELESS ) != 0; print(io, 'i'); end

0 commit comments

Comments
 (0)