Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2006-2009 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2009 the V8 project authors. All rights reserved. |
|
Jakob Kummerow
2012/03/13 15:39:06
2012
| |
| 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 |
| 11 // with the distribution. | 11 // with the distribution. |
| (...skipping 573 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 585 } | 585 } |
| 586 var subject = TO_STRING_INLINE(this); | 586 var subject = TO_STRING_INLINE(this); |
| 587 limit = (IS_UNDEFINED(limit)) ? 0xffffffff : TO_UINT32(limit); | 587 limit = (IS_UNDEFINED(limit)) ? 0xffffffff : TO_UINT32(limit); |
| 588 | 588 |
| 589 // ECMA-262 says that if separator is undefined, the result should | 589 // ECMA-262 says that if separator is undefined, the result should |
| 590 // be an array of size 1 containing the entire string. | 590 // be an array of size 1 containing the entire string. |
| 591 if (IS_UNDEFINED(separator)) { | 591 if (IS_UNDEFINED(separator)) { |
| 592 return [subject]; | 592 return [subject]; |
| 593 } | 593 } |
| 594 | 594 |
| 595 if (limit === 0) return []; | |
| 596 | |
| 595 var length = subject.length; | 597 var length = subject.length; |
| 596 if (!IS_REGEXP(separator)) { | 598 if (!IS_REGEXP(separator)) { |
| 597 separator = TO_STRING_INLINE(separator); | 599 separator = TO_STRING_INLINE(separator); |
| 598 | 600 |
| 599 if (limit === 0) return []; | |
| 600 | |
| 601 var separator_length = separator.length; | 601 var separator_length = separator.length; |
| 602 | 602 |
| 603 // If the separator string is empty then return the elements in the subject. | 603 // If the separator string is empty then return the elements in the subject. |
| 604 if (separator_length === 0) return %StringToArray(subject, limit); | 604 if (separator_length === 0) return %StringToArray(subject, limit); |
| 605 | 605 |
| 606 var result = %StringSplit(subject, separator, limit); | 606 var result = %StringSplit(subject, separator, limit); |
| 607 | 607 |
| 608 return result; | 608 return result; |
| 609 } | 609 } |
| 610 | 610 |
| 611 if (limit === 0) return []; | 611 // Separator is a regular expression. |
| 612 return StringSplitOnRegExp(subject, separator, limit, length); | |
| 613 } | |
| 612 | 614 |
| 615 | |
| 616 function StringSplitOnRegExp(subject, separator, limit, length) { | |
| 613 %_Log('regexp', 'regexp-split,%0S,%1r', [subject, separator]); | 617 %_Log('regexp', 'regexp-split,%0S,%1r', [subject, separator]); |
| 614 | 618 |
| 615 if (length === 0) { | 619 if (length === 0) { |
| 616 if (DoRegExpExec(separator, subject, 0, 0) != null) { | 620 if (DoRegExpExec(separator, subject, 0, 0) != null) { |
| 617 return []; | 621 return []; |
| 618 } | 622 } |
| 619 return [subject]; | 623 return [subject]; |
| 620 } | 624 } |
| 621 | 625 |
| 622 var currentIndex = 0; | 626 var currentIndex = 0; |
| (...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1004 "fixed", StringFixed, | 1008 "fixed", StringFixed, |
| 1005 "italics", StringItalics, | 1009 "italics", StringItalics, |
| 1006 "small", StringSmall, | 1010 "small", StringSmall, |
| 1007 "strike", StringStrike, | 1011 "strike", StringStrike, |
| 1008 "sub", StringSub, | 1012 "sub", StringSub, |
| 1009 "sup", StringSup | 1013 "sup", StringSup |
| 1010 )); | 1014 )); |
| 1011 } | 1015 } |
| 1012 | 1016 |
| 1013 SetUpString(); | 1017 SetUpString(); |
| OLD | NEW |