mirror of
https://github.com/vlang/v.git
synced 2025-09-13 14:32:26 +03:00
builtin: string.index_after() ?int
This commit is contained in:
parent
85973b9cca
commit
951d30405f
12 changed files with 94 additions and 44 deletions
|
@ -311,7 +311,7 @@ fn (l Line) write_at_category(txt string) ?string {
|
|||
title := category_map[l.category]
|
||||
title_pos := txt.index(title)?
|
||||
// Find the position of the ### category title
|
||||
pos := txt.index_after('\n', title_pos + 1)
|
||||
pos := txt.index_after('\n', title_pos + 1) or { return none }
|
||||
first_half := txt[..pos]
|
||||
second_half := txt[pos..]
|
||||
if txt.contains(l.text) {
|
||||
|
|
|
@ -104,24 +104,18 @@ fn get_all_modules() []string {
|
|||
mut start_token := "<a href='/mod"
|
||||
end_token := '</a>'
|
||||
// get the start index of the module entry
|
||||
mut start_index := s.index_after(start_token, read_len)
|
||||
mut start_index := s.index_after(start_token, read_len) or { -1 }
|
||||
if start_index == -1 {
|
||||
start_token = '<a href="/mod'
|
||||
start_index = s.index_after(start_token, read_len)
|
||||
if start_index == -1 {
|
||||
break
|
||||
}
|
||||
start_index = s.index_after(start_token, read_len) or { break }
|
||||
}
|
||||
// get the index of the end of anchor (a) opening tag
|
||||
// we use the previous start_index to make sure we are getting a module and not just a random 'a' tag
|
||||
start_token = '>'
|
||||
start_index = s.index_after(start_token, start_index) + start_token.len
|
||||
start_index = s.index_after(start_token, start_index) or { break } + start_token.len
|
||||
|
||||
// get the index of the end of module entry
|
||||
end_index := s.index_after(end_token, start_index)
|
||||
if end_index == -1 {
|
||||
break
|
||||
}
|
||||
end_index := s.index_after(end_token, start_index) or { break }
|
||||
modules << s[start_index..end_index]
|
||||
read_len = end_index
|
||||
if read_len >= s.len {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue