File tree Expand file tree Collapse file tree 2 files changed +36
-1
lines changed Expand file tree Collapse file tree 2 files changed +36
-1
lines changed Original file line number Diff line number Diff line change @@ -17,7 +17,14 @@ pub fn (_str string) to_wide() &u16 {
17
17
return wstr
18
18
}
19
19
} $else {
20
- return 0
20
+ srunes := _str.runes ()
21
+ unsafe {
22
+ mut result := & u16 (vcalloc_noscan ((srunes.len + 1 ) * 2 ))
23
+ for i, r in srunes {
24
+ result[i] = u16 (r)
25
+ }
26
+ return result
27
+ }
21
28
}
22
29
}
23
30
Original file line number Diff line number Diff line change @@ -26,3 +26,31 @@ fn test_utf8_wide_char() {
26
26
assert val[2 ].hex () == '94'
27
27
}
28
28
}
29
+
30
+ fn test_to_wide_latin () {
31
+ s := 'abc 123'
32
+ w := s.to_wide ()
33
+ unsafe {
34
+ assert w[0 ] == 97
35
+ assert w[1 ] == 98
36
+ assert w[2 ] == 99
37
+ assert w[3 ] == 32
38
+ assert w[4 ] == 49
39
+ assert w[5 ] == 50
40
+ assert w[6 ] == 51
41
+ assert w[7 ] == 0
42
+ }
43
+ }
44
+
45
+ fn test_to_wide_cyrillic () {
46
+ s := 'Проба'
47
+ w := s.to_wide ()
48
+ unsafe {
49
+ assert w[0 ] == 1055
50
+ assert w[1 ] == 1088
51
+ assert w[2 ] == 1086
52
+ assert w[3 ] == 1073
53
+ assert w[4 ] == 1072
54
+ assert w[5 ] == 0
55
+ }
56
+ }
You can’t perform that action at this time.
0 commit comments