builtin: fix substr()

pull/9325/head
Alexander Medvednikov 2021-03-15 21:16:23 +01:00
parent 77d5fcca59
commit 667a26335f
1 changed files with 9 additions and 9 deletions

View File

@ -604,17 +604,17 @@ fn (s string) substr2(start int, _end int, end_max bool) string {
// Example: assert 'ABCD'.substr(1,3) == 'BC'
pub fn (s string) substr(start int, end int) string {
$if !no_bounds_checking ? {
/*
$if debug {
if start > end || start > s.len || end > s.len || start < 0 || end < 0 {
println('substr($start, $end) out of bounds (len=$s.len)')
println('s="$s"')
print_backtrace()
return ''
if start > end || start > s.len || end > s.len || start < 0 || end < 0 {
/*
$if debug {
println('substr($start, $end) out of bounds (len=$s.len)')
println('s="$s"')
print_backtrace()
return ''
}
*/
panic('substr($start, $end) out of bounds (len=$s.len)')
}
*/
panic('substr($start, $end) out of bounds (len=$s.len)')
}
len := end - start
if len == s.len {