Skip to content

Commit 42a9eaa

Browse files
committed
regex: make match_string() receiver immutable
1 parent 7c4f45a commit 42a9eaa

1 file changed

Lines changed: 17 additions & 15 deletions

File tree

vlib/regex/regex_util.v

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -124,29 +124,31 @@ pub fn (re RE) get_group_list() []Re_group {
124124
******************************************************************************/
125125
// match_string Match the pattern with the in_txt string
126126
[direct_array_access]
127-
pub fn (mut re RE) match_string(in_txt string) (int, int) {
128-
start, mut end := re.match_base(in_txt.str, in_txt.len + 1)
129-
if end > in_txt.len {
130-
end = in_txt.len
131-
}
132-
133-
if start >= 0 && end > start {
134-
if (re.flag & f_ms) != 0 && start > 0 {
135-
return no_match_found, 0
127+
pub fn (re &RE) match_string(in_txt string) (int, int) {
128+
unsafe {
129+
start, mut end := re.match_base(in_txt.str, in_txt.len + 1)
130+
if end > in_txt.len {
131+
end = in_txt.len
136132
}
137-
if (re.flag & f_me) != 0 && end < in_txt.len {
138-
if in_txt[end] in new_line_list {
139-
return start, end
133+
134+
if start >= 0 && end > start {
135+
if (re.flag & f_ms) != 0 && start > 0 {
136+
return no_match_found, 0
137+
}
138+
if (re.flag & f_me) != 0 && end < in_txt.len {
139+
if in_txt[end] in new_line_list {
140+
return start, end
141+
}
142+
return no_match_found, 0
140143
}
141-
return no_match_found, 0
144+
return start, end
142145
}
143146
return start, end
144147
}
145-
return start, end
146148
}
147149

148150
// matches_string Checks if the pattern matches the in_txt string
149-
pub fn (mut re RE) matches_string(in_txt string) bool {
151+
pub fn (re &RE) matches_string(in_txt string) bool {
150152
start, _ := re.match_string(in_txt)
151153
return start != no_match_found
152154
}

0 commit comments

Comments
 (0)