1 | Imports System.Text
|
---|
2 | Imports System.Text.Detail
|
---|
3 |
|
---|
4 | Namespace EncodingTest
|
---|
5 |
|
---|
6 | Sub TestMain()
|
---|
7 | 'abcαβγアイウ(漢字拡張Bから3文字)
|
---|
8 | Dim chars[ELM(15)] = [
|
---|
9 | &h61, &h62, &h63,
|
---|
10 | &h03b1, &h03b2, &h03b3,
|
---|
11 | &h30a2, &h30a4, &h30a6,
|
---|
12 | &hd840, &hdc00, &hd840, &hdc01, &hd840, &hdc02] As WCHAR
|
---|
13 | Dim utf32bytes[ELM(12)] = [
|
---|
14 | &h61, &h62, &h63,
|
---|
15 | &h03b1, &h03b2, &h03b3,
|
---|
16 | &h30a2, &h30a4, &h30a6,
|
---|
17 | &h20000, &h20001, &h20002] As DWORD
|
---|
18 | Dim utf8bytes[ELM(30)] = [
|
---|
19 | &h61, &h62, &h63,
|
---|
20 | &hce, &hb1, &hce, &hb2, &hce, &hb3,
|
---|
21 | &he3, &h82, &ha2, &he3, &h82, &ha4, &he3, &h82, &ha6,
|
---|
22 | &hf0, &ha0, &h80, &h80, &hf0, &ha0, &h80, &h81, &hf0, &ha0, &h80, &h82] As Byte
|
---|
23 | Dim cp932bytes[ELM(15)] = [
|
---|
24 | &h61, &h62, &h63,
|
---|
25 | &h83, &hbf, &h83, &hc0, &h83, &hc1,
|
---|
26 | &h83, &h41, &h83, &h43, &h83, &h45] As Byte '拡張Bは省略
|
---|
27 |
|
---|
28 | Dim utf8 = New UTF8Encoding
|
---|
29 | Dim e = utf8.GetEncoder()
|
---|
30 | Dim d = utf8.GetDecoder()
|
---|
31 | Dim b[256] As Byte
|
---|
32 | Dim u16[256] As WCHAR
|
---|
33 | Dim len As Long
|
---|
34 |
|
---|
35 | len = utf8.GetBytesCount(chars, Len(chars) \ SizeOf(WCHAR))
|
---|
36 | UnitTest("UTF-8 GetByteCount", len = Len(utf8bytes))
|
---|
37 | utf8.GetBytes(chars, Len(chars) \ SizeOf (WCHAR), b, Len(b))
|
---|
38 | UnitTest("UTF-8 Encode", memcmp(b, utf8bytes, Len(utf8bytes)) = 0)
|
---|
39 |
|
---|
40 | len = utf8.GetCharsCount(utf8bytes, Len(utf8bytes))
|
---|
41 | UnitTest("UTF-8 GetCharCount", len = Len(chars) \ SizeOf(WCHAR))
|
---|
42 | utf8.GetChars(utf8bytes, Len(utf8bytes), u16, Len(u16) \ SizeOf (WCHAR))
|
---|
43 | UnitTest("UTF-8 Decode", memcmp(u16, chars, Len(chars)) = 0)
|
---|
44 | End Sub
|
---|
45 |
|
---|
46 | End Namespace
|
---|
47 |
|
---|
48 | EncodingTest.TestMain()
|
---|
49 |
|
---|