add `str` function for `rune`

pull/896/head
musou1500 2019-07-02 00:36:23 +09:00 committed by Alexander Medvednikov
parent 571410dd48
commit 668646f8f9
2 changed files with 22 additions and 3 deletions

9
examples/rune.v 100644
View File

@ -0,0 +1,9 @@
fn main() {
// GRINNING FACE😀 => f0 09 98 80
grinning_face := rune(0xf09f9880)
println(grinning_face)
// COMMERCIAL AT@ => 0x40
commercial_at := rune(0x40000000)
println(commercial_at)
}

View File

@ -145,10 +145,20 @@ pub fn (a []byte) contains(val byte) bool {
return false
}
/* TODO
fn (c rune) str() string {
pub fn (c rune) str() string {
fst_byte := int(c) >> 8 * 3 & 0xff
len := utf8_char_len(fst_byte)
mut str := string {
len: len
str: malloc(len + 1)
}
for i := 0; i < len; i++ {
str.str[i] = int(c) >> 8 * (3 - i) & 0xff
}
str[len] = `\0`
return str
}
*/
pub fn (c byte) str() string {
mut str := string {
len: 1