builtin: use a pure V version of string.to_wide() on != windows (#13314)
parent
e43794ad61
commit
44dddecc09
|
@ -17,7 +17,14 @@ pub fn (_str string) to_wide() &u16 {
|
|||
return wstr
|
||||
}
|
||||
} $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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -26,3 +26,31 @@ fn test_utf8_wide_char() {
|
|||
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
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue