11// MOST Web Framework 2.0 Codename Blueshift BSD-3-Clause license Copyright (c) 2017-2022, THEMOST LP All rights reserved
22var _ = require ( 'lodash' ) ;
3+ var { OpenDataParser} = require ( '@themost/query' ) ;
4+
35/**
46 * @param {string } s
57 * @returns {Array }
68 * @private
79 */
810function testSplitExpandExpression ( s ) {
9- var ix = 0 ;
10- var paren = - 1 , charAt , ix1 = - 1 ,
11- isLiteral = false ,
12- lastSplitIndex = 0 ,
13- hasParen = false ,
14- matches = [ ] ,
15- match = null ;
16- while ( ix < s . length ) {
17- charAt = s . charAt ( ix ) ;
18- if ( ( charAt === '(' ) && ! isLiteral ) {
19- if ( paren < 0 ) {
20- match = [ ] ;
21- match [ 0 ] = s . substr ( lastSplitIndex , ix - lastSplitIndex ) ;
22- paren = 0 ;
23- }
24- if ( ix1 == - 1 ) { ix1 = ix ; }
25- hasParen = true ;
26- paren += 1 ;
27- }
28- else if ( ( charAt === ')' ) && ! isLiteral ) {
29- if ( paren > 0 ) { paren -= 1 ; }
30- }
31- else if ( charAt === '\'' ) {
32- isLiteral = ! isLiteral ;
33- }
34- else if ( ( charAt === ',' ) && ( paren == - 1 ) ) {
35- if ( match == null ) {
36- matches . push ( [ s . substr ( lastSplitIndex , ix - lastSplitIndex ) ] ) ;
11+ const dataParser = new OpenDataParser ( ) ;
12+ const matches = dataParser . parseExpandSequence ( s ) . map ( x => {
13+ const match = [ x . name ]
14+ if ( x . options ) {
15+ const keys = Object . keys ( x . options ) ;
16+ if ( keys . length > 0 ) {
17+ match . push ( Object . keys ( x . options ) . filter ( key => {
18+ return x . options [ key ] != null
19+ } ) . map ( key => `${ key } =${ x . options [ key ] } ` ) . join ( ';' ) ) ;
3720 }
38- lastSplitIndex = ix + 1 ;
39- hasParen = false ;
4021 }
41-
42- if ( ( ix === s . length - 1 ) && ( paren == - 1 ) ) {
43- matches . push ( [ s . substr ( lastSplitIndex , ix - lastSplitIndex + 1 ) ] ) ;
44- match = null ;
45- }
46- else if ( paren == 0 ) {
47- match = match || [ ] ;
48- match [ 1 ] = s . substr ( ix1 + 1 , ix - ix1 - 1 ) ;
49- matches . push ( match ) ;
50- paren = - 1 ;
51- ix1 = - 1 ;
52- }
53- ix += 1 ;
54- }
22+ return match ;
23+ } ) ;
5524 return matches ;
25+
5626}
5727
5828/**
@@ -114,4 +84,4 @@ if (typeof exports !== 'undefined')
11484 return DataExpandResolver . prototype . testExpandExpression ( s ) ;
11585 }
11686 } ;
117- }
87+ }
0 commit comments