source: Include/com/bstring.ab@ 258

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

StringTest追加

File size: 2.7 KB
RevLine 
[138]1' com/bstring.ab
2
3#require <ole2.ab>
4#require <oleauto.ab>
5
6Class BString
[226]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
[138]12Public
13 Sub BString()
14 bs = 0
15 End Sub
16
17 Sub BString(len As DWord)
[142]18 bs = SysAllocStringLen(0, len)
[138]19 End Sub
20
21 Sub BString(ByRef s As BString)
[226]22 Init(s.bs, s.Length)
[138]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)
[226]34 Init(s, lstrlenA(s))
[138]35 End Sub
36
37 Sub BString(s As PCSTR, len As DWord)
[208]38 Dim lenBS = MultiByteToWideChar(CP_THREAD_ACP, 0, s, len As Long, 0, 0)
[138]39 bs = SysAllocStringLen(0, lenBS)
[208]40 MultiByteToWideChar(CP_THREAD_ACP, 0, s, len As Long, bs, lenBS)
[138]41 End Sub
42
43 Sub BString(ByRef s As String)
[226]44 Init(s.StrPtr, s.Length As DWord)
[138]45 End Sub
46
[142]47 Sub ~BString()
48 Clear()
49 End Sub
50
51 Sub Assign(ByRef bstr As BString)
52 Clear()
[226]53 Init(bstr, bstr.Length)
[142]54 End Sub
55
56 Sub Assign(s As LPCOLESTR)
57 Clear()
[226]58 Init(s, lstrlenW(s))
[142]59 End Sub
60
61 Sub AssignFromBStr(bstr As BSTR)
62 Clear()
[175]63 String.Copy(bs, bstr)
[142]64 End Sub
65
[175]66 Const Function Copy() As BSTR
67 BString.Copy(Copy, bs)
68 End Function
69
[138]70 Sub Clear()
71 If bs <> 0 Then
72 SysFreeString(bs)
73 bs = 0
74 End If
75 End Sub
76
[192]77 Sub Attach(ByRef bstr As BSTR)
[138]78 Clear()
[175]79 BString.Move(bs, bstr)
[138]80 End Sub
81
82 Function Detach() As BSTR
[175]83 BString.Move(Detach, bs)
[138]84 End Function
85
86 Function BStr() As BSTR
87 BStr = bs
88 End Function
[208]89/*
90 Static Function Assgin(bs As BSTR) As BString
91 Assgin = New BString
92 Assgin.Assgin(bs)
93 End Function
[138]94
[208]95 Static Function Attach(bs As BSTR) As BString
96 Attach = New BString
97 Attach.Attach(bs)
98 End Function
99*/
[138]100 Const Function Length() As DWord
101 Length = SysStringLen(bs)
102 End Function
103
[142]104 Const Function Operator [](i As SIZE_T) As OLECHAR
[138]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
[208]123 Return New String(bs As PCWSTR, Length As Long)
[138]124 End Function
125
[175]126 Override Function GetHashCode() As Long
127 Return _System_GetHashFromWordArray(bs, Length)
128 End Function
129
[138]130Private
131 bs As BSTR
[175]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
[138]141End Class
142
Note: See TracBrowser for help on using the repository browser.