1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2025-12-22 21:07:59 +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) for (var i in firefox_engines)
{ {
var alias = firefox_engines[i].alias; 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(); alias = firefox_engines[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

View File

@@ -117,7 +117,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;
@@ -1037,19 +1037,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]) {
@@ -1059,13 +1059,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
@@ -1074,11 +1074,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")

View File

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

View File

@@ -1009,20 +1009,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)

View File

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

View File

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

View File

@@ -484,7 +484,7 @@ vimperator.CommandLine = function () //{{{
[completion_start_index, completions] = res; [completion_start_index, 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])

View File

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

View File

@@ -164,13 +164,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;
@@ -181,10 +181,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);
@@ -193,7 +193,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);
} }
@@ -212,16 +212,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