1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2025-12-22 19:07:58 +01:00

use RegExp#test in preference to String#match

This commit is contained in:
Doug Kearns
2007-11-16 12:48:03 +00:00
parent fea5cceecc
commit f50bca0453
9 changed files with 44 additions and 45 deletions

View File

@@ -187,7 +187,7 @@ vimperator.Bookmarks = function () //{{{
for (var i in firefox_engines)
{
var alias = firefox_engines[i].alias;
if (!alias || !alias.match(/^[a-z0-9_-]+$/))
if (!alias || !/^[a-z0-9_-]+$/.test(alias))
alias = firefox_engines[i].name.replace(/^\W*([a-zA-Z_-]+).*/, "$1").toLowerCase();
if (!alias)
alias = "search"; // for search engines which we can't find a suitable alias

View File

@@ -117,7 +117,7 @@ vimperator.Command.prototype.hasName = function (name)
{
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]))
return true;
@@ -1037,19 +1037,19 @@ vimperator.Commands = function () //{{{
return;
}
var match;
var matches;
// 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]);
if (!reference[0] && match[3])
return vimperator.echoerr("E121: Undefined variable: " + match[2]);
var reference = vimperator.variableReference(matches[2]);
if (!reference[0] && matches[3])
return vimperator.echoerr("E121: Undefined variable: " + matches[2]);
var expr = vimperator.eval(match[4]);
var expr = vimperator.eval(matches[4]);
if (typeof expr === undefined)
return vimperator.echoerr("E15: Invalid expression: " + match[4]);
return vimperator.echoerr("E15: Invalid expression: " + matches[4]);
else
{
if (!reference[0]) {
@@ -1059,13 +1059,13 @@ vimperator.Commands = function () //{{{
return; // for now
}
if (match[3])
if (matches[3])
{
if (match[3] == "+")
if (matches[3] == "+")
reference[0][reference[1]] += expr;
else if (match[3] == "-")
else if (matches[3] == "-")
reference[0][reference[1]] -= expr;
else if (match[3] == ".")
else if (matches[3] == ".")
reference[0][reference[1]] += expr.toString();
}
else
@@ -1074,11 +1074,11 @@ vimperator.Commands = function () //{{{
}
}
// 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])
return vimperator.echoerr("E121: Undefined variable: " + match[1]);
return vimperator.echoerr("E121: Undefined variable: " + matches[1]);
var value = reference[0][reference[1]];
if (typeof value == "number")

View File

@@ -647,7 +647,7 @@ vimperator.Events = function () //{{{
map = vimperator.mappings.get(vimperator.mode, candidate_command);
// 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
if (vimperator.mode == vimperator.modes.INSERT || vimperator.mode == vimperator.modes.COMMAND_LINE)

View File

@@ -1009,20 +1009,18 @@ vimperator.Mappings = function () //{{{
));
function isDirectory(url)
{
if (url.match(/^file:\/\//) || url.match(/^\//))
if (/^file:\/\/|^\//.test(url))
{
var stripedFilename = url.replace(/^(file:\/\/)?(.*)/, "$2");
var file = vimperator.io.getFile(stripedFilename);
var strippedFilename = url.replace(/^(file:\/\/)?(.*)/, "$2");
var file = vimperator.io.getFile(strippedFilename);
if (!file || !file.isDirectory())
return false;
else
return true;
}
// for all other locations just check if the URL ends with /
if (url.match(/\/$/))
return true;
else
return false;
return /\/$/.test(url);
}
addDefaultMap(new vimperator.Map([vimperator.modes.NORMAL], ["gu", "<BS>"],
function (count)

View File

@@ -297,7 +297,7 @@ vimperator.Options = function () //{{{
// work around firefox popup blocker
var popup_allowed_events = loadPreference("dom.popup_allowed_events", "change click dblclick mouseup reset submit");
if (!popup_allowed_events.match("keypress"))
if (!/keypress/.test(popup_allowed_events))
storePreference("dom.popup_allowed_events", popup_allowed_events + " keypress");
// TODO: shouldn't we be resetting these in destroy() as well?

View File

@@ -57,7 +57,7 @@ vimperator.Tabs = function () //{{{
position = spec;
else if (spec === "$")
return last;
else if (!spec.match(/^([+-]?\d+|)$/))
else if (!/^([+-]?\d+|)$/.test(spec))
{
// TODO: move error reporting to ex-command?
vimperator.echoerr("E488: Trailing characters");
@@ -65,7 +65,7 @@ vimperator.Tabs = function () //{{{
}
else
{
if (spec.match(/^([+-]\d+)$/)) // relative position +/-N
if (/^([+-]\d+)$/.test(spec)) // relative position +/-N
position += parseInt(spec, 10);
else // absolute position
position = parseInt(spec, 10);

View File

@@ -484,7 +484,7 @@ vimperator.CommandLine = function () //{{{
[completion_start_index, completions] = res;
// sort the completion list
if (vimperator.options["wildoptions"].search(/\bsort\b/) > -1)
if (/\bsort\b/.test(vimperator.options["wildoptions"]))
{
completions.sort(function (a, b) {
if (a[0] < b[0])

View File

@@ -207,4 +207,5 @@ vimperator.util = {
return strNum[0] + " " + unitVal[unitIndex];
}
};
// vim: set fdm=marker sw=4 ts=4 et:

View File

@@ -164,13 +164,13 @@ const vimperator = (function () //{{{
eval: function (string)
{
string = string.toString().replace(/^\s*/, "").replace(/\s*$/, "");
var match = string.match(/^&(\w+)/);
if (match)
var matches = string.match(/^&(\w+)/);
if (matches)
{
var opt = this.options.get(match[1]);
var opt = this.options.get(matches[1]);
if (!opt)
{
this.echoerr("E113: Unknown option: " + match[1]);
this.echoerr("E113: Unknown option: " + matches[1]);
return;
}
var type = opt.type;
@@ -181,10 +181,10 @@ const vimperator = (function () //{{{
}
// String
else if (match = string.match(/^(['"])([^\1]*?[^\\]?)\1/))
else if (matches = string.match(/^(['"])([^\1]*?[^\\]?)\1/))
{
if (match)
return match[2].toString();
if (matches)
return matches[2].toString();
else
{
this.echoerr("E115: Missing quote: " + string);
@@ -193,7 +193,7 @@ const vimperator = (function () //{{{
}
// Number
else if (match = string.match(/^(\d+)$/))
else if (matches = string.match(/^(\d+)$/))
{
return parseInt(match[1], 10);
}
@@ -212,16 +212,16 @@ const vimperator = (function () //{{{
if (!string)
return [null, null, null];
var match = string.match(/^([bwtglsv]):(\w+)/);
if (match) // Variable
var matches = string.match(/^([bwtglsv]):(\w+)/);
if (matches) // Variable
{
// Other variables should be implemented
if (match[1] == "g")
if (matches[1] == "g")
{
if (match[2] in this.globalVariables)
return [this.globalVariables, match[2], match[1]];
if (matches[2] in this.globalVariables)
return [this.globalVariables, matches[2], matches[1]];
else
return [null, match[2], match[1]];
return [null, matches[2], matches[1]];
}
}
else // Global variable