@@ -3,6 +3,8 @@ import { ExprContext } from "../expr-context";
33import { BooleanValue , NodeSetValue , NumberValue , StringValue } from "../values" ;
44import { assert , regExpEscape } from "./internal-functions" ;
55
6+ /* Support functions. They are not exported. */
7+
68function cyrb53 ( str : string , seed = 0 ) {
79 let h1 = 0xdeadbeef ^ seed ;
810 let h2 = 0x41c6ce57 ^ seed ;
@@ -21,6 +23,7 @@ function cyrb53(str: string, seed = 0) {
2123 return 4294967296 * ( 2097151 & h2 ) + ( h1 >>> 0 ) ;
2224}
2325
26+ // Exported functions.
2427// In theory none of the `this.args` should work here,
2528// but `this` is replaced on `FunctionCallExpr.evaluate()`
2629// executes.
@@ -57,6 +60,11 @@ export function count(context: ExprContext) {
5760 return new NumberValue ( v . nodeSetValue ( ) . length ) ;
5861}
5962
63+ export function current ( context : ExprContext ) {
64+ assert ( this . args . length === 0 ) ;
65+ return new NodeSetValue ( [ context . nodeList [ context . position ] ] ) ;
66+ }
67+
6068export function endsWith ( context : ExprContext ) {
6169 assert ( this . args . length == 2 ) ;
6270 const s0 = this . args [ 0 ] . evaluate ( context ) . stringValue ( ) ;
@@ -114,21 +122,21 @@ export function id(context: ExprContext) {
114122export function lang ( context : ExprContext ) {
115123 assert ( this . args . length === 1 ) ;
116124 const lang = this . args [ 0 ] . evaluate ( context ) . stringValue ( ) ;
117- let xmllang ;
125+ let xmlLang ;
118126 let n = context . nodeList [ context . position ] ;
119127 while ( n && n != n . parentNode /* just in case ... */ ) {
120- xmllang = n . getAttributeValue ( 'xml:lang' ) ;
121- if ( xmllang ) {
128+ xmlLang = n . getAttributeValue ( 'xml:lang' ) ;
129+ if ( xmlLang ) {
122130 break ;
123131 }
124132 n = n . parentNode ;
125133 }
126- if ( ! xmllang ) {
134+ if ( ! xmlLang ) {
127135 return new BooleanValue ( false ) ;
128136 }
129137
130138 const re = new RegExp ( `^${ lang } $` , 'i' ) ;
131- return new BooleanValue ( xmllang . match ( re ) || xmllang . replace ( / _ .* $ / , '' ) . match ( re ) ) ;
139+ return new BooleanValue ( xmlLang . match ( re ) || xmlLang . replace ( / _ .* $ / , '' ) . match ( re ) ) ;
132140}
133141
134142export function last ( context : ExprContext ) {
@@ -139,7 +147,7 @@ export function last(context: ExprContext) {
139147
140148export function localName ( context : ExprContext ) {
141149 assert ( this . args . length === 1 || this . args . length === 0 ) ;
142- let n ;
150+ let n : XNode [ ] ;
143151 if ( this . args . length == 0 ) {
144152 n = [ context . nodeList [ context . position ] ] ;
145153 } else {
0 commit comments