source: Include/com/bstring.ab@ 246

Last change on this file since 246 was 226, checked in by イグトランス (egtra), 18 years ago

StringTest追加

File size: 2.7 KB
Line 
1' com/bstring.ab
2
3#require <ole2.ab>
4#require <oleauto.ab>
5
6Class BString
7 Sub Init(s As PCSTR, len As DWord)
8 Dim lenBS = MultiByteToWideChar(CP_THREAD_ACP, 0, s, len As Long, 0, 0)
9 bs = SysAllocStringLen(0, lenBS)
10 MultiByteToWideChar(CP_THREAD_ACP, 0, s, len As Long, bs, lenBS)
11 End Sub
12Public
13 Sub BString()
14 bs = 0
15 End Sub
16
17 Sub BString(len As DWord)
18 bs = SysAllocStringLen(0, len)
19 End Sub
20
21 Sub BString(ByRef s As BString)
22 Init(s.bs, s.Length)
23 End Sub
24
25 Sub BString(s As LPCOLESTR)
26 bs = SysAllocString(s)
27 End Sub
28
29 Sub BString(s As LPCOLESTR, len As DWord)
30 bs = SysAllocStringLen(s, len)
31 End Sub
32
33 Sub BString(s As PCSTR)
34 Init(s, lstrlenA(s))
35 End Sub
36
37 Sub BString(s As PCSTR, len As DWord)
38 Dim lenBS = MultiByteToWideChar(CP_THREAD_ACP, 0, s, len As Long, 0, 0)
39 bs = SysAllocStringLen(0, lenBS)
40 MultiByteToWideChar(CP_THREAD_ACP, 0, s, len As Long, bs, lenBS)
41 End Sub
42
43 Sub BString(ByRef s As String)
44 Init(s.StrPtr, s.Length As DWord)
45 End Sub
46
47 Sub ~BString()
48 Clear()
49 End Sub
50
51 Sub Assign(ByRef bstr As BString)
52 Clear()
53 Init(bstr, bstr.Length)
54 End Sub
55
56 Sub Assign(s As LPCOLESTR)
57 Clear()
58 Init(s, lstrlenW(s))
59 End Sub
60
61 Sub AssignFromBStr(bstr As BSTR)
62 Clear()
63 String.Copy(bs, bstr)
64 End Sub
65
66 Const Function Copy() As BSTR
67 BString.Copy(Copy, bs)
68 End Function
69
70 Sub Clear()
71 If bs <> 0 Then
72 SysFreeString(bs)
73 bs = 0
74 End If
75 End Sub
76
77 Sub Attach(ByRef bstr As BSTR)
78 Clear()
79 BString.Move(bs, bstr)
80 End Sub
81
82 Function Detach() As BSTR
83 BString.Move(Detach, bs)
84 End Function
85
86 Function BStr() As BSTR
87 BStr = bs
88 End Function
89/*
90 Static Function Assgin(bs As BSTR) As BString
91 Assgin = New BString
92 Assgin.Assgin(bs)
93 End Function
94
95 Static Function Attach(bs As BSTR) As BString
96 Attach = New BString
97 Attach.Attach(bs)
98 End Function
99*/
100 Const Function Length() As DWord
101 Length = SysStringLen(bs)
102 End Function
103
104 Const Function Operator [](i As SIZE_T) As OLECHAR
105#ifdef _DEBUG
106 If i > Length Then
107 'Throw OutOfRangeException
108 End If
109#endif
110 Return bs[i]
111 End Function
112
113 Sub Operator []=(i As SIZE_T, c As OLECHAR)
114#ifdef _DEBUG
115 If i > Length Then
116 'Throw OutOfRangeException
117 End If
118#endif
119 bs[i] = c
120 End Sub
121
122 Override Function ToString() As String
123 Return New String(bs As PCWSTR, Length As Long)
124 End Function
125
126 Override Function GetHashCode() As Long
127 Return _System_GetHashFromWordArray(bs, Length)
128 End Function
129
130Private
131 bs As BSTR
132
133 Static Sub Copy(ByRef dst As BSTR, ByVal src As BSTR)
134 dst = SysAllocStringLen(src, SysStringLen(src))
135 End Sub
136
137 Static Sub Move(ByRef dst As BSTR, ByRef src As BSTR)
138 dst = src
139 src = 0
140 End Sub
141End Class
142
Note: See TracBrowser for help on using the repository browser.