1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
|
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
<script:module xmlns:script="http://openoffice.org/2000/script" script:name="i18n_XCharacterClassification" script:language="StarBasic">
'*************************************************************************
'
' DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
'
' Copyright 2008 by Sun Microsystems, Inc.
'
' OpenOffice.org - a multi-platform office productivity suite
'
' $RCSfile: i18n_XCharacterClassification.xba,v $
'
' $Revision: 1.3 $
'
' This file is part of OpenOffice.org.
'
' OpenOffice.org is free software: you can redistribute it and/or modify
' it under the terms of the GNU Lesser General Public License version 3
' only, as published by the Free Software Foundation.
'
' OpenOffice.org is distributed in the hope that it will be useful,
' but WITHOUT ANY WARRANTY; without even the implied warranty of
' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
' GNU Lesser General Public License version 3 for more details
' (a copy is included in the LICENSE file that accompanied this code).
'
' You should have received a copy of the GNU Lesser General Public License
' version 3 along with OpenOffice.org. If not, see
' <http://www.openoffice.org/license.html>
' for a copy of the LGPLv3 License.
'
'*************************************************************************
'*************************************************************************
' Be sure that all variables are dimensioned:
option explicit
Sub RunTest()
'*************************************************************************
' INTERFACE:
' com.sun.star.i18n.XCharacterClassification
'*************************************************************************
On Error Goto ErrHndl
Dim bOK As Boolean
Dim sType As Variant
Dim cString1 As String, cString2 As String
Dim cRes As Variant, sDir As Variant
Const cString = "TestString1"
Dim Locale As New com.sun.star.lang.Locale
Locale.Language = "DE"
Locale.Country = "GERMANY"
Locale.Variant = ""
Test.StartMethod("toUpper()")
bOK = true
cRes = oObj.toUpper(cString, 2, 3, Locale)
bOK = bOK AND Comp(cRes, "STS")
Test.MethodTested("toUpper()", bOK)
Test.StartMethod("toLower()")
bOK = true
cRes = oObj.toLower(cString, 2, 3, Locale)
bOK = bOK AND Comp(cRes, "sts")
Test.MethodTested("toLower()", bOK)
Test.StartMethod("toTitle()")
bOK = true
cRes = oObj.toTitle(cString, 2, 3, Locale)
bOK = bOK AND Comp(cRes, "STS")
Test.MethodTested("toTitle()", bOK)
Test.StartMethod("getType()")
bOK = true
bOK = bOK AND oObj.getType(cString, 0) <> oObj.getType(cString, 2)
Test.MethodTested("getType()", bOK)
Test.StartMethod("getCharacterDirection()")
bOK = true
sDir = oObj.getCharacterDirection(cString, 1)
bOK = bOK AND isNumeric(sDir)
Test.MethodTested("getCharacterDirection()", bOK)
Test.StartMethod("getScript()")
bOK = true
bOK = bOK AND isNUmeric(oObj.getScript(cString, 0))
Test.MethodTested("getScript()", bOK)
Test.StartMethod("getCharacterType()")
bOK = true
sType = oObj.getCharacterType(cString, 0, Locale)
bOK = bOK AND (sType AND com.sun.star.i18n.KCharacterType.UPPER)
bOK = bOK AND NOT (sType AND com.sun.star.i18n.KCharacterType.DIGIT)
bOK = bOK AND (sType AND com.sun.star.i18n.KCharacterType.BASE_FORM)
sType = oObj.getCharacterType(cString, 1, Locale)
bOK = bOK AND (sType AND com.sun.star.i18n.KCharacterType.LOWER)
bOK = bOK AND NOT (sType AND com.sun.star.i18n.KCharacterType.DIGIT)
bOK = bOK AND (sType AND com.sun.star.i18n.KCharacterType.BASE_FORM)
sType = oObj.getCharacterType(cString, 10, Locale)
bOK = bOK AND NOT (sType AND com.sun.star.i18n.KCharacterType.UPPER)
bOK = bOK AND (sType AND com.sun.star.i18n.KCharacterType.DIGIT)
bOK = bOK AND (sType AND com.sun.star.i18n.KCharacterType.BASE_FORM)
Test.MethodTested("getCharacterType()", bOK)
Test.StartMethod("getStringType()")
bOK = true
sType = oObj.getStringType(cString, 0, 10, Locale)
bOK = bOK AND (sType AND com.sun.star.i18n.KCharacterType.UPPER)
bOK = bOK AND (sType AND com.sun.star.i18n.KCharacterType.LOWER)
bOK = bOK AND (sType AND com.sun.star.i18n.KCharacterType.BASE_FORM)
bOK = bOK AND NOT (sType AND com.sun.star.i18n.KCharacterType.DIGIT)
sType = oObj.getStringType(cString, 0, 11, Locale)
bOK = bOK AND (sType AND com.sun.star.i18n.KCharacterType.UPPER)
bOK = bOK AND (sType AND com.sun.star.i18n.KCharacterType.LOWER)
bOK = bOK AND (sType AND com.sun.star.i18n.KCharacterType.BASE_FORM)
bOK = bOK AND (sType AND com.sun.star.i18n.KCharacterType.DIGIT)
Test.MethodTested("getStringType()", bOK)
Test.StartMethod("parseAnyToken()")
bOK = true
cString1 = "int _ind1 = 1234;"
Out.Log ("Parsing string: " + cString1)
Dim tTypes(10) As Integer
Dim tVals(10) As String
Dim nStartChartFlags As Variant, userDefinedCharactersStart As Variant
Dim nContCharFlags As Variant, userDefinedCharactersCont As Variant, nTokenType As Variant
with com.sun.star.i18n.KParseType
tTypes(0) = .IDENTNAME: tVals(0) = "int"
tTypes(1) = .IDENTNAME: tVals(1) = "_ind1"
tTypes(2) = .ONE_SINGLE_CHAR: tVals(2) = "="
tTypes(3) = .ANY_NUMBER: tVals(3) = "1234"
end with
with com.sun.star.i18n.KParseTokens
nStartChartFlags = .ANY_ALPHA OR .IGNORE_LEADING_WS
userDefinedCharactersStart = "_"
nContCharFlags = nStartChartFlags OR .ANY_ALNUM
userDefinedCharactersCont = ""
end with
Dim nStart As Integer, idx As Integer, nPos As Integer
Dim pRes As Variant
Dim cActStr As String
nStart = 1
idx = 0
while nStart < Len(cString1)
pRes = oObj.parseAnyToken(cString1, nStart - 1, Locale, nStartChartFlags, userDefinedCharactersStart, _
nContCharFlags, userDefinedCharactersCont)
Out.Log("Type is " + pRes.TokenType)
if (pRes.TokenType = 0) then
nStart = nStart + 1
else
Out.Log("Type is as expexted - " + ((pRes.TokenType AND tTypes(idx)) > 0))
bOK = bOK AND (pRes.TokenType AND tTypes(idx))
cActStr = mid(cString1, (nStart + pRes.LeadingWhiteSpace), pRes.EndPos - (nStart + pRes.LeadingWhiteSpace) + 1)
Out.Log("Expected: '" + tVals(idx) + "'; actual is: '" + cActStr + "'")
bOK = bOK AND (cActStr = tVals(idx))
nStart = pRes.EndPos + 1
end if
idx = idx + 1
wend
Test.MethodTested("parseAnyToken()", bOK)
Test.StartMethod("parsePredefinedToken()")
bOK = true
cString2 = "1a, _a1$5"
with com.sun.star.i18n.KParseType
nTokenType = .IDENTNAME
end with
with com.sun.star.i18n.KParseTokens
nStartChartFlags = .ANY_ALPHA OR .IGNORE_LEADING_WS
userDefinedCharactersStart = "_"
nContCharFlags = nStartChartFlags OR .ANY_ALNUM
userDefinedCharactersCont = ""
end with
tVals(0) = "a"
tVals(1) = "_a1"
nPos = 1
idx = 0
while nPos < Len(cString2)
pRes = oObj.parsePredefinedToken(nTokenType, cString2, nPos - 1, Locale, nStartChartFlags, userDefinedCharactersStart, _
nContCharFlags, userDefinedCharactersCont)
Out.Log("Type is " + pRes.TokenType)
if (pRes.TokenType = 0) then
nPos = nPos + 1
else
bOK = bOK AND (pRes.TokenType AND tTypes(idx))
cActStr = mid(cString2, (nPos + pRes.LeadingWhiteSpace), pRes.EndPos - (nPos + pRes.LeadingWhiteSpace) + 1)
bOK = bOK AND Comp(cActStr, tVals(idx))
nPos = pRes.EndPos + 1
idx = idx + 1
end if
wend
bOK = bOK AND true
Test.MethodTested("parsePredefinedToken()", bOK)
Exit Sub
ErrHndl:
Test.Exception()
bOK = false
resume next
End Sub
Function Comp(cS1 As String, cS2 As String) As Boolean
Out.Log("Expected : '" + cS2 + "', actual : '" + cS1 + "'")
Comp = cS1 = cS2
End Function
</script:module>
|