1VERSION 1.0 CLASS
2BEGIN
3  MultiUse = -1  'True
4  Persistable = 0  'NotPersistable
5  DataBindingBehavior = 0  'vbNone
6  DataSourceBehavior  = 0  'vbNone
7  MTSTransactionMode  = 0  'NotAnMTSObject
8END
9Attribute VB_Name = "clsMigemo"
10Attribute VB_GlobalNameSpace = False
11Attribute VB_Creatable = True
12Attribute VB_PredeclaredId = False
13Attribute VB_Exposed = False
14Attribute VB_Ext_KEY = "SavedWithClassBuilder6" ,"Yes"
15Attribute VB_Ext_KEY = "Top_Level" ,"Yes"
16Option Explicit
17
18Public Enum DictionaryId
19    enmInvalid = 0
20    enmMigemo = 1
21    enmRomaToHira = 2
22    enmHiraToKata = 3
23    enmHanToZen = 4
24    enmZenToHan = 5
25End Enum
26
27Public Enum OperatorIndex
28    enmOr = 0
29    enmNestIn = 1
30    enmNestOut = 2
31    enmSelectIn = 3
32    enmSelectOut = 4
33    enmNewLine = 5
34End Enum
35
36Private Const enmDictMigemo = "migemo-dict"
37Private Const enmDictRoma2Hira = "roma2hira.dat"
38Private Const enmDictHira2Kata = "hira2kata.dat"
39Private Const enmDictHan2Zen = "han2zen.dat"
40Private Const enmDictZen2Han = "zen2han.dat"
41
42Private Declare Function migemo_open Lib "migemo.dll" (ByVal strDict As String) As Long
43Private Declare Sub migemo_close Lib "migemo.dll" (ByVal hMigemo As Long)
44Private Declare Function migemo_query Lib "migemo.dll" (ByVal hMigemo As Long, ByVal strQuery As String) As Long
45Private Declare Sub migemo_release Lib "migemo.dll" (ByVal hMigemo As Long, ByVal pAnswer As Long)
46Private Declare Function migemo_set_operator Lib "migemo.dll" (ByVal hMigemo As Long, ByVal EnmIndex As OperatorIndex, ByVal strOp As String) As Long
47Private Declare Function migemo_get_operator Lib "migemo.dll" (ByVal hMigemo As Long, ByVal EnmIndex As OperatorIndex) As Long
48Private Declare Function migemo_load Lib "migemo.dll" (ByVal hMigemo As Long, ByVal EnmDict As DictionaryId, ByVal strFile As String) As DictionaryId
49Private Declare Function migemo_is_enable Lib "migemo.dll" (ByVal hMigemo As Long) As Long
50Private Declare Sub CopyMemory Lib "kernel32.dll" Alias "RtlMoveMemory" (pTo As Any, uFrom As Any, ByVal lSize As Long)
51Private Declare Function StrLen Lib "kernel32.dll" Alias "lstrlen" (ByVal Ptr As Long) As Long
52
53Private m_hMigemo As Long
54
55Private 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
67End Function
68
69Private Sub Class_Initialize()
70    m_hMigemo = migemo_open(0)
71    OperatorNestIn = "(?:"
72End Sub
73
74Private Sub Class_Terminate()
75    If m_hMigemo Then
76        Call migemo_close(m_hMigemo)
77        m_hMigemo = 0
78    End If
79End Sub
80
81Public Function SetOperator(EnmIndex As OperatorIndex, strOp As String) As Boolean
82    SetOperator = migemo_set_operator(m_hMigemo, EnmIndex, strOp)
83End Function
84
85Public Function GetOperator(EnmIndex As OperatorIndex) As String
86    GetOperator = StrConv(PtrStr(migemo_get_operator(m_hMigemo, EnmIndex)), vbUnicode)
87End Function
88
89Public Property Let OperatorOr(ByVal strOp As String)
90    Call SetOperator(enmOr, strOp)
91End Property
92
93Public Property Get OperatorOr() As String
94    OperatorOr = GetOperator(enmOr)
95End Property
96
97Public Property Let OperatorNestIn(ByVal strOp As String)
98    Call SetOperator(enmNestIn, strOp)
99End Property
100
101Public Property Get OperatorNestIn() As String
102    OperatorNestIn = GetOperator(enmNestIn)
103End Property
104
105Public Property Let OperatorNestOut(ByVal strOp As String)
106    Call SetOperator(enmNestOut, strOp)
107End Property
108
109Public Property Get OperatorNestOut() As String
110    OperatorNestOut = GetOperator(enmNestOut)
111End Property
112
113Public Property Let OperatorSelectIn(ByVal strOp As String)
114    Call SetOperator(enmSelectIn, strOp)
115End Property
116
117Public Property Get OperatorSelectIn() As String
118    OperatorSelectIn = GetOperator(enmSelectIn)
119End Property
120
121Public Property Let OperatorSelectOut(ByVal strOp As String)
122    Call SetOperator(enmSelectOut, strOp)
123End Property
124
125Public Property Get OperatorSelectOut() As String
126    OperatorSelectOut = GetOperator(enmSelectOut)
127End Property
128
129Public Property Let OperatorNewLine(ByVal strOp As String)
130    Call SetOperator(enmNewLine, strOp)
131End Property
132
133Public Property Get OperatorNewLine() As String
134    OperatorNewLine = GetOperator(enmNewLine)
135End Property
136
137Public 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
142End Function
143
144Public 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
163End Function
164
165Public Function IsEnable() As Boolean
166    IsEnable = migemo_is_enable(m_hMigemo)
167End Function
168
169Public Function GetRegex(strQuery As String) As Object
170    Set GetRegex = CreateObject("VBScript.RegExp")
171    GetRegex.Pattern = Query(strQuery)
172End Function
173
174Public 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
183End Function
184
185Public Sub Dispose()
186    If m_hMigemo Then
187        Call migemo_close(m_hMigemo)
188        m_hMigemo = 0
189    End If
190End Sub
191
192