builtin: move byte methods from rune.v to int.v (#11987)

pull/11991/head
Wertzui123 2021-09-26 21:34:25 +02:00 committed by GitHub
parent 6967a47e07
commit 07d65b2aab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 24 deletions

View File

@ -484,3 +484,27 @@ pub fn (b byte) str_escaped() string {
}
return str
}
// Define this on byte as well, so that we can do `s[0].is_capital()`
pub fn (c byte) is_capital() bool {
return c >= `A` && c <= `Z`
}
pub fn (b []byte) clone() []byte {
mut res := []byte{len: b.len}
// mut res := make([]byte, {repeat:b.len})
for i in 0 .. b.len {
res[i] = b[i]
}
return res
}
// TODO: remove this once runes are implemented
pub fn (b []byte) bytestr() string {
unsafe {
buf := malloc_noscan(b.len + 1)
vmemcpy(buf, b.data, b.len)
buf[b.len] = 0
return tos(buf, b.len)
}
}

View File

@ -39,27 +39,3 @@ pub fn (ra []rune) string() string {
unsafe { sb.free() }
return res
}
// Define this on byte as well, so that we can do `s[0].is_capital()`
pub fn (c byte) is_capital() bool {
return c >= `A` && c <= `Z`
}
pub fn (b []byte) clone() []byte {
mut res := []byte{len: b.len}
// mut res := make([]byte, {repeat:b.len})
for i in 0 .. b.len {
res[i] = b[i]
}
return res
}
// TODO: remove this once runes are implemented
pub fn (b []byte) bytestr() string {
unsafe {
buf := malloc_noscan(b.len + 1)
vmemcpy(buf, b.data, b.len)
buf[b.len] = 0
return tos(buf, b.len)
}
}