From fe388ebca54f113316af6c0ab4d7716c7ad3f539 Mon Sep 17 00:00:00 2001 From: Samuel Lebeau Date: Tue, 14 Jul 2009 18:32:34 +0200 Subject: [PATCH] Replace calls to String#gsub by String#replace internally, be more specific about which version of Safari is supported --- README.rdoc | 2 +- src/lang/string.js | 18 ++++++++++++------ src/lang/template.js | 2 +- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/README.rdoc b/README.rdoc index 9d2362a..5f25ed0 100644 --- a/README.rdoc +++ b/README.rdoc @@ -11,7 +11,7 @@ Prototype currently targets the following platforms: * Microsoft Internet Explorer for Windows, version 6.0 and higher * Mozilla Firefox 1.5 and higher -* Apple Safari 2.0 and higher +* Apple Safari 2.0.4 and higher * Opera 9.25 and higher * Chrome 1.0 and higher diff --git a/src/lang/string.js b/src/lang/string.js index 5066d0d..f89cd13 100644 --- a/src/lang/string.js +++ b/src/lang/string.js @@ -293,7 +293,11 @@ Object.extend(String.prototype, (function() { * underscore (`_`). **/ function underscore() { - return this.gsub(/::/, '/').gsub(/([A-Z]+)([A-Z][a-z])/,'#{1}_#{2}').gsub(/([a-z\d])([A-Z])/,'#{1}_#{2}').gsub(/-/,'_').toLowerCase(); + return this.replace(/::/g, '/') + .replace(/([A-Z]+)([A-Z][a-z])/g, '$1_$2') + .replace(/([a-z\d])([A-Z])/g, '$1_$2') + .replace(/-/g, '_') + .toLowerCase(); } /** @@ -302,7 +306,7 @@ Object.extend(String.prototype, (function() { * Replaces every instance of the underscore character ("_") by a dash ("-"). **/ function dasherize() { - return this.gsub(/_/,'-'); + return this.replace(/_/g, '-'); } /** related to: Object.inspect @@ -312,9 +316,11 @@ Object.extend(String.prototype, (function() { * double quotes, with backslashes and quotes escaped). **/ function inspect(useDoubleQuotes) { - var escapedString = this.gsub(/[\x00-\x1f\\]/, function(match) { - var character = String.specialChar[match[0]]; - return character ? character : '\\u00' + match[0].charCodeAt().toPaddedString(2, 16); + var escapedString = this.replace(/[\x00-\x1f\\]/g, function(character) { + if (character in String.specialChar) { + return String.specialChar[character]; + } + return '\\u00' + character.charCodeAt().toPaddedString(2, 16); }); if (useDoubleQuotes) return '"' + escapedString.replace(/"/g, '\\"') + '"'; return "'" + escapedString.replace(/'/g, '\\\'') + "'"; @@ -336,7 +342,7 @@ Object.extend(String.prototype, (function() { * This security method is called internally. **/ function unfilterJSON(filter) { - return this.sub(filter || Prototype.JSONFilter, '#{1}'); + return this.replace(filter || Prototype.JSONFilter, '$1'); } /** diff --git a/src/lang/template.js b/src/lang/template.js index d3cb442..435a3e7 100644 --- a/src/lang/template.js +++ b/src/lang/template.js @@ -139,7 +139,7 @@ var Template = Class.create({ if (match == null) return before; while (match != null) { - var comp = match[1].startsWith('[') ? match[2].gsub('\\\\]', ']') : match[1]; + var comp = match[1].startsWith('[') ? match[2].replace(/\\\\]/g, ']') : match[1]; ctx = ctx[comp]; if (null == ctx || '' == match[3]) break; expr = expr.substring('[' == match[3] ? match[1].length : match[0].length);