OLD | NEW |
---|---|
1 // Copyright 2006-2009 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2009 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
409 // Helper function for replacing regular expressions with the result of a | 409 // Helper function for replacing regular expressions with the result of a |
410 // function application in String.prototype.replace. The function application | 410 // function application in String.prototype.replace. The function application |
411 // must be interleaved with the regexp matching (contrary to ECMA-262 | 411 // must be interleaved with the regexp matching (contrary to ECMA-262 |
412 // 15.5.4.11) to mimic SpiderMonkey and KJS behavior when the function uses | 412 // 15.5.4.11) to mimic SpiderMonkey and KJS behavior when the function uses |
413 // the static properties of the RegExp constructor. Example: | 413 // the static properties of the RegExp constructor. Example: |
414 // 'abcd'.replace(/(.)/g, function() { return RegExp.$1; } | 414 // 'abcd'.replace(/(.)/g, function() { return RegExp.$1; } |
415 // should be 'abcd' and not 'dddd' (or anything else). | 415 // should be 'abcd' and not 'dddd' (or anything else). |
416 function StringReplaceRegExpWithFunction(subject, regexp, replace) { | 416 function StringReplaceRegExpWithFunction(subject, regexp, replace) { |
417 var matchInfo = DoRegExpExec(regexp, subject, 0); | 417 var matchInfo = DoRegExpExec(regexp, subject, 0); |
418 if (IS_NULL(matchInfo)) return subject; | 418 if (IS_NULL(matchInfo)) return subject; |
419 | 419 |
Erik Corry
2010/03/19 11:04:11
Trailing spaces?
Lasse Reichstein
2010/03/19 11:25:42
Done.
| |
420 var result = new ReplaceResultBuilder(subject); | 420 var result = new ReplaceResultBuilder(subject); |
421 // There's at least one match. If the regexp is global, we have to loop | 421 // There's at least one match. If the regexp is global, we have to loop |
422 // over all matches. The loop is not in C++ code here like the one in | 422 // over all matches. The loop is not in C++ code here like the one in |
423 // RegExp.prototype.exec, because of the interleaved function application. | 423 // RegExp.prototype.exec, because of the interleaved function application. |
424 // Unfortunately, that means this code is nearly duplicated, here and in | 424 // Unfortunately, that means this code is nearly duplicated, here and in |
425 // jsregexp.cc. | 425 // jsregexp.cc. |
426 if (regexp.global) { | 426 if (regexp.global) { |
427 var previous = 0; | 427 var previous = 0; |
428 var startOfMatch; | 428 var startOfMatch; |
429 if (NUMBER_OF_CAPTURES(matchInfo) == 2) { | 429 if (NUMBER_OF_CAPTURES(matchInfo) == 2) { |
(...skipping 555 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
985 "small", StringSmall, | 985 "small", StringSmall, |
986 "strike", StringStrike, | 986 "strike", StringStrike, |
987 "sub", StringSub, | 987 "sub", StringSub, |
988 "sup", StringSup, | 988 "sup", StringSup, |
989 "toJSON", StringToJSON | 989 "toJSON", StringToJSON |
990 )); | 990 )); |
991 } | 991 } |
992 | 992 |
993 | 993 |
994 SetupString(); | 994 SetupString(); |
OLD | NEW |