Add RELEASE-NOTES for r93818 and r94155. Adding to the 1.18 file since they're tagged...
[mediawiki.git] / resources / jquery / jquery.byteLength.js
blob20fa5c8ead2d2fcf814703a05b7a1867d8ac7dd1
1 /**
2  * jQuery.byteLength
3  *
4  * Calculate the byte length of a string (accounting for UTF-8).
5  *
6  * @author Jan Paul Posma
7  */
8 jQuery.byteLength = function( str ) {
10         // This basically figures out how many bytes a UTF-16 string (which is what js sees)
11         // will take in UTF-8 by replacing a 2 byte character with 2 *'s, etc, and counting that.
12         // Note, surrogate (\uD800-\uDFFF) characters are counted as 2 bytes, since there's two of them
13         // and the actual character takes 4 bytes in UTF-8 (2*2=4). Might not work perfectly in
14         // edge cases such as illegal sequences, but that should never happen.
15         return str
16                 .replace( /[\u0080-\u07FF\uD800-\uDFFF]/g, '**' )
17                 .replace( /[\u0800-\uD7FF\uE000-\uFFFF]/g, '***' )
18                 .length;