mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2025-12-23 04:57:58 +01:00
use RegExp#test in preference to String#match
This commit is contained in:
@@ -166,7 +166,7 @@ vimperator.Bookmarks = function () //{{{
|
|||||||
for (var i in firefoxEngines)
|
for (var i in firefoxEngines)
|
||||||
{
|
{
|
||||||
var alias = firefoxEngines[i].alias;
|
var alias = firefoxEngines[i].alias;
|
||||||
if (!alias || !alias.match(/^[a-z0-9_-]+$/))
|
if (!alias || !/^[a-z0-9_-]+$/.test(alias))
|
||||||
alias = firefoxEngines[i].name.replace(/^\W*([a-zA-Z_-]+).*/, "$1").toLowerCase();
|
alias = firefoxEngines[i].name.replace(/^\W*([a-zA-Z_-]+).*/, "$1").toLowerCase();
|
||||||
if (!alias)
|
if (!alias)
|
||||||
alias = "search"; // for search engines which we can't find a suitable alias
|
alias = "search"; // for search engines which we can't find a suitable alias
|
||||||
|
|||||||
@@ -116,7 +116,7 @@ vimperator.Command.prototype.hasName = function (name)
|
|||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else if (this.specs[i].match(/^(\w+|!)\[\w+\]$/)) // abbreviation spec
|
else if (/^(\w+|!)\[\w+\]$/.test(this.specs[i])) // abbreviation spec
|
||||||
{
|
{
|
||||||
if (matchAbbreviation(name, this.specs[i]))
|
if (matchAbbreviation(name, this.specs[i]))
|
||||||
return true;
|
return true;
|
||||||
@@ -713,19 +713,19 @@ vimperator.Commands = function () //{{{
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var match;
|
var matches;
|
||||||
// 1 - type, 2 - name, 3 - +-., 4 - expr
|
// 1 - type, 2 - name, 3 - +-., 4 - expr
|
||||||
if (match = args.match(/([$@&])?([\w:]+)\s*([+-.])?=\s*(.+)/))
|
if (matches = args.match(/([$@&])?([\w:]+)\s*([+-.])?=\s*(.+)/))
|
||||||
{
|
{
|
||||||
if (!match[1])
|
if (!matches[1])
|
||||||
{
|
{
|
||||||
var reference = vimperator.variableReference(match[2]);
|
var reference = vimperator.variableReference(matches[2]);
|
||||||
if (!reference[0] && match[3])
|
if (!reference[0] && matches[3])
|
||||||
return vimperator.echoerr("E121: Undefined variable: " + match[2]);
|
return vimperator.echoerr("E121: Undefined variable: " + matches[2]);
|
||||||
|
|
||||||
var expr = vimperator.eval(match[4]);
|
var expr = vimperator.eval(matches[4]);
|
||||||
if (typeof expr === undefined)
|
if (typeof expr === undefined)
|
||||||
return vimperator.echoerr("E15: Invalid expression: " + match[4]);
|
return vimperator.echoerr("E15: Invalid expression: " + matches[4]);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (!reference[0])
|
if (!reference[0])
|
||||||
@@ -736,13 +736,13 @@ vimperator.Commands = function () //{{{
|
|||||||
return; // for now
|
return; // for now
|
||||||
}
|
}
|
||||||
|
|
||||||
if (match[3])
|
if (matches[3])
|
||||||
{
|
{
|
||||||
if (match[3] == "+")
|
if (matches[3] == "+")
|
||||||
reference[0][reference[1]] += expr;
|
reference[0][reference[1]] += expr;
|
||||||
else if (match[3] == "-")
|
else if (matches[3] == "-")
|
||||||
reference[0][reference[1]] -= expr;
|
reference[0][reference[1]] -= expr;
|
||||||
else if (match[3] == ".")
|
else if (matches[3] == ".")
|
||||||
reference[0][reference[1]] += expr.toString();
|
reference[0][reference[1]] += expr.toString();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -751,11 +751,11 @@ vimperator.Commands = function () //{{{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 1 - name
|
// 1 - name
|
||||||
else if (match = args.match(/^\s*([\w:]+)\s*$/))
|
else if (matches = args.match(/^\s*([\w:]+)\s*$/))
|
||||||
{
|
{
|
||||||
var reference = vimperator.variableReference(match[1]);
|
var reference = vimperator.variableReference(matches[1]);
|
||||||
if (!reference[0])
|
if (!reference[0])
|
||||||
return vimperator.echoerr("E121: Undefined variable: " + match[1]);
|
return vimperator.echoerr("E121: Undefined variable: " + matches[1]);
|
||||||
|
|
||||||
var value = reference[0][reference[1]];
|
var value = reference[0][reference[1]];
|
||||||
if (typeof value == "number")
|
if (typeof value == "number")
|
||||||
|
|||||||
@@ -615,7 +615,7 @@ vimperator.Events = function () //{{{
|
|||||||
map = vimperator.mappings.get(vimperator.modes.NORMAL, candidateCommand);
|
map = vimperator.mappings.get(vimperator.modes.NORMAL, candidateCommand);
|
||||||
|
|
||||||
// counts must be at the start of a complete mapping (10j -> go 10 lines down)
|
// counts must be at the start of a complete mapping (10j -> go 10 lines down)
|
||||||
if ((vimperator.input.buffer + key).match(/^[1-9][0-9]*$/))
|
if (/^[1-9][0-9]*$/.test(vimperator.input.buffer + key))
|
||||||
{
|
{
|
||||||
// no count for insert mode mappings
|
// no count for insert mode mappings
|
||||||
if (vimperator.hasMode(vimperator.modes.COMMAND_LINE))
|
if (vimperator.hasMode(vimperator.modes.COMMAND_LINE))
|
||||||
|
|||||||
@@ -893,20 +893,18 @@ vimperator.Mappings = function () //{{{
|
|||||||
));
|
));
|
||||||
function isDirectory(url)
|
function isDirectory(url)
|
||||||
{
|
{
|
||||||
if (url.match(/^file:\/\//) || url.match(/^\//))
|
if (/^file:\/\/|^\//.test(url))
|
||||||
{
|
{
|
||||||
var stripedFilename = url.replace(/^(file:\/\/)?(.*)/, "$2");
|
var strippedFilename = url.replace(/^(file:\/\/)?(.*)/, "$2");
|
||||||
var file = vimperator.io.getFile(stripedFilename);
|
var file = vimperator.io.getFile(strippedFilename);
|
||||||
if (!file || !file.isDirectory())
|
if (!file || !file.isDirectory())
|
||||||
return false;
|
return false;
|
||||||
else
|
else
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// for all other locations just check if the URL ends with /
|
// for all other locations just check if the URL ends with /
|
||||||
if (url.match(/\/$/))
|
return /\/$/.test(url);
|
||||||
return true;
|
|
||||||
else
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
addDefaultMap(new vimperator.Map(vimperator.modes.NORMAL, ["gu", "<BS>"],
|
addDefaultMap(new vimperator.Map(vimperator.modes.NORMAL, ["gu", "<BS>"],
|
||||||
function (count)
|
function (count)
|
||||||
|
|||||||
@@ -298,7 +298,7 @@ vimperator.Options = function () //{{{
|
|||||||
|
|
||||||
// work around firefox popup blocker
|
// work around firefox popup blocker
|
||||||
var popupAllowedEvents = loadPreference("dom.popup_allowed_events", "change click dblclick mouseup reset submit");
|
var popupAllowedEvents = loadPreference("dom.popup_allowed_events", "change click dblclick mouseup reset submit");
|
||||||
if (!popupAllowedEvents.match("keypress"))
|
if (!/keypress/.test(popupAllowedEvents))
|
||||||
storePreference("dom.popup_allowed_events", popupAllowedEvents + " keypress");
|
storePreference("dom.popup_allowed_events", popupAllowedEvents + " keypress");
|
||||||
|
|
||||||
// TODO: shouldn't we be resetting these in destroy() as well?
|
// TODO: shouldn't we be resetting these in destroy() as well?
|
||||||
|
|||||||
@@ -495,7 +495,7 @@ vimperator.CommandLine = function () //{{{
|
|||||||
[completionStartIndex, completions] = res;
|
[completionStartIndex, completions] = res;
|
||||||
|
|
||||||
// sort the completion list
|
// sort the completion list
|
||||||
if (vimperator.options["wildoptions"].search(/\bsort\b/) > -1)
|
if (/\bsort\b/.test(vimperator.options["wildoptions"]))
|
||||||
{
|
{
|
||||||
completions.sort(function (a, b) {
|
completions.sort(function (a, b) {
|
||||||
if (a[0] < b[0])
|
if (a[0] < b[0])
|
||||||
|
|||||||
@@ -280,13 +280,13 @@ const vimperator = (function () //{{{
|
|||||||
eval: function (string)
|
eval: function (string)
|
||||||
{
|
{
|
||||||
string = string.toString().replace(/^\s*/, "").replace(/\s*$/, "");
|
string = string.toString().replace(/^\s*/, "").replace(/\s*$/, "");
|
||||||
var match = string.match(/^&(\w+)/);
|
var matches = string.match(/^&(\w+)/);
|
||||||
if (match)
|
if (matches)
|
||||||
{
|
{
|
||||||
var opt = this.options.get(match[1]);
|
var opt = this.options.get(matches[1]);
|
||||||
if (!opt)
|
if (!opt)
|
||||||
{
|
{
|
||||||
this.echoerr("E113: Unknown option: " + match[1]);
|
this.echoerr("E113: Unknown option: " + matches[1]);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var type = opt.type;
|
var type = opt.type;
|
||||||
@@ -297,10 +297,10 @@ const vimperator = (function () //{{{
|
|||||||
}
|
}
|
||||||
|
|
||||||
// String
|
// String
|
||||||
else if (match = string.match(/^(['"])([^\1]*?[^\\]?)\1/))
|
else if (matches = string.match(/^(['"])([^\1]*?[^\\]?)\1/))
|
||||||
{
|
{
|
||||||
if (match)
|
if (matches)
|
||||||
return match[2].toString();
|
return matches[2].toString();
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
this.echoerr("E115: Missing quote: " + string);
|
this.echoerr("E115: Missing quote: " + string);
|
||||||
@@ -309,7 +309,7 @@ const vimperator = (function () //{{{
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Number
|
// Number
|
||||||
else if (match = string.match(/^(\d+)$/))
|
else if (matches = string.match(/^(\d+)$/))
|
||||||
{
|
{
|
||||||
return parseInt(match[1], 10);
|
return parseInt(match[1], 10);
|
||||||
}
|
}
|
||||||
@@ -328,16 +328,16 @@ const vimperator = (function () //{{{
|
|||||||
if (!string)
|
if (!string)
|
||||||
return [null, null, null];
|
return [null, null, null];
|
||||||
|
|
||||||
var match = string.match(/^([bwtglsv]):(\w+)/);
|
var matches = string.match(/^([bwtglsv]):(\w+)/);
|
||||||
if (match) // Variable
|
if (matches) // Variable
|
||||||
{
|
{
|
||||||
// Other variables should be implemented
|
// Other variables should be implemented
|
||||||
if (match[1] == "g")
|
if (matches[1] == "g")
|
||||||
{
|
{
|
||||||
if (match[2] in this.globalVariables)
|
if (matches[2] in this.globalVariables)
|
||||||
return [this.globalVariables, match[2], match[1]];
|
return [this.globalVariables, matches[2], matches[1]];
|
||||||
else
|
else
|
||||||
return [null, match[2], match[1]];
|
return [null, matches[2], matches[1]];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else // Global variable
|
else // Global variable
|
||||||
|
|||||||
Reference in New Issue
Block a user