mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
v2: scopes, or, in, hex
This commit is contained in:
@@ -195,6 +195,17 @@ struct RepIndex {
|
||||
val_idx int
|
||||
}
|
||||
|
||||
fn compare_rep_index(a, b &RepIndex) int {
|
||||
if a.idx < b.idx {
|
||||
return -1
|
||||
}
|
||||
if a.idx > b.idx {
|
||||
return 1
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
|
||||
fn (a mut []RepIndex) sort() {
|
||||
a.sort_with_compare(compare_rep_index)
|
||||
}
|
||||
@@ -207,16 +218,6 @@ fn (a RepIndex) < (b RepIndex) bool {
|
||||
*/
|
||||
|
||||
|
||||
fn compare_rep_index(a, b &RepIndex) int {
|
||||
if a.idx < b.idx {
|
||||
return -1
|
||||
}
|
||||
if a.idx > b.idx {
|
||||
return 1
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
pub fn (s string) replace_each(vals []string) string {
|
||||
if s.len == 0 || vals.len == 0 {
|
||||
return s
|
||||
@@ -244,7 +245,8 @@ pub fn (s string) replace_each(vals []string) string {
|
||||
// We need to remember both the position in the string,
|
||||
// and which rep/with pair it refers to.
|
||||
idxs << RepIndex{
|
||||
idx,rep_i}
|
||||
idx:idx
|
||||
val_idx:rep_i}
|
||||
idx++
|
||||
new_len += with.len - rep.len
|
||||
}
|
||||
@@ -403,8 +405,8 @@ pub fn (s string) split(delim string) []string {
|
||||
}
|
||||
|
||||
/*
|
||||
split_nth - splits the string based on the passed `delim` substring.
|
||||
It returns the first Nth parts. When N=0, return all the splits.
|
||||
split_nth - splits the string based on the passed `delim` substring.
|
||||
It returns the first Nth parts. When N=0, return all the splits.
|
||||
The last returned element has the remainder of the string, even if
|
||||
the remainder contains more `delim` substrings.
|
||||
*/
|
||||
@@ -447,7 +449,7 @@ pub fn (s string) split_nth(delim string, nth int) []string {
|
||||
res << s.right(start)
|
||||
break
|
||||
}
|
||||
|
||||
|
||||
res << val
|
||||
start = i + delim.len
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user