Skip to content

builtin.wchar #

Constants #

const zero = from_rune(0)

zero is a Character, that in C L"" strings represents the string end character (terminator).

fn from_rune #

fn from_rune(r rune) Character

from_rune creates a Character, given a V rune

fn from_string #

fn from_string(s string) &Character

from_string converts the V string (in UTF-8 encoding), into a newly allocated platform specific buffer of C.wchar_t . The conversion is done by processing each rune of the input string 1 by 1.

fn length_in_bytes #

unsafe
fn length_in_bytes(p voidptr) int

length_in_bytes returns the length of the given wchar_t* wide C style L"" string in bytes. Note that the size of wchar_t is different on the different platforms, thus the length in bytes for the same data converted from UTF-8 to a &Character buffer, will be different as well. i.e. unsafe { wchar.length_in_bytes(wchar.from_string('abc')) } will be 12 on unix, but 6 on windows.

fn length_in_characters #

unsafe
fn length_in_characters(p voidptr) int

See also length_in_bytes .

Example

assert unsafe { wchar.length_in_characters(wchar.from_string('abc')) } == 3

fn to_string #

unsafe
fn to_string(p voidptr) string

to_string creates a V string, encoded in UTF-8, given a wchar_t* wide C style L"" string. It relies that the string has a 0 terminator at its end, to determine the string's length. Note, that the size of wchar_t is platform-dependent, and is 2 bytes on windows, while it is 4 bytes on most everything else. Unless you are interfacing with a C library, that does specifically use wchar_t, consider using string_from_wide instead, which will always assume that the input data is in an UTF-16 encoding, no matter what the platform is.

fn to_string2 #

unsafe
fn to_string2(p voidptr, len int) string

to_string2 creates a V string, encoded in UTF-8, given a C.wchar_t* wide C style L"" string. Note, that the size of C.wchar_t is platform-dependent, and is 2 bytes on windows, while 4 on most everything else. Unless you are interfacing with a C library, that does specifically use wchar_t, consider using string_from_wide2 instead, which will always assume that the input data is in an UTF-16 encoding, no matter what the platform is.

type Character #

type Character = C.wchar_t

Character is a type, that eases working with the platform dependent C.wchar_t type.

Note: the size of C.wchar_t varies between platforms, it is 2 bytes on windows, and usually 4 bytes elsewhere.

fn (Character) str #

fn (a Character) str() string

return a string representation of the given Character

fn (Character) == #

fn (a Character) == (b Character) bool

== is an equality operator, to ease comparing Characters

Todo: the default == operator, that V generates, does not work for C.wchar_t .

fn (Character) to_rune #

fn (c Character) to_rune() rune

to_rune creates a V rune, given a Character

struct C.wchar_t #

@[typedef]
struct C.wchar_t {}