21
21
*/
22
22
package org .exist .xquery .functions .fn ;
23
23
24
+ import java .util .regex .Pattern ;
24
25
import java .util .regex .PatternSyntaxException ;
25
26
26
27
import org .exist .dom .QName ;
27
28
import org .exist .util .PatternFactory ;
28
- import org .exist .xquery .Dependency ;
29
- import org .exist .xquery .ErrorCodes ;
30
- import org .exist .xquery .Function ;
31
- import org .exist .xquery .FunctionSignature ;
32
- import org .exist .xquery .Profiler ;
33
- import org .exist .xquery .XPathException ;
34
- import org .exist .xquery .XQueryContext ;
29
+ import org .exist .xquery .*;
35
30
import org .exist .xquery .value .FunctionParameterSequenceType ;
36
- import org .exist .xquery .value .Item ;
37
31
import org .exist .xquery .value .Sequence ;
38
32
import org .exist .xquery .value .StringValue ;
39
33
import org .exist .xquery .value .Type ;
46
40
* @author <a href="mailto:[email protected] ">Wolfgang Meier</a>
47
41
* @see <a href="https://www.w3.org/TR/xpath-functions-31/#func-tokenize">https://www.w3.org/TR/xpath-functions-31/#func-tokenize</a>
48
42
*/
49
- public class FunTokenize extends FunMatches {
43
+ public class FunTokenize extends BasicFunction {
50
44
51
45
private static final QName FS_TOKENIZE_NAME = new QName ("tokenize" , Function .BUILTIN_FUNCTION_NS );
52
46
@@ -78,20 +72,9 @@ public FunTokenize(final XQueryContext context, final FunctionSignature signatur
78
72
}
79
73
80
74
@ Override
81
- public Sequence eval (final Sequence contextSequence , final Item contextItem ) throws XPathException {
82
- if (context .getProfiler ().isEnabled ()) {
83
- context .getProfiler ().start (this );
84
- context .getProfiler ().message (this , Profiler .DEPENDENCIES , "DEPENDENCIES" , Dependency .getDependenciesName (this .getDependencies ()));
85
- if (contextSequence != null ) {
86
- context .getProfiler ().message (this , Profiler .START_SEQUENCES , "CONTEXT SEQUENCE" , contextSequence );
87
- }
88
- if (contextItem != null ) {
89
- context .getProfiler ().message (this , Profiler .START_SEQUENCES , "CONTEXT ITEM" , contextItem .toSequence ());
90
- }
91
- }
92
-
75
+ public Sequence eval (final Sequence [] args , final Sequence contextSequence ) throws XPathException {
93
76
final Sequence result ;
94
- final Sequence stringArg = getArgument ( 0 ). eval ( contextSequence , contextItem ) ;
77
+ final Sequence stringArg = args [ 0 ] ;
95
78
if (stringArg .isEmpty ()) {
96
79
result = Sequence .EMPTY_SEQUENCE ;
97
80
} else {
@@ -100,34 +83,30 @@ public Sequence eval(final Sequence contextSequence, final Item contextItem) thr
100
83
result = Sequence .EMPTY_SEQUENCE ;
101
84
} else {
102
85
final int flags ;
103
- if (getSignature ().getArgumentCount () == 3 ) {
104
- flags = parseFlags (this , getArgument (2 ).eval (contextSequence , contextItem )
105
- .getStringValue ());
86
+ if (args .length == 3 ) {
87
+ flags = parseFlags (this , args [2 ].itemAt (0 ).getStringValue ());
106
88
} else {
107
89
flags = 0 ;
108
90
}
109
91
110
92
final String pattern ;
111
- if ( getArgumentCount () == 1 ) {
93
+ if ( args . length == 1 ) {
112
94
pattern = " " ;
113
95
string = FunNormalizeSpace .normalize (string );
114
96
} else {
115
97
if (hasLiteral (flags )) {
116
98
// no need to change anything
117
- pattern = getArgument ( 1 ). eval ( contextSequence , contextItem ).getStringValue ();
99
+ pattern = args [ 1 ]. itemAt ( 0 ).getStringValue ();
118
100
} else {
119
101
final boolean ignoreWhitespace = hasIgnoreWhitespace (flags );
120
102
final boolean caseBlind = hasCaseInsensitive (flags );
121
- pattern = translateRegexp (this , getArgument ( 1 ). eval ( contextSequence , contextItem ).getStringValue (), ignoreWhitespace , caseBlind );
103
+ pattern = translateRegexp (this , args [ 1 ]. itemAt ( 0 ).getStringValue (), ignoreWhitespace , caseBlind );
122
104
}
123
105
}
124
106
125
107
try {
126
- if (pat == null || (!pattern .equals (pat .pattern ())) || flags != pat .flags ()) {
127
- pat = PatternFactory .getInstance ().getPattern (pattern , flags );
128
- }
129
-
130
- if (pat .matcher ("" ).matches ()) {
108
+ final Pattern pat = PatternFactory .getInstance ().getPattern (pattern , flags );
109
+ if (pat .matcher ("" ).matches ()) {
131
110
throw new XPathException (this , ErrorCodes .FORX0003 , "regular expression could match empty string" );
132
111
}
133
112
@@ -144,10 +123,6 @@ public Sequence eval(final Sequence contextSequence, final Item contextItem) thr
144
123
}
145
124
}
146
125
147
- if (context .getProfiler ().isEnabled ()) {
148
- context .getProfiler ().end (this , "" , result );
149
- }
150
-
151
126
return result ;
152
127
}
153
128
0 commit comments