1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

regex: new options returning interface to the regex module (#6062)

This commit is contained in:
Maciej Obarski
2020-08-08 08:04:12 +02:00
committed by GitHub
parent 664c26ab4b
commit 2a4ef2acbd
4 changed files with 268 additions and 274 deletions

View File

@ -1,6 +1,6 @@
/*
regex 0.9e
regex 0.9g
Copyright (c) 2019-2020 Dario Deledda. All rights reserved.
Use of this source code is governed by an MIT license
@ -19,7 +19,7 @@ module regex
import strings
pub const(
v_regex_version = "0.9e" // regex module version
v_regex_version = "0.9g" // regex module version
max_code_len = 256 // default small base code len for the regex programs
max_quantifier = 1073741824 // default max repetitions allowed for the quantifiers = 2^30
@ -912,7 +912,12 @@ fn (re RE) parse_groups(in_txt string, in_i int) (int, bool, string, int) {
// main compiler
//
// compile return (return code, index) where index is the index of the error in the query string if return code is an error code
[deprecated]
pub fn (mut re RE) compile(in_txt string) (int,int) {
return re.impl_compile(in_txt)
}
fn (mut re RE) impl_compile(in_txt string) (int,int) {
mut i := 0 // input string index
mut pc := 0 // program counter
mut tmp_code := u32(0)
@ -2187,6 +2192,7 @@ Public functions
//
// regex create a regex object from the query string
[deprecated]
pub fn regex(in_query string) (RE,int,int){
mut re := RE{}
re.prog = [Token{}].repeat(in_query.len+1)
@ -2198,12 +2204,17 @@ pub fn regex(in_query string) (RE,int,int){
}
// new_regex create a RE of small size, usually sufficient for ordinary use
[deprecated]
pub fn new_regex() RE {
return new_regex_by_size(1)
return impl_new_regex_by_size(1)
}
// new_regex_by_size create a RE of large size, mult specify the scale factor of the memory that will be allocated
[deprecated]
pub fn new_regex_by_size(mult int) RE {
return impl_new_regex_by_size(mult)
}
fn impl_new_regex_by_size(mult int) RE {
mut re := RE{}
re.prog = [Token{}].repeat(max_code_len*mult) // max program length, default 256 istructions
re.cc = [CharClass{}].repeat(max_code_len*mult) // char class list