1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

builtin: use a pure V version of string.to_wide() on != windows (#13314)

This commit is contained in:
Delyan Angelov 2022-01-28 20:41:50 +02:00 committed by GitHub
parent e43794ad61
commit 44dddecc09
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 36 additions and 1 deletions

View File

@ -17,7 +17,14 @@ pub fn (_str string) to_wide() &u16 {
return wstr return wstr
} }
} $else { } $else {
return 0 srunes := _str.runes()
unsafe {
mut result := &u16(vcalloc_noscan((srunes.len + 1) * 2))
for i, r in srunes {
result[i] = u16(r)
}
return result
}
} }
} }

View File

@ -26,3 +26,31 @@ fn test_utf8_wide_char() {
assert val[2].hex() == '94' assert val[2].hex() == '94'
} }
} }
fn test_to_wide_latin() {
s := 'abc 123'
w := s.to_wide()
unsafe {
assert w[0] == 97
assert w[1] == 98
assert w[2] == 99
assert w[3] == 32
assert w[4] == 49
assert w[5] == 50
assert w[6] == 51
assert w[7] == 0
}
}
fn test_to_wide_cyrillic() {
s := 'Проба'
w := s.to_wide()
unsafe {
assert w[0] == 1055
assert w[1] == 1088
assert w[2] == 1086
assert w[3] == 1073
assert w[4] == 1072
assert w[5] == 0
}
}