package httpsfv
import (
"errors"
"strings"
"unicode"
)
var ErrInvalidStringFormat = errors .New ("invalid string format" )
func marshalString(b *strings .Builder , s string ) error {
if err := b .WriteByte ('"' ); err != nil {
return err
}
for i := 0 ; i < len (s ); i ++ {
if s [i ] <= '\u001F' || s [i ] >= unicode .MaxASCII {
return ErrInvalidStringFormat
}
switch s [i ] {
case '"' , '\\' :
if err := b .WriteByte ('\\' ); err != nil {
return err
}
}
if err := b .WriteByte (s [i ]); err != nil {
return err
}
}
if err := b .WriteByte ('"' ); err != nil {
return err
}
return nil
}
func parseString(s *scanner ) (string , error ) {
if s .eof () || s .data [s .off ] != '"' {
return "" , &UnmarshalError {s .off , ErrInvalidStringFormat }
}
s .off ++
var b strings .Builder
for !s .eof () {
c := s .data [s .off ]
s .off ++
switch c {
case '\\' :
if s .eof () {
return "" , &UnmarshalError {s .off , ErrInvalidStringFormat }
}
n := s .data [s .off ]
if n != '"' && n != '\\' {
return "" , &UnmarshalError {s .off , ErrInvalidStringFormat }
}
s .off ++
if err := b .WriteByte (n ); err != nil {
return "" , err
}
continue
case '"' :
return b .String (), nil
default :
if c <= '\u001F' || c >= unicode .MaxASCII {
return "" , &UnmarshalError {s .off , ErrInvalidStringFormat }
}
if err := b .WriteByte (c ); err != nil {
return "" , err
}
}
}
return "" , &UnmarshalError {s .off , ErrInvalidStringFormat }
}
The pages are generated with Golds v0.8.2 . (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 .