Open trufae opened 1 year ago
decompose a striung into an array of bytes, aka chars
You can get string to byte(u8) array and vice versa:
a := 'qwerty βππ€£πβ
πππ'
b := a.bytes()
c := b.bytestr()
println(a)
println(typeof(b).name)
println(b.len)
println(c)
Output
qwerty βππ€£πβ
πππ
[]u8
37
qwerty βππ€£πβ
πππ
OK (0.002 sec real, 0.001 sec wall)
While I agree it would be nice if
s += ` `
would work, this works now
s += ` `.str()
char
on the other hand, is mainly for C interop. In V, the type should be u8
, so
a := u8(0x41)
b := a.ascii_str() + "AAAAA";
will assign B the string 'AAAAAA'
as expected.
Describe the bug
Imho it should be easy for V to append chars or runes into strings. but i couldnt find an easy way to do that. This results in different errors i end up just using string interpolations to achieve the same, but definitvely it shouldnt perform that well.
Expected Behavior
This code should be valid imho:
concatenating two runes should be also valid and must result into a string:
how can i convert a char into a rune? i didnt find any
safe
way to do that that doesnt involve complicated constructions things like this should work imho:also, a char, should be also valid for 1 byte runes. aka ascii
I coudlnt find the way to get the numeric value of a rune or a char, and viceversa. This is not what itoa/atoi is for, but to basically decompose a striung into an array of bytes, aka chars
Current Behavior
See above, none of this works and its not intuitive
Reproduction Steps
compile the snippets
Possible Solution
No response
Additional Information/Context
No response
V version
V 0.3.3 e70848a
Environment details (OS name and version, etc.)
OS: linux, Linux version 5.15.90-0-lts (buildozer@build-3-17-x86_64) (gcc (Alpine 12.2.1_git20220924-r4) 12.2.1 20220924, GNU ld (GNU Binutils) 2.39) #1-Alpine SMP Wed, 25 Jan 2023 08:18:30 +0000 Processor: 4 cpus, 64bit, little endian, Intel(R) Celeron(R) N4120 CPU @ 1.10GHz CC version: cc (Alpine 12.2.1_git20220924-r4) 12.2.1 20220924
getwd: /home/pancake/prg/v-sax vmodules: /home/pancake/.vmodules vroot: /home/pancake/prg/v vexe: /home/pancake/prg/v/v vexe mtime: 2023-02-01 17:02:38 is vroot writable: true is vmodules writable: true V full version: V 0.3.3 e70848a
Git version: git version 2.38.3 Git vroot status: 0.3.3-20-g90ae3c82 (2 commit(s) behind V master) .git/config present: true thirdparty/tcc status: thirdparty-linuxmusl-amd64 6b2bc802