From 708fafe4a6ac5aa89ebad2ca0ac20935835d0061 Mon Sep 17 00:00:00 2001 From: Doug Kearns Date: Thu, 22 Nov 2007 11:46:49 +0000 Subject: [PATCH] use RegExp#test in preference to String#match --- content/bookmarks.js | 2 +- content/commands.js | 32 ++++++++++++++++---------------- content/events.js | 2 +- content/mappings.js | 12 +++++------- content/options.js | 2 +- content/ui.js | 2 +- content/vimperator.js | 28 ++++++++++++++-------------- 7 files changed, 39 insertions(+), 41 deletions(-) diff --git a/content/bookmarks.js b/content/bookmarks.js index a25e36e8..45142666 100644 --- a/content/bookmarks.js +++ b/content/bookmarks.js @@ -166,7 +166,7 @@ vimperator.Bookmarks = function () //{{{ for (var i in firefoxEngines) { 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(); if (!alias) alias = "search"; // for search engines which we can't find a suitable alias diff --git a/content/commands.js b/content/commands.js index d9126474..2e869167 100644 --- a/content/commands.js +++ b/content/commands.js @@ -116,7 +116,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; @@ -713,19 +713,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]) @@ -736,13 +736,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 @@ -751,11 +751,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") diff --git a/content/events.js b/content/events.js index 7519c9e4..235a458d 100644 --- a/content/events.js +++ b/content/events.js @@ -615,7 +615,7 @@ vimperator.Events = function () //{{{ map = vimperator.mappings.get(vimperator.modes.NORMAL, candidateCommand); // 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.hasMode(vimperator.modes.COMMAND_LINE)) diff --git a/content/mappings.js b/content/mappings.js index aac00a20..ca82161a 100644 --- a/content/mappings.js +++ b/content/mappings.js @@ -893,20 +893,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", ""], function (count) diff --git a/content/options.js b/content/options.js index 149e122e..d82db98f 100644 --- a/content/options.js +++ b/content/options.js @@ -298,7 +298,7 @@ vimperator.Options = function () //{{{ // work around firefox popup blocker 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"); // TODO: shouldn't we be resetting these in destroy() as well? diff --git a/content/ui.js b/content/ui.js index c7f24753..78e53466 100644 --- a/content/ui.js +++ b/content/ui.js @@ -495,7 +495,7 @@ vimperator.CommandLine = function () //{{{ [completionStartIndex, 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]) diff --git a/content/vimperator.js b/content/vimperator.js index 77a589a5..b6a7bbdb 100644 --- a/content/vimperator.js +++ b/content/vimperator.js @@ -280,13 +280,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; @@ -297,10 +297,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); @@ -309,7 +309,7 @@ const vimperator = (function () //{{{ } // Number - else if (match = string.match(/^(\d+)$/)) + else if (matches = string.match(/^(\d+)$/)) { return parseInt(match[1], 10); } @@ -328,16 +328,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