fnURL = function(sChar) {
		var sEncoded = mURLLookup[sChar];
		if (!sEncoded) {
			// encode code point as UTF-8 byte sequence and percent-encode each resulting byte
			var iChar = sChar.codePointAt(0);
			if (iChar < 128) {
				sEncoded = "%" + toHex(iChar, 2);
			} else if (iChar < 2048) {
				sEncoded = "%" + toHex((iChar >> 6) | 192, 2) +
					"%" + toHex((iChar & 63) | 128, 2);
			} else if ( iChar < 65536 ){
				sEncoded = "%" + toHex((iChar >> 12) | 224, 2) +
					"%" + toHex(((iChar >> 6) & 63) | 128, 2) +
					"%" + toHex((iChar & 63) | 128, 2);
			} else {
				sEncoded = "%" + toHex((iChar >> 18) | 240, 2) +
				"%" + toHex(((iChar >> 12) & 63) | 128, 2) +
				"%" + toHex(((iChar >>  6) & 63) | 128, 2) +
				"%" + toHex((iChar & 63) | 128, 2);
			}
			mURLLookup[sChar] = sEncoded;
		}
		return sEncoded;
	}
RegExp and escape function for URL escaping.

The first term describes Unicode surrogate pairs, the second term all other chars that require encoding.