From 07d65b2aabeb4413afbf853892f8caf6a8adbc57 Mon Sep 17 00:00:00 2001 From: Wertzui123 <46199283+Wertzui123@users.noreply.github.com> Date: Sun, 26 Sep 2021 21:34:25 +0200 Subject: [PATCH] builtin: move byte methods from rune.v to int.v (#11987) --- vlib/builtin/int.v | 24 ++++++++++++++++++++++++ vlib/builtin/rune.v | 24 ------------------------ 2 files changed, 24 insertions(+), 24 deletions(-) diff --git a/vlib/builtin/int.v b/vlib/builtin/int.v index a105512e05..70e27822dd 100644 --- a/vlib/builtin/int.v +++ b/vlib/builtin/int.v @@ -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) + } +} diff --git a/vlib/builtin/rune.v b/vlib/builtin/rune.v index 3364d9001a..806010c301 100644 --- a/vlib/builtin/rune.v +++ b/vlib/builtin/rune.v @@ -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) - } -}