Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
jio_mebibou
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Alexandra Rogova
jio_mebibou
Commits
a99b1dfb
Commit
a99b1dfb
authored
Dec 03, 2015
by
Romain Courteaud
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Query: reduce number of created regexp
parent
caab106c
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
24 deletions
+15
-24
src/queries/query.js
src/queries/query.js
+15
-24
No files found.
src/queries/query.js
View file @
a99b1dfb
...
@@ -3,7 +3,12 @@
...
@@ -3,7 +3,12 @@
(
function
(
RSVP
,
window
,
parseStringToObject
)
{
(
function
(
RSVP
,
window
,
parseStringToObject
)
{
"
use strict
"
;
"
use strict
"
;
var
query_class_dict
=
{};
var
query_class_dict
=
{},
regexp_escape
=
/
[\-\[\]
{}()*+?.,
\\\^
$|#
\s]
/g
,
regexp_percent
=
/%/g
,
regexp_underscore
=
/_/g
,
regexp_operator
=
/^
(?:
AND|OR|NOT
)
$/i
,
regexp_comparaison
=
/^
(?:
!
?
=|<=
?
|>=
?)
$/i
;
/**
/**
* Convert metadata values to array of strings. ex:
* Convert metadata values to array of strings. ex:
...
@@ -383,11 +388,7 @@
...
@@ -383,11 +388,7 @@
* @return {String} The escaped string
* @return {String} The escaped string
*/
*/
function
stringEscapeRegexpCharacters
(
string
)
{
function
stringEscapeRegexpCharacters
(
string
)
{
if
(
typeof
string
===
"
string
"
)
{
return
string
.
replace
(
regexp_escape
,
"
\\
$&
"
);
return
string
.
replace
(
/
([\\\.\$\[\]\(\)\{\}\^\?\*\+\-])
/g
,
"
\\
$1
"
);
}
throw
new
TypeError
(
"
Query.stringEscapeRegexpCharacters():
"
+
"
Argument no 1 is not of type 'string'
"
);
}
}
/**
/**
...
@@ -425,13 +426,9 @@
...
@@ -425,13 +426,9 @@
if
(
use_wildcard_characters
===
false
)
{
if
(
use_wildcard_characters
===
false
)
{
return
new
RegExp
(
"
^
"
+
stringEscapeRegexpCharacters
(
string
)
+
"
$
"
);
return
new
RegExp
(
"
^
"
+
stringEscapeRegexpCharacters
(
string
)
+
"
$
"
);
}
}
return
new
RegExp
(
"
^
"
+
stringEscapeRegexpCharacters
(
string
).
replace
(
return
new
RegExp
(
"
^
"
+
stringEscapeRegexpCharacters
(
string
)
/%/g
,
.
replace
(
regexp_percent
,
'
.*
'
)
"
.*
"
.
replace
(
regexp_underscore
,
'
.
'
)
+
"
$
"
);
).
replace
(
/_/g
,
"
.
"
)
+
"
$
"
);
}
}
/**
/**
...
@@ -483,7 +480,7 @@
...
@@ -483,7 +480,7 @@
*/
*/
ComplexQuery
.
prototype
.
match
=
function
(
item
)
{
ComplexQuery
.
prototype
.
match
=
function
(
item
)
{
var
operator
=
this
.
operator
;
var
operator
=
this
.
operator
;
if
(
!
(
/^
(?:
AND|OR|NOT
)
$/i
.
test
(
operator
)))
{
if
(
!
(
regexp_operator
.
test
(
operator
)))
{
operator
=
"
AND
"
;
operator
=
"
AND
"
;
}
}
return
this
[
operator
.
toUpperCase
()](
item
);
return
this
[
operator
.
toUpperCase
()](
item
);
...
@@ -770,9 +767,9 @@
...
@@ -770,9 +767,9 @@
value
=
null
,
value
=
null
,
key
=
this
.
key
;
key
=
this
.
key
;
if
(
!
(
/^
(?:
!
?
=|<=
?
|>=
?)
$/i
.
test
(
operator
)))
{
if
(
!
(
regexp_comparaison
.
test
(
operator
)))
{
// `operator` is not correct, we have to change it to "like" or "="
// `operator` is not correct, we have to change it to "like" or "="
if
(
/%/
.
test
(
this
.
value
))
{
if
(
regexp_percent
.
test
(
this
.
value
))
{
// `value` contains a non escaped `%`
// `value` contains a non escaped `%`
operator
=
"
like
"
;
operator
=
"
like
"
;
}
else
{
}
else
{
...
@@ -881,10 +878,7 @@
...
@@ -881,10 +878,7 @@
if
(
typeof
value
.
cmp
===
"
function
"
)
{
if
(
typeof
value
.
cmp
===
"
function
"
)
{
return
RSVP
.
resolve
(
value
.
cmp
(
comparison_value
)
===
0
);
return
RSVP
.
resolve
(
value
.
cmp
(
comparison_value
)
===
0
);
}
}
if
(
if
(
comparison_value
.
toString
()
===
value
.
toString
())
{
searchTextToRegExp
(
comparison_value
.
toString
(),
false
).
test
(
value
.
toString
())
)
{
return
RSVP
.
resolve
(
true
);
return
RSVP
.
resolve
(
true
);
}
}
}
}
...
@@ -942,10 +936,7 @@
...
@@ -942,10 +936,7 @@
if
(
typeof
value
.
cmp
===
"
function
"
)
{
if
(
typeof
value
.
cmp
===
"
function
"
)
{
return
RSVP
.
resolve
(
value
.
cmp
(
comparison_value
)
!==
0
);
return
RSVP
.
resolve
(
value
.
cmp
(
comparison_value
)
!==
0
);
}
}
if
(
if
(
comparison_value
.
toString
()
===
value
.
toString
())
{
searchTextToRegExp
(
comparison_value
.
toString
(),
false
).
test
(
value
.
toString
())
)
{
return
RSVP
.
resolve
(
false
);
return
RSVP
.
resolve
(
false
);
}
}
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment