@@ -175,6 +175,50 @@ export function isWhiteSpace(c: i32): bool {
175175 }
176176}
177177
178+ /** First high (lead) surrogate. */
179+ export const SURROGATE_HIGH = 0xD800 ;
180+
181+ /** First low (trail) surrogate. */
182+ export const SURROGATE_LOW = 0xDC00 ;
183+
184+ /** Tests if a code unit or code point is a surrogate. */
185+ export function isSurrogate ( c : i32 ) : bool {
186+ // F800: 11111 0 0000000000 Mask
187+ // D800: 11011 X XXXXXXXXXX Any surrogate
188+ return ( c & 0xF800 ) == SURROGATE_HIGH ;
189+ }
190+
191+ /** Tests if a surrogate is a high (lead) surrogate. */
192+ export function isSurrogateHigh ( c : i32 ) : bool {
193+ // D800-DBFF
194+ return c < SURROGATE_LOW ;
195+ }
196+
197+ /** Tests if a surrogate is a low (trail) surrogate. */
198+ export function isSurrogateLow ( c : i32 ) : bool {
199+ // DC00-DFFF
200+ return c >= SURROGATE_LOW ;
201+ }
202+
203+ /** Tests if a code unit or code point is a high (lead) surrogate. */
204+ export function isHighSurrogate ( c : i32 ) : bool {
205+ // FC00: 11111 1 0000000000 Mask
206+ // D800: 11011 0 XXXXXXXXXX High/Lead surrogate
207+ return ( c & 0xFC00 ) == SURROGATE_HIGH ;
208+ }
209+
210+ /** Tests if a code unit or code point is a low (trail) surrogate. */
211+ export function isLowSurrogate ( c : i32 ) : bool {
212+ // FC00: 11111 1 0000000000 Mask
213+ // DC00: 11011 1 XXXXXXXXXX Low/Trail surrogate
214+ return ( c & 0xFC00 ) == SURROGATE_LOW ;
215+ }
216+
217+ /** Converts a surrogate pair to its respective code point. */
218+ export function combineSurrogates ( hi : i32 , lo : i32 ) : i32 {
219+ return 0x10000 + ( ( hi & 0x3FF ) << 10 ) | ( lo & 0x3FF ) ;
220+ }
221+
178222export function isAlpha ( c : i32 ) : bool {
179223 let c0 = c | 32 ; // unify uppercases and lowercases a|A - z|Z
180224 return c0 >= CharCode . a && c0 <= CharCode . z ;
0 commit comments