1*b1cdbd2cSJim Jagielski<?xml version="1.0" encoding="UTF-8"?>
2*b1cdbd2cSJim Jagielski<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
3*b1cdbd2cSJim Jagielski<script:module xmlns:script="http://openoffice.org/2000/script" script:name="i18n_XCharacterClassification" script:language="StarBasic">
4*b1cdbd2cSJim Jagielski
5*b1cdbd2cSJim Jagielski
6*b1cdbd2cSJim Jagielski'*************************************************************************
7*b1cdbd2cSJim Jagielski'
8*b1cdbd2cSJim Jagielski'  Licensed to the Apache Software Foundation (ASF) under one
9*b1cdbd2cSJim Jagielski'  or more contributor license agreements.  See the NOTICE file
10*b1cdbd2cSJim Jagielski'  distributed with this work for additional information
11*b1cdbd2cSJim Jagielski'  regarding copyright ownership.  The ASF licenses this file
12*b1cdbd2cSJim Jagielski'  to you under the Apache License, Version 2.0 (the
13*b1cdbd2cSJim Jagielski'  "License"); you may not use this file except in compliance
14*b1cdbd2cSJim Jagielski'  with the License.  You may obtain a copy of the License at
15*b1cdbd2cSJim Jagielski'
16*b1cdbd2cSJim Jagielski'    http://www.apache.org/licenses/LICENSE-2.0
17*b1cdbd2cSJim Jagielski'
18*b1cdbd2cSJim Jagielski'  Unless required by applicable law or agreed to in writing,
19*b1cdbd2cSJim Jagielski'  software distributed under the License is distributed on an
20*b1cdbd2cSJim Jagielski'  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21*b1cdbd2cSJim Jagielski'  KIND, either express or implied.  See the License for the
22*b1cdbd2cSJim Jagielski'  specific language governing permissions and limitations
23*b1cdbd2cSJim Jagielski'  under the License.
24*b1cdbd2cSJim Jagielski'
25*b1cdbd2cSJim Jagielski'*************************************************************************
26*b1cdbd2cSJim Jagielski
27*b1cdbd2cSJim Jagielski
28*b1cdbd2cSJim Jagielski
29*b1cdbd2cSJim Jagielski
30*b1cdbd2cSJim Jagielski
31*b1cdbd2cSJim Jagielski' Be sure that all variables are dimensioned:
32*b1cdbd2cSJim Jagielskioption explicit
33*b1cdbd2cSJim Jagielski
34*b1cdbd2cSJim Jagielski
35*b1cdbd2cSJim Jagielski
36*b1cdbd2cSJim JagielskiSub RunTest()
37*b1cdbd2cSJim Jagielski
38*b1cdbd2cSJim Jagielski'*************************************************************************
39*b1cdbd2cSJim Jagielski' INTERFACE:
40*b1cdbd2cSJim Jagielski' com.sun.star.i18n.XCharacterClassification
41*b1cdbd2cSJim Jagielski'*************************************************************************
42*b1cdbd2cSJim JagielskiOn Error Goto ErrHndl
43*b1cdbd2cSJim Jagielski    Dim bOK As Boolean
44*b1cdbd2cSJim Jagielski    Dim sType As Variant
45*b1cdbd2cSJim Jagielski    Dim cString1 As String, cString2 As String
46*b1cdbd2cSJim Jagielski    Dim cRes As Variant, sDir As Variant
47*b1cdbd2cSJim Jagielski
48*b1cdbd2cSJim Jagielski    Const cString = "TestString1"
49*b1cdbd2cSJim Jagielski
50*b1cdbd2cSJim Jagielski    Dim Locale As New com.sun.star.lang.Locale
51*b1cdbd2cSJim Jagielski
52*b1cdbd2cSJim Jagielski    Locale.Language = "DE"
53*b1cdbd2cSJim Jagielski    Locale.Country = "GERMANY"
54*b1cdbd2cSJim Jagielski    Locale.Variant = ""
55*b1cdbd2cSJim Jagielski
56*b1cdbd2cSJim Jagielski    Test.StartMethod("toUpper()")
57*b1cdbd2cSJim Jagielski    bOK = true
58*b1cdbd2cSJim Jagielski    cRes = oObj.toUpper(cString, 2, 3, Locale)
59*b1cdbd2cSJim Jagielski    bOK = bOK AND Comp(cRes, "STS")
60*b1cdbd2cSJim Jagielski    Test.MethodTested("toUpper()", bOK)
61*b1cdbd2cSJim Jagielski
62*b1cdbd2cSJim Jagielski    Test.StartMethod("toLower()")
63*b1cdbd2cSJim Jagielski    bOK = true
64*b1cdbd2cSJim Jagielski    cRes = oObj.toLower(cString, 2, 3, Locale)
65*b1cdbd2cSJim Jagielski    bOK = bOK AND Comp(cRes, "sts")
66*b1cdbd2cSJim Jagielski    Test.MethodTested("toLower()", bOK)
67*b1cdbd2cSJim Jagielski
68*b1cdbd2cSJim Jagielski    Test.StartMethod("toTitle()")
69*b1cdbd2cSJim Jagielski    bOK = true
70*b1cdbd2cSJim Jagielski    cRes = oObj.toTitle(cString, 2, 3, Locale)
71*b1cdbd2cSJim Jagielski    bOK = bOK AND Comp(cRes, "STS")
72*b1cdbd2cSJim Jagielski    Test.MethodTested("toTitle()", bOK)
73*b1cdbd2cSJim Jagielski
74*b1cdbd2cSJim Jagielski    Test.StartMethod("getType()")
75*b1cdbd2cSJim Jagielski    bOK = true
76*b1cdbd2cSJim Jagielski    bOK = bOK AND oObj.getType(cString, 0) &lt;&gt; oObj.getType(cString, 2)
77*b1cdbd2cSJim Jagielski    Test.MethodTested("getType()", bOK)
78*b1cdbd2cSJim Jagielski
79*b1cdbd2cSJim Jagielski    Test.StartMethod("getCharacterDirection()")
80*b1cdbd2cSJim Jagielski    bOK = true
81*b1cdbd2cSJim Jagielski    sDir = oObj.getCharacterDirection(cString, 1)
82*b1cdbd2cSJim Jagielski    bOK = bOK AND isNumeric(sDir)
83*b1cdbd2cSJim Jagielski    Test.MethodTested("getCharacterDirection()", bOK)
84*b1cdbd2cSJim Jagielski
85*b1cdbd2cSJim Jagielski    Test.StartMethod("getScript()")
86*b1cdbd2cSJim Jagielski    bOK = true
87*b1cdbd2cSJim Jagielski    bOK = bOK AND isNUmeric(oObj.getScript(cString, 0))
88*b1cdbd2cSJim Jagielski    Test.MethodTested("getScript()", bOK)
89*b1cdbd2cSJim Jagielski
90*b1cdbd2cSJim Jagielski    Test.StartMethod("getCharacterType()")
91*b1cdbd2cSJim Jagielski    bOK = true
92*b1cdbd2cSJim Jagielski    sType = oObj.getCharacterType(cString,  0, Locale)
93*b1cdbd2cSJim Jagielski    bOK = bOK AND (sType AND com.sun.star.i18n.KCharacterType.UPPER)
94*b1cdbd2cSJim Jagielski    bOK = bOK AND NOT (sType AND com.sun.star.i18n.KCharacterType.DIGIT)
95*b1cdbd2cSJim Jagielski    bOK = bOK AND (sType AND com.sun.star.i18n.KCharacterType.BASE_FORM)
96*b1cdbd2cSJim Jagielski    sType = oObj.getCharacterType(cString,  1, Locale)
97*b1cdbd2cSJim Jagielski    bOK = bOK AND (sType AND com.sun.star.i18n.KCharacterType.LOWER)
98*b1cdbd2cSJim Jagielski    bOK = bOK AND NOT (sType AND com.sun.star.i18n.KCharacterType.DIGIT)
99*b1cdbd2cSJim Jagielski    bOK = bOK AND (sType AND com.sun.star.i18n.KCharacterType.BASE_FORM)
100*b1cdbd2cSJim Jagielski    sType = oObj.getCharacterType(cString, 10, Locale)
101*b1cdbd2cSJim Jagielski    bOK = bOK AND NOT (sType AND com.sun.star.i18n.KCharacterType.UPPER)
102*b1cdbd2cSJim Jagielski    bOK = bOK AND (sType AND com.sun.star.i18n.KCharacterType.DIGIT)
103*b1cdbd2cSJim Jagielski    bOK = bOK AND (sType AND com.sun.star.i18n.KCharacterType.BASE_FORM)
104*b1cdbd2cSJim Jagielski    Test.MethodTested("getCharacterType()", bOK)
105*b1cdbd2cSJim Jagielski
106*b1cdbd2cSJim Jagielski    Test.StartMethod("getStringType()")
107*b1cdbd2cSJim Jagielski    bOK = true
108*b1cdbd2cSJim Jagielski    sType = oObj.getStringType(cString, 0, 10, Locale)
109*b1cdbd2cSJim Jagielski    bOK = bOK AND (sType AND com.sun.star.i18n.KCharacterType.UPPER)
110*b1cdbd2cSJim Jagielski    bOK = bOK AND (sType AND com.sun.star.i18n.KCharacterType.LOWER)
111*b1cdbd2cSJim Jagielski    bOK = bOK AND (sType AND com.sun.star.i18n.KCharacterType.BASE_FORM)
112*b1cdbd2cSJim Jagielski    bOK = bOK AND NOT (sType AND com.sun.star.i18n.KCharacterType.DIGIT)
113*b1cdbd2cSJim Jagielski    sType = oObj.getStringType(cString, 0, 11, Locale)
114*b1cdbd2cSJim Jagielski    bOK = bOK AND (sType AND com.sun.star.i18n.KCharacterType.UPPER)
115*b1cdbd2cSJim Jagielski    bOK = bOK AND (sType AND com.sun.star.i18n.KCharacterType.LOWER)
116*b1cdbd2cSJim Jagielski    bOK = bOK AND (sType AND com.sun.star.i18n.KCharacterType.BASE_FORM)
117*b1cdbd2cSJim Jagielski    bOK = bOK AND (sType AND com.sun.star.i18n.KCharacterType.DIGIT)
118*b1cdbd2cSJim Jagielski    Test.MethodTested("getStringType()", bOK)
119*b1cdbd2cSJim Jagielski
120*b1cdbd2cSJim Jagielski    Test.StartMethod("parseAnyToken()")
121*b1cdbd2cSJim Jagielski    bOK = true
122*b1cdbd2cSJim Jagielski
123*b1cdbd2cSJim Jagielski    cString1 = "int _ind1 = 1234;"
124*b1cdbd2cSJim Jagielski    Out.Log ("Parsing string: " + cString1)
125*b1cdbd2cSJim Jagielski    Dim tTypes(10) As Integer
126*b1cdbd2cSJim Jagielski    Dim tVals(10) As String
127*b1cdbd2cSJim Jagielski    Dim nStartChartFlags As Variant, userDefinedCharactersStart As Variant
128*b1cdbd2cSJim Jagielski    Dim nContCharFlags As Variant, userDefinedCharactersCont As Variant, nTokenType As Variant
129*b1cdbd2cSJim Jagielski
130*b1cdbd2cSJim Jagielski   	with com.sun.star.i18n.KParseType
131*b1cdbd2cSJim Jagielski        tTypes(0) = .IDENTNAME: tVals(0) = "int"
132*b1cdbd2cSJim Jagielski        tTypes(1) = .IDENTNAME: tVals(1) = "_ind1"
133*b1cdbd2cSJim Jagielski        tTypes(2) = .ONE_SINGLE_CHAR: tVals(2) = "="
134*b1cdbd2cSJim Jagielski        tTypes(3) = .ANY_NUMBER: tVals(3) = "1234"
135*b1cdbd2cSJim Jagielski    end with
136*b1cdbd2cSJim Jagielski
137*b1cdbd2cSJim Jagielski    with com.sun.star.i18n.KParseTokens
138*b1cdbd2cSJim Jagielski        nStartChartFlags = .ANY_ALPHA OR .IGNORE_LEADING_WS
139*b1cdbd2cSJim Jagielski        userDefinedCharactersStart = "_"
140*b1cdbd2cSJim Jagielski        nContCharFlags = nStartChartFlags OR .ANY_ALNUM
141*b1cdbd2cSJim Jagielski        userDefinedCharactersCont = ""
142*b1cdbd2cSJim Jagielski    end with
143*b1cdbd2cSJim Jagielski
144*b1cdbd2cSJim Jagielski    Dim nStart As Integer, idx As Integer, nPos As Integer
145*b1cdbd2cSJim Jagielski    Dim pRes As Variant
146*b1cdbd2cSJim Jagielski    Dim cActStr As String
147*b1cdbd2cSJim Jagielski
148*b1cdbd2cSJim Jagielski    nStart = 1
149*b1cdbd2cSJim Jagielski    idx = 0
150*b1cdbd2cSJim Jagielski
151*b1cdbd2cSJim Jagielski    while nStart &lt; Len(cString1)
152*b1cdbd2cSJim Jagielski       	pRes = oObj.parseAnyToken(cString1, nStart - 1, Locale, nStartChartFlags, userDefinedCharactersStart, _
153*b1cdbd2cSJim Jagielski   	        nContCharFlags, userDefinedCharactersCont)
154*b1cdbd2cSJim Jagielski
155*b1cdbd2cSJim Jagielski      Out.Log("Type is " + pRes.TokenType)
156*b1cdbd2cSJim Jagielski   		if (pRes.TokenType = 0) then
157*b1cdbd2cSJim Jagielski          nStart = nStart + 1
158*b1cdbd2cSJim Jagielski   		else
159*b1cdbd2cSJim Jagielski          Out.Log("Type is as expexted - " + ((pRes.TokenType AND tTypes(idx)) &gt; 0))
160*b1cdbd2cSJim Jagielski          bOK = bOK AND (pRes.TokenType AND tTypes(idx))
161*b1cdbd2cSJim Jagielski          cActStr = mid(cString1, (nStart + pRes.LeadingWhiteSpace), pRes.EndPos - (nStart + pRes.LeadingWhiteSpace) + 1)
162*b1cdbd2cSJim Jagielski          Out.Log("Expected: '" + tVals(idx) + "'; actual is: '" + cActStr + "'")
163*b1cdbd2cSJim Jagielski          bOK = bOK AND (cActStr = tVals(idx))
164*b1cdbd2cSJim Jagielski          nStart = pRes.EndPos + 1
165*b1cdbd2cSJim Jagielski      end if
166*b1cdbd2cSJim Jagielski      idx = idx + 1
167*b1cdbd2cSJim Jagielski    wend
168*b1cdbd2cSJim Jagielski    Test.MethodTested("parseAnyToken()", bOK)
169*b1cdbd2cSJim Jagielski
170*b1cdbd2cSJim Jagielski    Test.StartMethod("parsePredefinedToken()")
171*b1cdbd2cSJim Jagielski    bOK = true
172*b1cdbd2cSJim Jagielski
173*b1cdbd2cSJim Jagielski    cString2 = "1a, _a1$5"
174*b1cdbd2cSJim Jagielski   	with com.sun.star.i18n.KParseType
175*b1cdbd2cSJim Jagielski        nTokenType = .IDENTNAME
176*b1cdbd2cSJim Jagielski    end with
177*b1cdbd2cSJim Jagielski    with com.sun.star.i18n.KParseTokens
178*b1cdbd2cSJim Jagielski        nStartChartFlags = .ANY_ALPHA OR .IGNORE_LEADING_WS
179*b1cdbd2cSJim Jagielski        userDefinedCharactersStart = "_"
180*b1cdbd2cSJim Jagielski        nContCharFlags = nStartChartFlags OR .ANY_ALNUM
181*b1cdbd2cSJim Jagielski        userDefinedCharactersCont = ""
182*b1cdbd2cSJim Jagielski    end with
183*b1cdbd2cSJim Jagielski
184*b1cdbd2cSJim Jagielski    tVals(0) = "a"
185*b1cdbd2cSJim Jagielski    tVals(1) = "_a1"
186*b1cdbd2cSJim Jagielski
187*b1cdbd2cSJim Jagielski    nPos = 1
188*b1cdbd2cSJim Jagielski    idx = 0
189*b1cdbd2cSJim Jagielski    while nPos &lt; Len(cString2)
190*b1cdbd2cSJim Jagielski       	pRes = oObj.parsePredefinedToken(nTokenType, cString2, nPos - 1, Locale, nStartChartFlags, userDefinedCharactersStart, _
191*b1cdbd2cSJim Jagielski   	        nContCharFlags, userDefinedCharactersCont)
192*b1cdbd2cSJim Jagielski
193*b1cdbd2cSJim Jagielski        Out.Log("Type is " + pRes.TokenType)
194*b1cdbd2cSJim Jagielski        if (pRes.TokenType = 0) then
195*b1cdbd2cSJim Jagielski            nPos = nPos + 1
196*b1cdbd2cSJim Jagielski        else
197*b1cdbd2cSJim Jagielski            bOK = bOK AND (pRes.TokenType AND tTypes(idx))
198*b1cdbd2cSJim Jagielski            cActStr = mid(cString2, (nPos + pRes.LeadingWhiteSpace), pRes.EndPos - (nPos + pRes.LeadingWhiteSpace) + 1)
199*b1cdbd2cSJim Jagielski            bOK = bOK AND Comp(cActStr, tVals(idx))
200*b1cdbd2cSJim Jagielski            nPos = pRes.EndPos + 1
201*b1cdbd2cSJim Jagielski            idx = idx + 1
202*b1cdbd2cSJim Jagielski        end if
203*b1cdbd2cSJim Jagielski    wend
204*b1cdbd2cSJim Jagielski
205*b1cdbd2cSJim Jagielski    bOK = bOK AND true
206*b1cdbd2cSJim Jagielski    Test.MethodTested("parsePredefinedToken()", bOK)
207*b1cdbd2cSJim Jagielski
208*b1cdbd2cSJim JagielskiExit Sub
209*b1cdbd2cSJim JagielskiErrHndl:
210*b1cdbd2cSJim Jagielski    Test.Exception()
211*b1cdbd2cSJim Jagielski    bOK = false
212*b1cdbd2cSJim Jagielski    resume next
213*b1cdbd2cSJim JagielskiEnd Sub
214*b1cdbd2cSJim JagielskiFunction Comp(cS1 As String, cS2 As String) As Boolean
215*b1cdbd2cSJim Jagielski    Out.Log("Expected : '" + cS2 + "', actual : '" + cS1 + "'")
216*b1cdbd2cSJim Jagielski    Comp = cS1 = cS2
217*b1cdbd2cSJim JagielskiEnd Function
218*b1cdbd2cSJim Jagielski</script:module>
219