ci: fix windows jobs

pull/7342/head
Delyan Angelov 2020-12-15 11:01:51 +02:00
parent 058258bc72
commit 5684ed5a8a
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED
1 changed files with 17 additions and 20 deletions

View File

@ -1,14 +1,17 @@
module builtin
const (
cp_utf8 = 65001
)
pub fn (_str string) to_wide() &u16 {
$if windows {
num_chars := (C.MultiByteToWideChar(cp_utf8, 0, charptr(_str.str), _str.len, 0, 0))
num_chars := (C.MultiByteToWideChar(cp_utf8, 0, charptr(_str.str), _str.len, 0,
0))
mut wstr := &u16(malloc((num_chars + 1) * 2)) // sizeof(wchar_t)
if wstr != 0 {
C.MultiByteToWideChar(cp_utf8, 0, charptr(_str.str), _str.len, wstr, num_chars)
unsafe {
C.memset(&byte(wstr) + num_chars * 2, 0, 2)
}
unsafe {C.memset(&byte(wstr) + num_chars * 2, 0, 2)}
}
return wstr
} $else {
@ -30,10 +33,9 @@ pub fn string_from_wide2(_wstr &u16, len int) string {
num_chars := C.WideCharToMultiByte(cp_utf8, 0, _wstr, len, 0, 0, 0, 0)
mut str_to := malloc(num_chars + 1)
if str_to != 0 {
C.WideCharToMultiByte(cp_utf8, 0, _wstr, len, charptr(str_to), num_chars, 0, 0)
unsafe {
C.memset(str_to + num_chars, 0, 1)
}
C.WideCharToMultiByte(cp_utf8, 0, _wstr, len, charptr(str_to), num_chars,
0, 0)
unsafe {C.memset(str_to + num_chars, 0, 1)}
}
return tos2(str_to)
} $else {
@ -47,25 +49,20 @@ pub fn utf8_getchar() int {
len := utf8_len(byte(~c))
if c < 0 {
return 0
}
else if len == 0 {
} else if len == 0 {
return c
}
else if len == 1 {
} else if len == 1 {
return -1
}
else {
mut uc := c & ((1<<(7 - len)) - 1)
} else {
mut uc := c & ((1 << (7 - len)) - 1)
for i := 0; i + 1 < len; i++ {
c2 := C.getchar()
if c2 != -1 && (c2>>6) == 2 {
if c2 != -1 && (c2 >> 6) == 2 {
uc <<= 6
uc |= (c2 & 63)
}
else if c2 == -1 {
} else if c2 == -1 {
return 0
}
else {
} else {
return -1
}
}