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="util_XTextSearch" script:language="StarBasic">
4
5
6'*************************************************************************
7'
8'  Licensed to the Apache Software Foundation (ASF) under one
9'  or more contributor license agreements.  See the NOTICE file
10'  distributed with this work for additional information
11'  regarding copyright ownership.  The ASF licenses this file
12'  to you under the Apache License, Version 2.0 (the
13'  "License"); you may not use this file except in compliance
14'  with the License.  You may obtain a copy of the License at
15'
16'    http://www.apache.org/licenses/LICENSE-2.0
17'
18'  Unless required by applicable law or agreed to in writing,
19'  software distributed under the License is distributed on an
20'  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21'  KIND, either express or implied.  See the License for the
22'  specific language governing permissions and limitations
23'  under the License.
24'
25'*************************************************************************
26
27
28
29
30
31' Be sure that all variables are dimensioned:
32option explicit
33
34
35
36Sub RunTest()
37
38'*************************************************************************
39' INTERFACE:
40' com.sun.star.util.XTextSearch
41'*************************************************************************
42On Error Goto ErrHndl
43    Dim bOK As Boolean
44
45    Dim _Locale As new com.sun.star.lang.Locale
46    _Locale.Country = "US"
47    _Locale.Language = "en"
48
49    Test.StartMethod("setOptions()")
50    bOK = true
51    Dim aSearchOptions As new com.sun.star.util.SearchOptions
52    aSearchOptions.algorithmType = com.sun.star.util.SearchAlgorithms.REGEXP
53    aSearchOptions.searchFlag = com.sun.star.util.SearchFlags.ALL_IGNORE_CASE
54    aSearchOptions.searchString = "h[ae](k|l|j)+o" 'Should work because of ALL_IGNORE_CASE!
55    aSearchOptions.Locale = _Locale
56    oObj.setOptions(aSearchOptions)
57    Test.MethodTested("setOptions()", bOK)
58
59    Test.StartMethod("searchForward()")
60    bOK = true
61    Dim _string As String
62    Dim _result As Variant
63
64    _string = "String with 'Hello' and 'Hallo'."
65    _result = oObj.searchForward(_string, 0, len(_string))
66    if (ubound(_result.startOffset()) &gt;= 0) then
67        bOK = bOK AND _result.startOffset(0) = 13
68        bOK = bOK AND _result.endOffset(0) = 18
69        _result = oObj.searchForward(_string, 18, len(_string))
70        bOK = bOK AND _result.startOffset(0) = 25
71        bOK = bOK AND _result.endOffset(0) = 30
72    else
73        Out.Log("No matches were found!")
74        bOK = false
75    end if
76    Test.MethodTested("searchForward()", bOK)
77
78    Test.StartMethod("searchBackward()")
79    bOK = true
80    _result = oObj.searchBackward(_string, len(_string), 0)
81    if (ubound(_result.startOffset()) &gt;= 0) then
82        bOK = bOK AND _result.startOffset(0) = 30
83        bOK = bOK AND _result.endOffset(0) = 25
84        _result = oObj.searchBackward(_string, _result.endOffset(0), 0)
85        bOK = bOK AND _result.startOffset(0) = 18
86        bOK = bOK AND _result.endOffset(0) = 13
87    else
88        Out.Log("No matches were found!")
89        bOK = false
90    end if
91    Test.MethodTested("searchBackward()", bOK)
92
93Exit Sub
94ErrHndl:
95    Test.Exception()
96    bOK = false
97    resume next
98End Sub
99</script:module>
100