1 <?xml version=
"1.0" encoding=
"UTF-8"?>
2 <!DOCTYPE script:module PUBLIC
"-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
3 <script:module xmlns:
script=
"http://openoffice.org/2000/script" script:
name=
"i18n_XCharacterClassification" script:
language=
"StarBasic">
6 '*************************************************************************
8 ' DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
10 ' Copyright
2008 by Sun Microsystems, Inc.
12 ' OpenOffice.org - a multi-platform office productivity suite
14 ' $RCSfile: i18n_XCharacterClassification.xba,v $
18 ' This file is part of OpenOffice.org.
20 ' OpenOffice.org is free software: you can redistribute it and/or modify
21 ' it under the terms of the GNU Lesser General Public License version
3
22 ' only, as published by the Free Software Foundation.
24 ' OpenOffice.org is distributed in the hope that it will be useful,
25 ' but WITHOUT ANY WARRANTY; without even the implied warranty of
26 ' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 ' GNU Lesser General Public License version
3 for more details
28 ' (a copy is included in the LICENSE file that accompanied this code).
30 ' You should have received a copy of the GNU Lesser General Public License
31 ' version
3 along with OpenOffice.org. If not, see
32 '
<http://www.openoffice.org/license.html
>
33 ' for a copy of the LGPLv3 License.
35 '*************************************************************************
36 '*************************************************************************
40 ' Be sure that all variables are dimensioned:
47 '*************************************************************************
49 ' com.sun.star.i18n.XCharacterClassification
50 '*************************************************************************
54 Dim cString1 As String, cString2 As String
55 Dim cRes As Variant, sDir As Variant
57 Const cString =
"TestString1"
59 Dim Locale As New com.sun.star.lang.Locale
61 Locale.Language =
"DE"
62 Locale.Country =
"GERMANY"
65 Test.StartMethod(
"toUpper()")
67 cRes = oObj.toUpper(cString,
2,
3, Locale)
68 bOK = bOK AND Comp(cRes,
"STS")
69 Test.MethodTested(
"toUpper()", bOK)
71 Test.StartMethod(
"toLower()")
73 cRes = oObj.toLower(cString,
2,
3, Locale)
74 bOK = bOK AND Comp(cRes,
"sts")
75 Test.MethodTested(
"toLower()", bOK)
77 Test.StartMethod(
"toTitle()")
79 cRes = oObj.toTitle(cString,
2,
3, Locale)
80 bOK = bOK AND Comp(cRes,
"STS")
81 Test.MethodTested(
"toTitle()", bOK)
83 Test.StartMethod(
"getType()")
85 bOK = bOK AND oObj.getType(cString,
0)
<> oObj.getType(cString,
2)
86 Test.MethodTested(
"getType()", bOK)
88 Test.StartMethod(
"getCharacterDirection()")
90 sDir = oObj.getCharacterDirection(cString,
1)
91 bOK = bOK AND isNumeric(sDir)
92 Test.MethodTested(
"getCharacterDirection()", bOK)
94 Test.StartMethod(
"getScript()")
96 bOK = bOK AND isNUmeric(oObj.getScript(cString,
0))
97 Test.MethodTested(
"getScript()", bOK)
99 Test.StartMethod(
"getCharacterType()")
101 sType = oObj.getCharacterType(cString,
0, Locale)
102 bOK = bOK AND (sType AND com.sun.star.i18n.KCharacterType.UPPER)
103 bOK = bOK AND NOT (sType AND com.sun.star.i18n.KCharacterType.DIGIT)
104 bOK = bOK AND (sType AND com.sun.star.i18n.KCharacterType.BASE_FORM)
105 sType = oObj.getCharacterType(cString,
1, Locale)
106 bOK = bOK AND (sType AND com.sun.star.i18n.KCharacterType.LOWER)
107 bOK = bOK AND NOT (sType AND com.sun.star.i18n.KCharacterType.DIGIT)
108 bOK = bOK AND (sType AND com.sun.star.i18n.KCharacterType.BASE_FORM)
109 sType = oObj.getCharacterType(cString,
10, Locale)
110 bOK = bOK AND NOT (sType AND com.sun.star.i18n.KCharacterType.UPPER)
111 bOK = bOK AND (sType AND com.sun.star.i18n.KCharacterType.DIGIT)
112 bOK = bOK AND (sType AND com.sun.star.i18n.KCharacterType.BASE_FORM)
113 Test.MethodTested(
"getCharacterType()", bOK)
115 Test.StartMethod(
"getStringType()")
117 sType = oObj.getStringType(cString,
0,
10, Locale)
118 bOK = bOK AND (sType AND com.sun.star.i18n.KCharacterType.UPPER)
119 bOK = bOK AND (sType AND com.sun.star.i18n.KCharacterType.LOWER)
120 bOK = bOK AND (sType AND com.sun.star.i18n.KCharacterType.BASE_FORM)
121 bOK = bOK AND NOT (sType AND com.sun.star.i18n.KCharacterType.DIGIT)
122 sType = oObj.getStringType(cString,
0,
11, Locale)
123 bOK = bOK AND (sType AND com.sun.star.i18n.KCharacterType.UPPER)
124 bOK = bOK AND (sType AND com.sun.star.i18n.KCharacterType.LOWER)
125 bOK = bOK AND (sType AND com.sun.star.i18n.KCharacterType.BASE_FORM)
126 bOK = bOK AND (sType AND com.sun.star.i18n.KCharacterType.DIGIT)
127 Test.MethodTested(
"getStringType()", bOK)
129 Test.StartMethod(
"parseAnyToken()")
132 cString1 =
"int _ind1 = 1234;"
133 Out.Log (
"Parsing string: " + cString1)
134 Dim tTypes(
10) As Integer
135 Dim tVals(
10) As String
136 Dim nStartChartFlags As Variant, userDefinedCharactersStart As Variant
137 Dim nContCharFlags As Variant, userDefinedCharactersCont As Variant, nTokenType As Variant
139 with com.sun.star.i18n.KParseType
140 tTypes(
0) = .IDENTNAME: tVals(
0) =
"int"
141 tTypes(
1) = .IDENTNAME: tVals(
1) =
"_ind1"
142 tTypes(
2) = .ONE_SINGLE_CHAR: tVals(
2) =
"="
143 tTypes(
3) = .ANY_NUMBER: tVals(
3) =
"1234"
146 with com.sun.star.i18n.KParseTokens
147 nStartChartFlags = .ANY_ALPHA OR .IGNORE_LEADING_WS
148 userDefinedCharactersStart =
"_"
149 nContCharFlags = nStartChartFlags OR .ANY_ALNUM
150 userDefinedCharactersCont =
""
153 Dim nStart As Integer, idx As Integer, nPos As Integer
155 Dim cActStr As String
160 while nStart
< Len(cString1)
161 pRes = oObj.parseAnyToken(cString1, nStart -
1, Locale, nStartChartFlags, userDefinedCharactersStart, _
162 nContCharFlags, userDefinedCharactersCont)
164 Out.Log(
"Type is " + pRes.TokenType)
165 if (pRes.TokenType =
0) then
168 Out.Log(
"Type is as expexted - " + ((pRes.TokenType AND tTypes(idx))
> 0))
169 bOK = bOK AND (pRes.TokenType AND tTypes(idx))
170 cActStr = mid(cString1, (nStart + pRes.LeadingWhiteSpace), pRes.EndPos - (nStart + pRes.LeadingWhiteSpace) +
1)
171 Out.Log(
"Expected: '" + tVals(idx) +
"'; actual is: '" + cActStr +
"'")
172 bOK = bOK AND (cActStr = tVals(idx))
173 nStart = pRes.EndPos +
1
177 Test.MethodTested(
"parseAnyToken()", bOK)
179 Test.StartMethod(
"parsePredefinedToken()")
182 cString2 =
"1a, _a1$5"
183 with com.sun.star.i18n.KParseType
184 nTokenType = .IDENTNAME
186 with com.sun.star.i18n.KParseTokens
187 nStartChartFlags = .ANY_ALPHA OR .IGNORE_LEADING_WS
188 userDefinedCharactersStart =
"_"
189 nContCharFlags = nStartChartFlags OR .ANY_ALNUM
190 userDefinedCharactersCont =
""
198 while nPos
< Len(cString2)
199 pRes = oObj.parsePredefinedToken(nTokenType, cString2, nPos -
1, Locale, nStartChartFlags, userDefinedCharactersStart, _
200 nContCharFlags, userDefinedCharactersCont)
202 Out.Log(
"Type is " + pRes.TokenType)
203 if (pRes.TokenType =
0) then
206 bOK = bOK AND (pRes.TokenType AND tTypes(idx))
207 cActStr = mid(cString2, (nPos + pRes.LeadingWhiteSpace), pRes.EndPos - (nPos + pRes.LeadingWhiteSpace) +
1)
208 bOK = bOK AND Comp(cActStr, tVals(idx))
209 nPos = pRes.EndPos +
1
215 Test.MethodTested(
"parsePredefinedToken()", bOK)
223 Function Comp(cS1 As String, cS2 As String) As Boolean
224 Out.Log(
"Expected : '" + cS2 +
"', actual : '" + cS1 +
"'")