diff --git a/examples/rune.v b/examples/rune.v new file mode 100644 index 0000000000..f30b6711ee --- /dev/null +++ b/examples/rune.v @@ -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) +} diff --git a/vlib/builtin/int.v b/vlib/builtin/int.v index 686a1c6806..f5c304c984 100644 --- a/vlib/builtin/int.v +++ b/vlib/builtin/int.v @@ -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