Selector: Inline Sizzle into the selector module
[jquery.git] / src / selector / escapeSelector.js
blob1d89c2f00bb9120cf199f3c2487d5b900f96e47f
1 define( [
2         "../core"
3 ], function( jQuery ) {
5 "use strict";
7 // CSS string/identifier serialization
8 // https://drafts.csswg.org/cssom/#common-serializing-idioms
9 var rcssescape = /([\0-\x1f\x7f]|^-?\d)|^-$|[^\x80-\uFFFF\w-]/g;
11 function fcssescape( ch, asCodePoint ) {
12         if ( asCodePoint ) {
14                 // U+0000 NULL becomes U+FFFD REPLACEMENT CHARACTER
15                 if ( ch === "\0" ) {
16                         return "\uFFFD";
17                 }
19                 // Control characters and (dependent upon position) numbers get escaped as code points
20                 return ch.slice( 0, -1 ) + "\\" + ch.charCodeAt( ch.length - 1 ).toString( 16 ) + " ";
21         }
23         // Other potentially-special ASCII characters get backslash-escaped
24         return "\\" + ch;
27 jQuery.escapeSelector = function( sel ) {
28         return ( sel + "" ).replace( rcssescape, fcssescape );
31 } );