package jsonstringimport ()// ByteClass is a set of bytes, which has the control characters, as a table of the bytes and as the tables of// the scan by SIMD.typeByteClassstruct { table [256]bool tables nibbleTables}// NewByteClass is the class of the bytes and of the control characters.func ( ...byte) *ByteClass { := &ByteClass{}for , := range { .table[] = true }for := 0; < 0x20; ++ { .table[] = true } .tables = newNibbleTables(&.table)return}// Has is whether a byte of src is in the class.func ( *ByteClass) ( []byte) bool { := len()if == 0 {returnfalse } := unsafe.Pointer(unsafe.SliceData())if , := scanBytesSIMD(, , &.tables); {return }for , := range {if .table[] {returntrue } }returnfalse}// htmlOfCompact are the bytes which compact escapes for HTML in valid JSON, '<', '>' and '&', and the first byte// of U+2028 and U+2029, as a table and as the tables of the loop of the escapes by SIMD, which stops at that byte// since it has no sequence ( see escapeSequences ).var ( htmlOfCompact = [256]bool{'<': true, '>': true, '&': true, 0xe2: true} htmlOfCompactTables = newNibbleTables(&htmlOfCompact))// AppendHTMLEscaped appends src to dst with '<', '>', '&', U+2028 and U+2029 escaped, wherever they are, as// encoding/json escapes them for HTML: as \u003c, \u003e, \u0026, \u2028 and \u2029.func (, []byte) []byte { := unsafe.String(unsafe.SliceData(), len()) := len() , := 0, 0// limit is where the loop of the bytes gives the rest back to the loop by SIMD, which stops at the first byte // of U+2028 and U+2029, as appendNormalizedString does. := if >= 32 && hasEscapeLoop { , = appendEscapedSIMD(, , &htmlOfCompactTables, false) = = min(, +32) }for {for < { := []if !htmlOfCompact[] { ++continue }if == 0xe2 {// U+2028 and U+2029 are E2 80 A8 and E2 80 A9.if +2 < && [+1] == 0x80 && [+2]&^1 == 0xa8 { = append(, [:]...) = append(, `\u202`...) = append(, hex[[+2]&0xf]) += 3 = continue } ++continue } = append(, [:]...) := escapeSequences[] := len() = binary.LittleEndian.AppendUint64(, )[:+int(>>56)] ++ = }if >= {break } = append(, [:]...)varint , = appendEscapedSIMD(, [:], &htmlOfCompactTables, false) += = = min(, +32) }returnappend(, [:]...)}
The pages are generated with Goldsv0.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.