X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=src%2Fcore.js;h=3f156a5fd6e9422b70f4a8c972e295997504b69b;hb=2fbe3fbf681b65426868920d00085f1fa56034c7;hp=50e167657df12c78a5799452c6f6b63d42fa7b65;hpb=dcf0fa5048ef2379d551f29ffa29b14ec5ee09d5;p=jquery.git diff --git a/src/core.js b/src/core.js index 50e1676..3f156a5 100644 --- a/src/core.js +++ b/src/core.js @@ -27,7 +27,8 @@ var jQuery = function( selector, context ) { rnotwhite = /\S/, // Used for trimming whitespace - rtrim = /^(\s|\u00A0)+|(\s|\u00A0)+$/g, + trimLeft = /^\s+/, + trimRight = /\s+$/, // Match a standalone tag rsingleTag = /^<(\w+)\s*\/?>(?:<\/\1>)?$/, @@ -567,9 +568,20 @@ jQuery.extend({ return object; }, - trim: function( text ) { - return (text || "").replace( rtrim, "" ); - }, + // Use native String.trim function wherever possible + trim: String.trim ? + function( text ) { + return text == null ? + "" : + String.trim( text ); + } : + + // Otherwise use our own trimming functionality + function( text ) { + return text == null ? + "" : + text.toString().replace( trimLeft, "" ).replace( trimRight, "" ); + }, // results is for internal usage only makeArray: function( array, results ) { @@ -720,6 +732,13 @@ if ( indexOf ) { }; } +// Verify that \s matches non-breaking spaces +// (IE fails on this test) +if ( !/\s/.test( "\xA0" ) ) { + trimLeft = /^[\s\xA0]+/; + trimRight = /[\s\xA0]+$/; +} + // All jQuery objects should point back to these rootjQuery = jQuery(document);