MCPcopy Create free account
hub / github.com/cockroachdb/cockroachdb-parser / scanBitString

Method scanBitString

pkg/sql/scanner/scan.go:885–919  ·  view source on GitHub ↗

scanBitString scans the content inside B'....'.

(lval ScanSymType, ch int)

Source from the content-addressed store, hash-verified

883
884// scanBitString scans the content inside B'....'.
885func (s *Scanner) scanBitString(lval ScanSymType, ch int) bool {
886 s.lastAttemptedID = int32(lexbase.BITCONST)
887 buf := s.buffer()
888outer:
889 for {
890 b := s.next()
891 switch b {
892 case ch:
893 newline, ok := s.skipWhitespace(lval, false)
894 if !ok {
895 return false
896 }
897 // SQL allows joining adjacent strings separated by whitespace
898 // as long as that whitespace contains at least one
899 // newline. Kind of strange to require the newline, but that
900 // is the standard.
901 if s.peek() == ch && newline {
902 s.pos++
903 continue
904 }
905 break outer
906
907 case '0', '1':
908 buf = append(buf, byte(b))
909 default:
910 lval.SetID(lexbase.ERROR)
911 lval.SetStr(fmt.Sprintf(`"%c" is not a valid binary digit`, rune(b)))
912 return false
913 }
914 }
915
916 lval.SetID(lexbase.BITCONST)
917 lval.SetStr(s.finishString(buf))
918 return true
919}
920
921// scanString scans the content inside '...'. This is used for simple
922// string literals '...' but also e'....' and b'...'. For x'...', see

Callers 1

ScanMethod · 0.80

Calls 7

bufferMethod · 0.95
nextMethod · 0.95
skipWhitespaceMethod · 0.95
peekMethod · 0.95
finishStringMethod · 0.95
SetIDMethod · 0.65
SetStrMethod · 0.65

Tested by

no test coverage detected