package jximport ()consthexChars = "0123456789abcdef"// safeSet holds the value true if the ASCII character with the given array// position can be represented inside a JSON string without any further// escaping.//// All values are true except for the ASCII control characters (0-31), the// double quote ("), and the backslash character ("\").varsafeSet = [256]byte{// First 31 characters.1, 1, 1, 1, 1, 1, 1, 1,1, 1, 1, 1, 1, 1, 1, 1,1, 1, 1, 1, 1, 1, 1, 1,1, 1, 1, 1, 1, 1, 1, 1,'"': 1,'\\': 1,}// Str encodes string without html escaping.//// Use StrEscape to escape html, this is default for encoding/json and// should be used by default for untrusted strings.func ( *Writer) ( string) bool {returnwriteStr(, )}// ByteStr encodes string without html escaping.//// Use ByteStrEscape to escape html, this is default for encoding/json and// should be used by default for untrusted strings.func ( *Writer) ( []byte) bool {returnwriteStr(, )}func [ byteseq.Byteseq]( *Writer, ) ( bool) { = .byte('"')// Fast path, without utf8 and escape support.var ( = 0 = len() )for ; < && !; ++ { := []ifsafeSet[] != 0 {break } } = || writeStreamByteseq(, [:])if == {return || .byte('"') }return || strSlow[](, [:])}func [ byteseq.Byteseq]( *Writer, ) ( bool) {var , int// for the remaining parts, we process them char by charfor < len() && ! { := []ifsafeSet[] == 0 { ++continue }if < { = || writeStreamByteseq(, [:]) }switch {case'\\', '"': = || .twoBytes('\\', )case'\n': = || .twoBytes('\\', 'n')case'\r': = || .twoBytes('\\', 'r')case'\t': = || .twoBytes('\\', 't')default:// This encodes bytes < 0x20 except for \t, \n and \r. // If escapeHTML is set, it also escapes <, >, and & // because they can lead to security holes when // user-controlled strings are rendered into JSON // and served to some browsers. = || .rawStr(`\u00`) || .twoBytes(hexChars[>>4], hexChars[&0xF]) } ++ = continue }if < len() { = || writeStreamByteseq(, [:]) }return || .byte('"')}
The pages are generated with Goldsv0.6.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 @Go100and1 (reachable from the left QR code) to get the latest news of Golds.