Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LEX improvement #1204

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 16 additions & 32 deletions gun.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,14 @@
while(l-- > 0){ s += c.charAt(Math.floor(Math.random() * c.length)) }
return s;
}
String.match = function(t, o){ var tmp, u;
if('string' !== typeof t){ return false }
if('string' == typeof o){ o = {'=': o} }
o = o || {};
tmp = (o['='] || o['*'] || o['>'] || o['<']);
if(t === tmp){ return true }
if(u !== o['=']){ return false }
tmp = (o['*'] || o['>']);
if(t.slice(0, (tmp||'').length) === tmp){ return true }
if(u !== o['*']){ return false }
if(u !== o['>'] && u !== o['<']){
return (t >= o['>'] && t <= o['<'])? true : false;
}
if(u !== o['>'] && t >= o['>']){ return true }
if(u !== o['<'] && t <= o['<']){ return true }
return false;
String.match = function(t, o){
return (
('string' === typeof t && (t === o || t === o['='])) ||
(o['='] === undefined &&
(o['>'] === undefined || t >= o['>']) &&
(o['<'] === undefined || t <= o['<']) &&
(o['*'] === undefined || t.slice(0, o['*'].length) === o['*']))
);
}
String.hash = function(s, c){ // via SO
if(typeof s !== 'string'){ return }
Expand Down Expand Up @@ -1799,22 +1791,14 @@
while(l > 0){ s += c.charAt(Math.floor(Math.random() * c.length)); l-- }
return s;
}
Type.text.match = Type.text.match || function(t, o){ var tmp, u; DEP('text.match');
if('string' !== typeof t){ return false }
if('string' == typeof o){ o = {'=': o} }
o = o || {};
tmp = (o['='] || o['*'] || o['>'] || o['<']);
if(t === tmp){ return true }
if(u !== o['=']){ return false }
tmp = (o['*'] || o['>'] || o['<']);
if(t.slice(0, (tmp||'').length) === tmp){ return true }
if(u !== o['*']){ return false }
if(u !== o['>'] && u !== o['<']){
return (t >= o['>'] && t <= o['<'])? true : false;
}
if(u !== o['>'] && t >= o['>']){ return true }
if(u !== o['<'] && t <= o['<']){ return true }
return false;
Type.text.match = Type.text.match || function(t, o){ DEP('text.match');
return (
('string' === typeof t && (t === o || t === o['='])) ||
(o['='] === undefined &&
(o['>'] === undefined || t >= o['>']) &&
(o['<'] === undefined || t <= o['<']) &&
(o['*'] === undefined || t.slice(0, o['*'].length) === o['*']))
);
}
Type.text.hash = Type.text.hash || function(s, c){ // via SO
DEP('text.hash');
Expand Down
2 changes: 1 addition & 1 deletion gun.min.js

Large diffs are not rendered by default.

24 changes: 8 additions & 16 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,14 @@
while(l > 0){ s += c.charAt(Math.floor(Math.random() * c.length)); l-- }
return s;
}
Type.text.match = Type.text.match || function(t, o){ var tmp, u; DEP('text.match');
if('string' !== typeof t){ return false }
if('string' == typeof o){ o = {'=': o} }
o = o || {};
tmp = (o['='] || o['*'] || o['>'] || o['<']);
if(t === tmp){ return true }
if(u !== o['=']){ return false }
tmp = (o['*'] || o['>'] || o['<']);
if(t.slice(0, (tmp||'').length) === tmp){ return true }
if(u !== o['*']){ return false }
if(u !== o['>'] && u !== o['<']){
return (t >= o['>'] && t <= o['<'])? true : false;
}
if(u !== o['>'] && t >= o['>']){ return true }
if(u !== o['<'] && t <= o['<']){ return true }
return false;
Type.text.match = Type.text.match || function(t, o){ DEP('text.match');
return (
('string' === typeof t && (t === o || t === o['='])) ||
(o['='] === undefined &&
(o['>'] === undefined || t >= o['>']) &&
(o['<'] === undefined || t <= o['<']) &&
(o['*'] === undefined || t.slice(0, o['*'].length) === o['*']))
);
}
Type.text.hash = Type.text.hash || function(s, c){ // via SO
DEP('text.hash');
Expand Down
24 changes: 8 additions & 16 deletions src/shim.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,14 @@ String.random = function(l, c){
while(l-- > 0){ s += c.charAt(Math.floor(Math.random() * c.length)) }
return s;
}
String.match = function(t, o){ var tmp, u;
if('string' !== typeof t){ return false }
if('string' == typeof o){ o = {'=': o} }
o = o || {};
tmp = (o['='] || o['*'] || o['>'] || o['<']);
if(t === tmp){ return true }
if(u !== o['=']){ return false }
tmp = (o['*'] || o['>']);
if(t.slice(0, (tmp||'').length) === tmp){ return true }
if(u !== o['*']){ return false }
if(u !== o['>'] && u !== o['<']){
return (t >= o['>'] && t <= o['<'])? true : false;
}
if(u !== o['>'] && t >= o['>']){ return true }
if(u !== o['<'] && t <= o['<']){ return true }
return false;
String.match = function(t, o){
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe add //target, other comment

Copy link

@syonfox syonfox Sep 24, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if this is useful or not to you guys, but for new people might help,
Some sections could probably be added to lex docs somewhere.

I moved this to here so its more findable. If your working on it again at some point maybe take a look and let me know if i am missing something.

https://github.com/amark/gun/wiki/Strings,-Keys-and-Lex-Rules

return (
('string' === typeof t && (t === o || t === o['='])) ||
(o['='] === undefined &&
(o['>'] === undefined || t >= o['>']) &&
(o['<'] === undefined || t <= o['<']) &&
(o['*'] === undefined || t.slice(0, o['*'].length) === o['*']))
);
}
String.hash = function(s, c){ // via SO
if(typeof s !== 'string'){ return }
Expand Down