| OLD | NEW |
| 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 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 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 return %StringLocaleCompare(this_str, other_str); | 145 return %StringLocaleCompare(this_str, other_str); |
| 146 } | 146 } |
| 147 | 147 |
| 148 | 148 |
| 149 // ECMA-262 section 15.5.4.10 | 149 // ECMA-262 section 15.5.4.10 |
| 150 function StringMatch(regexp) { | 150 function StringMatch(regexp) { |
| 151 if (!IS_REGEXP(regexp)) regexp = new ORIGINAL_REGEXP(regexp); | 151 if (!IS_REGEXP(regexp)) regexp = new ORIGINAL_REGEXP(regexp); |
| 152 var subject = ToString(this); | 152 var subject = ToString(this); |
| 153 | 153 |
| 154 if (!regexp.global) return regexp.exec(subject); | 154 if (!regexp.global) return regexp.exec(subject); |
| 155 %_Log('regexp', 'regexp-match,%0S,%1r', [subject, regexp]); |
| 155 var matches = DoRegExpExecGlobal(regexp, subject); | 156 var matches = DoRegExpExecGlobal(regexp, subject); |
| 156 | 157 |
| 157 // If the regexp did not match, return null. | 158 // If the regexp did not match, return null. |
| 158 if (matches.length == 0) return null; | 159 if (matches.length == 0) return null; |
| 159 | 160 |
| 160 // Build the result array. | 161 // Build the result array. |
| 161 var result = new $Array(match_string); | 162 var result = new $Array(match_string); |
| 162 for (var i = 0; i < matches.length; ++i) { | 163 for (var i = 0; i < matches.length; ++i) { |
| 163 var match = matches[i]; | 164 var match = matches[i]; |
| 164 var match_string = subject.slice(match[0], match[1]); | 165 var match_string = subject.slice(match[0], match[1]); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 178 return %StringSlice(string, start, end); | 179 return %StringSlice(string, start, end); |
| 179 } | 180 } |
| 180 | 181 |
| 181 | 182 |
| 182 // ECMA-262, section 15.5.4.11 | 183 // ECMA-262, section 15.5.4.11 |
| 183 function StringReplace(search, replace) { | 184 function StringReplace(search, replace) { |
| 184 var subject = ToString(this); | 185 var subject = ToString(this); |
| 185 | 186 |
| 186 // Delegate to one of the regular expression variants if necessary. | 187 // Delegate to one of the regular expression variants if necessary. |
| 187 if (IS_REGEXP(search)) { | 188 if (IS_REGEXP(search)) { |
| 189 %_Log('regexp', 'regexp-replace,%0r,%1S', [search, subject]); |
| 188 if (IS_FUNCTION(replace)) { | 190 if (IS_FUNCTION(replace)) { |
| 189 return StringReplaceRegExpWithFunction(subject, search, replace); | 191 return StringReplaceRegExpWithFunction(subject, search, replace); |
| 190 } else { | 192 } else { |
| 191 return StringReplaceRegExp(subject, search, replace); | 193 return StringReplaceRegExp(subject, search, replace); |
| 192 } | 194 } |
| 193 } | 195 } |
| 194 | 196 |
| 195 // Convert the search argument to a string and search for it. | 197 // Convert the search argument to a string and search for it. |
| 196 search = ToString(search); | 198 search = ToString(search); |
| 197 var start = %StringIndexOf(subject, search, 0); | 199 var start = %StringIndexOf(subject, search, 0); |
| (...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 506 // use that. We do as SpiderMonkey and KJS. | 508 // use that. We do as SpiderMonkey and KJS. |
| 507 if (%_ArgumentsLength() === 0) { | 509 if (%_ArgumentsLength() === 0) { |
| 508 result[result.length] = subject; | 510 result[result.length] = subject; |
| 509 return result; | 511 return result; |
| 510 } | 512 } |
| 511 | 513 |
| 512 var length = subject.length; | 514 var length = subject.length; |
| 513 var currentIndex = 0; | 515 var currentIndex = 0; |
| 514 var startIndex = 0; | 516 var startIndex = 0; |
| 515 | 517 |
| 516 var sep = IS_REGEXP(separator) ? separator : ToString(separator); | 518 var sep; |
| 519 if (IS_REGEXP(separator)) { |
| 520 sep = separator; |
| 521 %_Log('regexp', 'regexp-split,%0S,%1r', [subject, sep]); |
| 522 } else { |
| 523 sep = ToString(separator); |
| 524 } |
| 517 | 525 |
| 518 if (length === 0) { | 526 if (length === 0) { |
| 519 if (splitMatch(sep, subject, 0, 0) != null) return result; | 527 if (splitMatch(sep, subject, 0, 0) != null) return result; |
| 520 result[result.length] = subject; | 528 result[result.length] = subject; |
| 521 return result; | 529 return result; |
| 522 } | 530 } |
| 523 | 531 |
| 524 while (true) { | 532 while (true) { |
| 525 | 533 |
| 526 if (startIndex === length) { | 534 if (startIndex === length) { |
| (...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 849 "italics", StringItalics, | 857 "italics", StringItalics, |
| 850 "small", StringSmall, | 858 "small", StringSmall, |
| 851 "strike", StringStrike, | 859 "strike", StringStrike, |
| 852 "sub", StringSub, | 860 "sub", StringSub, |
| 853 "sup", StringSup | 861 "sup", StringSup |
| 854 )); | 862 )); |
| 855 } | 863 } |
| 856 | 864 |
| 857 | 865 |
| 858 SetupString(); | 866 SetupString(); |
| OLD | NEW |