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