vlib: refactor empty string checks to use s == '' or s != '', instead of s.len == 0 (#21300)

This commit is contained in:
Turiiya 2024-04-18 01:44:31 +02:00 committed by GitHub
parent 46be635072
commit 8aa9314a99
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
55 changed files with 95 additions and 96 deletions

View file

@ -60,7 +60,7 @@ fn write_page_table(mut sb strings.Builder, uri_path string, requested_file_path
sb.writeln('<th align="left" style="width: 200px">Last modified</th>')
sb.writeln('<th align="left">Name</th>')
sb.writeln('</tr>')
if uri_path.len == 0 {
if uri_path == '' {
sb.writeln('<tr>')
sb.writeln('<td>---</td>')
sb.writeln('<td>---</td>')

View file

@ -17,7 +17,7 @@ fn test_http_get_from_vlang_utc_now() {
println('Test getting current time from ${url} by http.get')
res := http.get(url) or { panic(err) }
assert res.status() == .ok
assert res.body.len > 0
assert res.body != ''
assert res.body.int() > 1566403696
println('Current time is: ${res.body.int()}')
}
@ -39,7 +39,7 @@ fn test_public_servers() {
println('Testing http.get on public url: ${url} ')
res := http.get(url) or { panic(err) }
assert res.status() == .ok
assert res.body.len > 0
assert res.body != ''
}
}
@ -51,6 +51,6 @@ fn test_relative_redirects() {
} // tempfix periodic: httpbin relative redirects are broken
res := http.get('https://httpbin.org/relative-redirect/3?abc=xyz') or { panic(err) }
assert res.status() == .ok
assert res.body.len > 0
assert res.body != ''
assert res.body.contains('"abc": "xyz"')
}

View file

@ -131,7 +131,7 @@ pub fn new_response(conf ResponseConfig) Response {
body: conf.body
header: conf.header
}
if resp.body.len > 0 && !resp.header.contains(.content_length) {
if resp.body != '' && !resp.header.contains(.content_length) {
resp.header.add(.content_length, resp.body.len.str())
}
resp.set_status(conf.status)