+ // Like String#charAt, but return the pair of UTF-16 surrogates for characters outside of BMP.
+ function codePointAt( string, offset, backwards ) {
+ // We don't need to check for offsets at the beginning or end of string,
+ // String#slice will simply return a shorter (or empty) substring.
+ var maybePair = backwards ?
+ string.slice( offset - 1, offset + 1 ) :
+ string.slice( offset, offset + 2 );
+ if ( /^[\uD800-\uDBFF][\uDC00-\uDFFF]$/.test( maybePair ) ) {
+ return maybePair;
+ } else {
+ return string.charAt( offset );
+ }
+ }
+