Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(66)

Side by Side Diff: frog/minfrog

Issue 8907042: Support replaceAll for regexps. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 #!/usr/bin/env node 1 #!/usr/bin/env node
2 // ********** Library dart:core ************** 2 // ********** Library dart:core **************
3 // ********** Natives dart:core ************** 3 // ********** Natives dart:core **************
4 /** 4 /**
5 * Generates a dynamic call stub for a function. 5 * Generates a dynamic call stub for a function.
6 * Our goal is to create a stub method like this on-the-fly: 6 * Our goal is to create a stub method like this on-the-fly:
7 * function($0, $1, capture) { return this($0, $1, true, capture); } 7 * function($0, $1, capture) { return this($0, $1, true, capture); }
8 * 8 *
9 * This stub then replaces the dynamic one on Function, with one that is 9 * This stub then replaces the dynamic one on Function, with one that is
10 * specialized for that particular function, taking into account its default 10 * specialized for that particular function, taking into account its default
(...skipping 1634 matching lines...) Expand 10 before | Expand all | Expand 10 after
1645 } 1645 }
1646 StringImplementation.prototype.isEmpty = function() { 1646 StringImplementation.prototype.isEmpty = function() {
1647 return this.length == 0; 1647 return this.length == 0;
1648 } 1648 }
1649 StringImplementation.prototype.contains = function(pattern, startIndex) { 1649 StringImplementation.prototype.contains = function(pattern, startIndex) {
1650 return this.indexOf(pattern, startIndex) >= 0; 1650 return this.indexOf(pattern, startIndex) >= 0;
1651 } 1651 }
1652 StringImplementation.prototype._replaceFirst = function(from, to) { 1652 StringImplementation.prototype._replaceFirst = function(from, to) {
1653 return this.replace(from, to); 1653 return this.replace(from, to);
1654 } 1654 }
1655 StringImplementation.prototype._replaceFirstRegExp = function(from, to) { 1655 StringImplementation.prototype._replaceRegExp = function(from, to) {
1656 return this.replace(from.re, to); 1656 return this.replace(from.re, to);
1657 } 1657 }
1658 StringImplementation.prototype.replaceFirst = function(from, to) { 1658 StringImplementation.prototype.replaceFirst = function(from, to) {
1659 if ((typeof(from) == 'string')) return this._replaceFirst(from, to); 1659 if ((typeof(from) == 'string')) return this._replaceFirst(from, to);
1660 if (!!(from && from.is$RegExp())) return this._replaceFirstRegExp(from, to); 1660 if (!!(from && from.is$RegExp())) return this._replaceRegExp(from, to);
1661 var $$list = from.allMatches(this); 1661 var $$list = from.allMatches(this);
1662 for (var $$i = from.allMatches(this).iterator(); $$i.hasNext$0(); ) { 1662 for (var $$i = from.allMatches(this).iterator(); $$i.hasNext$0(); ) {
1663 var match = $$i.next$0(); 1663 var match = $$i.next$0();
1664 return this.substring(0, match.start$0()) + to + this.substring(match.end$0( )); 1664 return this.substring(0, match.start$0()) + to + this.substring(match.end$0( ));
1665 } 1665 }
1666 } 1666 }
1667 StringImplementation.prototype._replaceAll = function(from, to) {
1668 from = new RegExp(from.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"), 'g');
1669 to = to.replace(/\$/g, '$$$$'); // Escape sequences are fun!
1670 return this.replace(from, to);
1671 }
1667 StringImplementation.prototype.replaceAll = function(from, to) { 1672 StringImplementation.prototype.replaceAll = function(from, to) {
1668 if (typeof(from) == 'string' || from instanceof String) { 1673 if ((typeof(from) == 'string')) return this._replaceAll(from, to);
1669 from = new RegExp(from.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"), 'g'); 1674 if (!!(from && from.is$RegExp())) return this._replaceRegExp(from.get$dynamic( ).get$_global(), to);
1670 to = to.replace(/\$/g, '$$$$'); // Escape sequences are fun! 1675 var buffer = new StringBufferImpl("");
1676 var lastMatchEnd = 0;
1677 var $$list = from.allMatches(this);
1678 for (var $$i = from.allMatches(this).iterator(); $$i.hasNext$0(); ) {
1679 var match = $$i.next$0();
1680 buffer.add$1(this.substring(lastMatchEnd, match.start$0()));
1681 buffer.add$1(to);
1682 lastMatchEnd = match.end$0();
1671 } 1683 }
1672 return this.replace(from, to); 1684 buffer.add$1(this.substring(lastMatchEnd));
1673 } 1685 }
1674 StringImplementation.prototype.hashCode = function() { 1686 StringImplementation.prototype.hashCode = function() {
1675 if (this.hash_ === undefined) { 1687 if (this.hash_ === undefined) {
1676 for (var i = 0; i < this.length; i++) { 1688 for (var i = 0; i < this.length; i++) {
1677 var ch = this.charCodeAt(i); 1689 var ch = this.charCodeAt(i);
1678 this.hash_ += ch; 1690 this.hash_ += ch;
1679 this.hash_ += this.hash_ << 10; 1691 this.hash_ += this.hash_ << 10;
1680 this.hash_ ^= this.hash_ >> 6; 1692 this.hash_ ^= this.hash_ >> 6;
1681 } 1693 }
1682 1694
(...skipping 11637 matching lines...) Expand 10 before | Expand all | Expand 10 after
13320 $globals._NO_COLOR = '\u001b[0m'; 13332 $globals._NO_COLOR = '\u001b[0m';
13321 $globals._RED_COLOR = '\u001b[31m'; 13333 $globals._RED_COLOR = '\u001b[31m';
13322 } 13334 }
13323 var const$0 = new EnvMap()/*const EnvMap()*/; 13335 var const$0 = new EnvMap()/*const EnvMap()*/;
13324 var const$2 = new EmptyQueueException()/*const EmptyQueueException()*/; 13336 var const$2 = new EmptyQueueException()/*const EmptyQueueException()*/;
13325 var const$3 = new _DeletedKeySentinel()/*const _DeletedKeySentinel()*/; 13337 var const$3 = new _DeletedKeySentinel()/*const _DeletedKeySentinel()*/;
13326 var const$8 = new NoMoreElementsException()/*const NoMoreElementsException()*/; 13338 var const$8 = new NoMoreElementsException()/*const NoMoreElementsException()*/;
13327 var $globals = {}; 13339 var $globals = {};
13328 $static_init(); 13340 $static_init();
13329 main(); 13341 main();
OLDNEW
« frog/lib/string_implementation.dart ('K') | « frog/lib/string_implementation.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698