Source File
ansi8.go
Belonging Package
github.com/clipperhouse/uax29/v2/graphemes
package graphemes// ansiEscapeLength8Bit returns the byte length of a valid 8-bit C1 ANSI// sequence at the start of data, or 0 if none.//// Recognized forms (ECMA-48 / ISO 6429):// - C1 CSI (0x9B) body as parameter/intermediate/final bytes// - C1 OSC (0x9D) body terminated by BEL, C1 ST, CAN, or SUB// - C1 DCS/SOS/PM/APC (0x90/0x98/0x9E/0x9F) body terminated by C1 ST, CAN, or SUB// - Standalone C1 controls (0x80..0x9F not listed above): single bytefunc ansiEscapeLength8Bit[ ~string | ~[]byte]( ) int {if len() == 0 {return 0}switch [0] {case 0x9B: // C1 CSI:= csiBodyLength([1:])if == 0 {return 0}return 1 +case 0x9D: // C1 OSC:= oscLengthC1([1:])if < 0 {return 0}return 1 +case 0x90, 0x98, 0x9E, 0x9F: // C1 DCS, SOS, PM, APC:= stSequenceLengthC1([1:])if < 0 {return 0}return 1 +default:if [0] >= 0x80 && [0] <= 0x9F {return 1}}return 0}// oscLengthC1 returns the length of a C1 OSC body.// data is the slice after the C1 OSC initiator (0x9D).//// Returns:// - n >= 0: consumed body length (includes BEL/ST terminator when present)// - -1: not terminated in the provided data//// Terminators: BEL (0x07) or C1 ST (0x9C).// CAN (0x18) and SUB (0x1A) cancel the control string.func oscLengthC1[ ~string | ~[]byte]( ) int {for := 0; < len(); ++ {:= []if == bel || == st {return + 1}if == can || == sub {return}}return -1}// stSequenceLengthC1 parses DCS/SOS/PM/APC bodies that terminate with C1 ST// (0x9C), or are canceled by CAN/SUB.func stSequenceLengthC1[ ~string | ~[]byte]( ) int {for := 0; < len(); ++ {:= []if == can || == sub {return}if == st {return + 1}}return -1}
![]() |
The pages are generated with Golds v0.8.7. (GOOS=linux GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds. |