mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
update all index() uses
This commit is contained in:
parent
2651b8957a
commit
a23a4ed98a
@ -187,12 +187,16 @@ fn print_output(s os.Result) {
|
|||||||
for line in lines {
|
for line in lines {
|
||||||
if line.starts_with('.vrepl_temp.v') {
|
if line.starts_with('.vrepl_temp.v') {
|
||||||
// Hide the temporary file name
|
// Hide the temporary file name
|
||||||
println(line[line.index(' ') + 1 .. ])
|
idx := line.index(' ') or {
|
||||||
|
println(line)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
println(line[idx+1..])
|
||||||
} else {
|
} else {
|
||||||
println(line)
|
println(line)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
fn test_flag_parsing() {
|
fn test_flag_parsing() {
|
||||||
mut rest := '-lGlfw -f gl2,-ltest_nice_meme,-l cc,-Ldl test.o a.o ' //, whatever.o'
|
mut rest := '-lGlfw -f gl2,-ltest_nice_meme,-l cc,-Ldl test.o a.o ' //, whatever.o'
|
||||||
result := ['-l', 'Glfw',
|
result := ['-l', 'Glfw',
|
||||||
'-f', 'gl2',
|
'-f', 'gl2',
|
||||||
'-l', 'test_nice_meme',
|
'-l', 'test_nice_meme',
|
||||||
'-l', 'cc',
|
'-l', 'cc',
|
||||||
'-L', 'dl',
|
'-L', 'dl',
|
||||||
'', 'test.o',
|
'', 'test.o',
|
||||||
@ -21,8 +21,10 @@ fn test_flag_parsing() {
|
|||||||
|
|
||||||
// Which ever one of these is lowest we use
|
// Which ever one of these is lowest we use
|
||||||
// TODO: we really shouldnt support all of these cmon
|
// TODO: we really shouldnt support all of these cmon
|
||||||
mut lowest := base.index('-')
|
mut lowest := base.index('-') or { -1 }
|
||||||
for x in [base.index(' '), base.index(',')] {
|
a := base.index(' ') or { -1 }
|
||||||
|
b := base.index(',') or { -1 }
|
||||||
|
for x in [a, b] {
|
||||||
if (x < lowest && x != -1) || lowest == -1 {
|
if (x < lowest && x != -1) || lowest == -1 {
|
||||||
lowest = x
|
lowest = x
|
||||||
}
|
}
|
||||||
@ -44,6 +46,6 @@ fn test_flag_parsing() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for i, f in flags {
|
for i, f in flags {
|
||||||
assert f == result[i]
|
assert f == result[i]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -113,8 +113,7 @@ fn (r mut Reader) read_record() ?[]string {
|
|||||||
for {
|
for {
|
||||||
// not quoted
|
// not quoted
|
||||||
if line[0] != `"` {
|
if line[0] != `"` {
|
||||||
i = line.index(r.delimiter.str())
|
i = line.index(r.delimiter.str()) or {
|
||||||
if i == -1 {
|
|
||||||
// last
|
// last
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
@ -125,8 +124,7 @@ fn (r mut Reader) read_record() ?[]string {
|
|||||||
// quoted
|
// quoted
|
||||||
else {
|
else {
|
||||||
line = line[1..]
|
line = line[1..]
|
||||||
i = line.index('"')
|
if i := line.index('"') {
|
||||||
if i != -1 {
|
|
||||||
if i+1 == line.len {
|
if i+1 == line.len {
|
||||||
// last record
|
// last record
|
||||||
fields << line[..i]
|
fields << line[..i]
|
||||||
@ -145,7 +143,6 @@ fn (r mut Reader) read_record() ?[]string {
|
|||||||
return err_invalid_delim
|
return err_invalid_delim
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return fields
|
return fields
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -185,18 +185,17 @@ fn parse_response(resp string) Response {
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
i++
|
i++
|
||||||
pos := h.index(':')
|
pos := h.index(':') or {
|
||||||
if pos == -1 {
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
//if h.contains('Content-Type') {
|
//if h.contains('Content-Type') {
|
||||||
//continue
|
//continue
|
||||||
//}
|
//}
|
||||||
key := h[..pos]
|
key := h[..pos]
|
||||||
val := h[pos + 2..]
|
val := h[pos+2..]
|
||||||
headers[key] = val.trim_space()
|
headers[key] = val.trim_space()
|
||||||
}
|
}
|
||||||
|
|
||||||
if headers['Transfer-Encoding'] == 'chunked' {
|
if headers['Transfer-Encoding'] == 'chunked' {
|
||||||
text = chunked.decode( text )
|
text = chunked.decode( text )
|
||||||
}
|
}
|
||||||
@ -211,7 +210,7 @@ fn parse_response(resp string) Response {
|
|||||||
fn (req &Request) build_request_headers(method, host_name, path string) string {
|
fn (req &Request) build_request_headers(method, host_name, path string) string {
|
||||||
ua := req.user_agent
|
ua := req.user_agent
|
||||||
mut uheaders := []string
|
mut uheaders := []string
|
||||||
for key, val in req.headers {
|
for key, val in req.headers {
|
||||||
uheaders << '${key}: ${val}\r\n'
|
uheaders << '${key}: ${val}\r\n'
|
||||||
}
|
}
|
||||||
if req.data.len > 0 {
|
if req.data.len > 0 {
|
||||||
|
Loading…
Reference in New Issue
Block a user