diff --git a/tools/vrepl.v b/tools/vrepl.v index 70623e6d53..a15b8549a8 100644 --- a/tools/vrepl.v +++ b/tools/vrepl.v @@ -187,12 +187,16 @@ fn print_output(s os.Result) { for line in lines { if line.starts_with('.vrepl_temp.v') { // Hide the temporary file name - println(line[line.index(' ') + 1 .. ]) + idx := line.index(' ') or { + println(line) + return + } + println(line[idx+1..]) } else { println(line) } } - + } fn main() { diff --git a/vlib/compiler/tests/msvc_test.v b/vlib/compiler/tests/msvc_test.v index 84baa23f30..b3532e3ba0 100644 --- a/vlib/compiler/tests/msvc_test.v +++ b/vlib/compiler/tests/msvc_test.v @@ -1,8 +1,8 @@ fn test_flag_parsing() { mut rest := '-lGlfw -f gl2,-ltest_nice_meme,-l cc,-Ldl test.o a.o ' //, whatever.o' - result := ['-l', 'Glfw', - '-f', 'gl2', - '-l', 'test_nice_meme', + result := ['-l', 'Glfw', + '-f', 'gl2', + '-l', 'test_nice_meme', '-l', 'cc', '-L', 'dl', '', 'test.o', @@ -21,8 +21,10 @@ fn test_flag_parsing() { // Which ever one of these is lowest we use // TODO: we really shouldnt support all of these cmon - mut lowest := base.index('-') - for x in [base.index(' '), base.index(',')] { + mut lowest := base.index('-') or { -1 } + a := base.index(' ') or { -1 } + b := base.index(',') or { -1 } + for x in [a, b] { if (x < lowest && x != -1) || lowest == -1 { lowest = x } @@ -44,6 +46,6 @@ fn test_flag_parsing() { } for i, f in flags { - assert f == result[i] + assert f == result[i] } } diff --git a/vlib/encoding/csv/reader.v b/vlib/encoding/csv/reader.v index a696a92135..d7654e45e5 100644 --- a/vlib/encoding/csv/reader.v +++ b/vlib/encoding/csv/reader.v @@ -113,8 +113,7 @@ fn (r mut Reader) read_record() ?[]string { for { // not quoted if line[0] != `"` { - i = line.index(r.delimiter.str()) - if i == -1 { + i = line.index(r.delimiter.str()) or { // last break } @@ -125,8 +124,7 @@ fn (r mut Reader) read_record() ?[]string { // quoted else { line = line[1..] - i = line.index('"') - if i != -1 { + if i := line.index('"') { if i+1 == line.len { // last record fields << line[..i] @@ -145,7 +143,6 @@ fn (r mut Reader) read_record() ?[]string { return err_invalid_delim } } - return fields } diff --git a/vlib/http/http.v b/vlib/http/http.v index ccc81f1e5d..73d17bc733 100644 --- a/vlib/http/http.v +++ b/vlib/http/http.v @@ -185,18 +185,17 @@ fn parse_response(resp string) Response { break } i++ - pos := h.index(':') - if pos == -1 { + pos := h.index(':') or { continue } //if h.contains('Content-Type') { //continue //} key := h[..pos] - val := h[pos + 2..] + val := h[pos+2..] headers[key] = val.trim_space() } - + if headers['Transfer-Encoding'] == 'chunked' { 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 { ua := req.user_agent mut uheaders := []string - for key, val in req.headers { + for key, val in req.headers { uheaders << '${key}: ${val}\r\n' } if req.data.len > 0 {