Ticket #2279: trim[6001].diff
| File trim[6001].diff, 2.3 KB (added by flesler, 3 years ago) |
|---|
-
src/core.js
1117 1117 return elem[ name ]; 1118 1118 }, 1119 1119 1120 // Trim function by Ariel Flesler 1121 // http://flesler.blogspot.com/2008/11/fast-trim-function-for-javascript.html 1120 1122 trim: function( text ) { 1121 return (text || "").replace( /^\s+|\s+$/g, "" ); 1123 if( !text ) 1124 return ""; 1125 1126 var start = -1, 1127 end = text.length; 1128 while( text.charCodeAt(--end) < 33 ); 1129 while( text.charCodeAt(++start) < 33 ); 1130 return text.slice( start, end + 1 ); 1122 1131 }, 1123 1132 1124 1133 makeArray: function( array ) { … … 1126 1135 1127 1136 if( array != null ){ 1128 1137 var i = array.length; 1129 // The window, strings (and functions)also have 'length'1138 // The window, strings and functions also have 'length' 1130 1139 if( i == null || typeof array === "string" || jQuery.isFunction(array) || array.setInterval ) 1131 1140 ret[0] = array; 1132 1141 else -
test/unit/core.js
1795 1795 equals( c[0].nodeValue, "hi", "Check node,textnode,comment contents is just the one from span" ); 1796 1796 }); 1797 1797 1798 test(" jQuery.makeArray", function(){1798 test("makeArray()", function(){ 1799 1799 expect(15); 1800 1800 1801 1801 equals( jQuery.makeArray(jQuery('html>*'))[0].nodeName, "HEAD", "Pass makeArray a jQuery object" ); … … 1830 1830 1831 1831 ok( jQuery.makeArray(document.getElementById('form')).length >= 13, "Pass makeArray a form (treat as elements)" ); 1832 1832 }); 1833 1834 test("trim()", function(){ 1835 expect( 10 ); 1836 1837 var parse = jQuery.trim; 1838 1839 equals( parse(""), "", "Empty String" ); 1840 equals( parse(" "), "", "Empty, with spaces" ); 1841 equals( parse(" \n\t\r "), "", "Empty, with new lines, tabs, etc" ); 1842 1843 equals( parse("abc"), "abc", "No spaces" ); 1844 1845 equals( parse("abc "), "abc", "Trailing spaces" ); 1846 equals( parse("abc \n\t\r "), "abc", "Trailing new lines, tabs, etc" ); 1847 1848 equals( parse(" abc"), "abc", "Leading spaces" ); 1849 equals( parse(" \n\t\r abc"), "abc", "Leading new lines, tabs, etc" ); 1850 1851 equals( parse(" abc "), "abc", "Both leading and trailing spaces" ); 1852 equals( parse(" \n\t\r abc \n\t\r "), "abc", "Both leading and trailing new lines, tabs, etc" ); 1853 }); 1854 No newline at end of file
