source: Include/com/bstring.ab@ 187

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

Variant, VBObjectの追加

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