MCPcopy Create free account
hub / github.com/dolthub/doltgresql / scanBitString

Method scanBitString

postgres/parser/parser/scan.go:808–841  ·  view source on GitHub ↗

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

(lval *sqlSymType, ch int)

Source from the content-addressed store, hash-verified

806
807// scanBitString scans the content inside B'....'.
808func (s *scanner) scanBitString(lval *sqlSymType, ch int) bool {
809 buf := s.buffer()
810outer:
811 for {
812 b := s.next()
813 switch b {
814 case ch:
815 _, newline, ok := s.skipWhitespace(lval, false)
816 if !ok {
817 return false
818 }
819 // SQL allows joining adjacent strings separated by whitespace
820 // as long as that whitespace contains at least one
821 // newline. Kind of strange to require the newline, but that
822 // is the standard.
823 if s.peek() == ch && newline {
824 s.pos++
825 continue
826 }
827 break outer
828
829 case '0', '1':
830 buf = append(buf, byte(b))
831 default:
832 lval.id = ERROR
833 lval.str = fmt.Sprintf(`"%c" is not a valid binary digit`, rune(b))
834 return false
835 }
836 }
837
838 lval.id = BITCONST
839 lval.str = s.finishString(buf)
840 return true
841}
842
843// scanString scans the content inside '...'. This is used for simple
844// string literals '...' but also e'....' and b'...'. For x'...', see

Callers 1

scanMethod · 0.95

Calls 5

bufferMethod · 0.95
nextMethod · 0.95
skipWhitespaceMethod · 0.95
peekMethod · 0.95
finishStringMethod · 0.95

Tested by

no test coverage detected