* Get the full Unicode code point at the current buffer position. * Handles surrogate pairs for astral plane characters (U+10000+). * Returns [codePoint, charCount] where charCount is 1 or 2.
(
buffer: string,
index: number,
)
| 437 | * Returns [codePoint, charCount] where charCount is 1 or 2. |
| 438 | */ |
| 439 | #getCodePoint( |
| 440 | buffer: string, |
| 441 | index: number, |
| 442 | ): [codePoint: number, charCount: number] { |
| 443 | const code = buffer.charCodeAt(index); |
| 444 | // Check for high surrogate (0xD800-0xDBFF) |
| 445 | if (code >= 0xD800 && code <= 0xDBFF && index + 1 < buffer.length) { |
| 446 | const low = buffer.charCodeAt(index + 1); |
| 447 | // Check for valid low surrogate (0xDC00-0xDFFF) |
| 448 | if (low >= 0xDC00 && low <= 0xDFFF) { |
| 449 | // Decode surrogate pair: ((high - 0xD800) * 0x400) + (low - 0xDC00) + 0x10000 |
| 450 | const codePoint = ((code - 0xD800) << 10) + (low - 0xDC00) + 0x10000; |
| 451 | return [codePoint, 2]; |
| 452 | } |
| 453 | } |
| 454 | return [code, 1]; |
| 455 | } |
| 456 | |
| 457 | /** |
| 458 | * Check if the current buffer position has a valid NameStartChar. |
no outgoing calls
no test coverage detected