mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
@@ -910,7 +910,7 @@ pub fn (s string) substr(start int, end int) string {
|
||||
// version of `substr()` that is used in `a[start..end] or {`
|
||||
// return an error when the index is out of range
|
||||
[direct_array_access]
|
||||
pub fn (s string) substr_with_check(start int, end int) ?string {
|
||||
pub fn (s string) substr_with_check(start int, end int) !string {
|
||||
if start > end || start > s.len || end > s.len || start < 0 || end < 0 {
|
||||
return error('substr(${start}, ${end}) out of bounds (len=${s.len})')
|
||||
}
|
||||
@@ -1606,7 +1606,7 @@ fn (s string) at(idx int) byte {
|
||||
// return an error when the index is out of range
|
||||
fn (s string) at_with_check(idx int) ?u8 {
|
||||
if idx < 0 || idx >= s.len {
|
||||
return error('string index out of range')
|
||||
return none
|
||||
}
|
||||
unsafe {
|
||||
return s.str[idx]
|
||||
|
||||
Reference in New Issue
Block a user