Debian Codegraph @

tools/clsMigemo.cls

raw ◀ ▶
1 Debian patch touch this file
•1 VERSION 1.0 CLASS
2 BEGIN
3 MultiUse = -1 'True
4 Persistable = 0 'NotPersistable
5 DataBindingBehavior = 0 'vbNone
6 DataSourceBehavior = 0 'vbNone
7 MTSTransactionMode = 0 'NotAnMTSObject
8 END
9 Attribute VB_Name = "clsMigemo"
10 Attribute VB_GlobalNameSpace = False
11 Attribute VB_Creatable = True
12 Attribute VB_PredeclaredId = False
13 Attribute VB_Exposed = False
14 Attribute VB_Ext_KEY = "SavedWithClassBuilder6" ,"Yes"
15 Attribute VB_Ext_KEY = "Top_Level" ,"Yes"
16 Option Explicit
17
18 Public Enum DictionaryId
19 enmInvalid = 0
20 enmMigemo = 1
21 enmRomaToHira = 2
22 enmHiraToKata = 3
23 enmHanToZen = 4
24 enmZenToHan = 5
25 End Enum
26
27 Public Enum OperatorIndex
28 enmOr = 0
29 enmNestIn = 1
30 enmNestOut = 2
31 enmSelectIn = 3
32 enmSelectOut = 4
33 enmNewLine = 5
34 End Enum
35
36 Private Const enmDictMigemo = "migemo-dict"
37 Private Const enmDictRoma2Hira = "roma2hira.dat"
38 Private Const enmDictHira2Kata = "hira2kata.dat"
39 Private Const enmDictHan2Zen = "han2zen.dat"
40 Private Const enmDictZen2Han = "zen2han.dat"
41
42 Private Declare Function migemo_open Lib "migemo.dll" (ByVal strDict As String) As Long
43 Private Declare Sub migemo_close Lib "migemo.dll" (ByVal hMigemo As Long)
44 Private Declare Function migemo_query Lib "migemo.dll" (ByVal hMigemo As Long, ByVal strQuery As String) As Long
45 Private Declare Sub migemo_release Lib "migemo.dll" (ByVal hMigemo As Long, ByVal pAnswer As Long)
46 Private Declare Function migemo_set_operator Lib "migemo.dll" (ByVal hMigemo As Long, ByVal EnmIndex As OperatorIndex, ByVal strOp As String) As Long
47 Private Declare Function migemo_get_operator Lib "migemo.dll" (ByVal hMigemo As Long, ByVal EnmIndex As OperatorIndex) As Long
48 Private Declare Function migemo_load Lib "migemo.dll" (ByVal hMigemo As Long, ByVal EnmDict As DictionaryId, ByVal strFile As String) As DictionaryId
49 Private Declare Function migemo_is_enable Lib "migemo.dll" (ByVal hMigemo As Long) As Long
50 Private Declare Sub CopyMemory Lib "kernel32.dll" Alias "RtlMoveMemory" (pTo As Any, uFrom As Any, ByVal lSize As Long)
51 Private Declare Function StrLen Lib "kernel32.dll" Alias "lstrlen" (ByVal Ptr As Long) As Long
52
53 Private m_hMigemo As Long
54
55 Private Function PtrStr(lpString As Long) As String
56 Dim buff() As Byte
57 Dim nSize As Long
58
59 If lpString Then
60 nSize = StrLen(lpString)
61 If nSize Then
62 ReDim buff(0 To (nSize - 1)) As Byte
63 CopyMemory buff(0), ByVal lpString, nSize
64 PtrStr = buff
65 End If
66 End If
67 End Function
68
69 Private Sub Class_Initialize()
70 m_hMigemo = migemo_open(0)
71 OperatorNestIn = "(?:"
72 End Sub
73
74 Private Sub Class_Terminate()
75 If m_hMigemo Then
76 Call migemo_close(m_hMigemo)
77 m_hMigemo = 0
78 End If
79 End Sub
80
81 Public Function SetOperator(EnmIndex As OperatorIndex, strOp As String) As Boolean
82 SetOperator = migemo_set_operator(m_hMigemo, EnmIndex, strOp)
83 End Function
84
85 Public Function GetOperator(EnmIndex As OperatorIndex) As String
86 GetOperator = StrConv(PtrStr(migemo_get_operator(m_hMigemo, EnmIndex)), vbUnicode)
87 End Function
88
89 Public Property Let OperatorOr(ByVal strOp As String)
90 Call SetOperator(enmOr, strOp)
91 End Property
92
93 Public Property Get OperatorOr() As String
94 OperatorOr = GetOperator(enmOr)
95 End Property
96
97 Public Property Let OperatorNestIn(ByVal strOp As String)
98 Call SetOperator(enmNestIn, strOp)
99 End Property
100
101 Public Property Get OperatorNestIn() As String
102 OperatorNestIn = GetOperator(enmNestIn)
103 End Property
104
105 Public Property Let OperatorNestOut(ByVal strOp As String)
106 Call SetOperator(enmNestOut, strOp)
107 End Property
108
109 Public Property Get OperatorNestOut() As String
110 OperatorNestOut = GetOperator(enmNestOut)
111 End Property
112
113 Public Property Let OperatorSelectIn(ByVal strOp As String)
114 Call SetOperator(enmSelectIn, strOp)
115 End Property
116
117 Public Property Get OperatorSelectIn() As String
118 OperatorSelectIn = GetOperator(enmSelectIn)
119 End Property
120
121 Public Property Let OperatorSelectOut(ByVal strOp As String)
122 Call SetOperator(enmSelectOut, strOp)
123 End Property
124
125 Public Property Get OperatorSelectOut() As String
126 OperatorSelectOut = GetOperator(enmSelectOut)
127 End Property
128
129 Public Property Let OperatorNewLine(ByVal strOp As String)
130 Call SetOperator(enmNewLine, strOp)
131 End Property
132
133 Public Property Get OperatorNewLine() As String
134 OperatorNewLine = GetOperator(enmNewLine)
135 End Property
136
137 Public Function LoadDictionary(EnmDictId As DictionaryId, strFile As String) As Boolean
138 LoadDictionary = False
139 If migemo_load(m_hMigemo, EnmDictId, strFile) = EnmDictId Then
140 LoadDictionary = True
141 End If
142 End Function
143
144 Public Function LoadDictionaryAll(strFile As String) As Boolean
145 Dim strBase As String
146 Dim lngLoaded As Long
147 LoadDictionaryAll = False
148
149 strBase = Left(strFile, InStrRev(strFile, "/"))
150 If Len(strBase) = 0 Then
151 strBase = Left(strFile, InStrRev(strFile, "\"))
152 End If
153
154 lngLoaded = 0
155 lngLoaded = lngLoaded + IIf(LoadDictionary(enmMigemo, strFile), 1, 0)
156 lngLoaded = lngLoaded + IIf(LoadDictionary(enmRomaToHira, strBase & enmDictRoma2Hira), 1, 0)
157 lngLoaded = lngLoaded + IIf(LoadDictionary(enmHiraToKata, strBase & enmDictHira2Kata), 1, 0)
158 lngLoaded = lngLoaded + IIf(LoadDictionary(enmHanToZen, strBase & enmDictHan2Zen), 1, 0)
159 lngLoaded = lngLoaded + IIf(LoadDictionary(enmZenToHan, strBase & enmDictZen2Han), 1, 0)
160 If lngLoaded = 5 Then
161 LoadDictionaryAll = True
162 End If
163 End Function
164
165 Public Function IsEnable() As Boolean
166 IsEnable = migemo_is_enable(m_hMigemo)
167 End Function
168
169 Public Function GetRegex(strQuery As String) As Object
170 Set GetRegex = CreateObject("VBScript.RegExp")
171 GetRegex.Pattern = Query(strQuery)
172 End Function
173
174 Public Function Query(strQuery As String) As String
175 Dim pAnswer As Long
176 pAnswer = migemo_query(m_hMigemo, strQuery)
177 If pAnswer Then
178 Query = StrConv(PtrStr(pAnswer), vbUnicode)
179 Call migemo_release(m_hMigemo, pAnswer)
180 Else
181 Query = ""
182 End If
183 End Function
184
185 Public Sub Dispose()
186 If m_hMigemo Then
187 Call migemo_close(m_hMigemo)
188 m_hMigemo = 0
189 End If
190 End Sub
191