MCPcopy Create free account
hub / github.com/auxten/postgresql-parser / scanHexString

Method scanHexString

pkg/sql/parser/scan.go:695–749  ·  view source on GitHub ↗

scanHexString scans the content inside x'....'.

(lval *sqlSymType, ch int)

Source from the content-addressed store, hash-verified

693
694// scanHexString scans the content inside x'....'.
695func (s *scanner) scanHexString(lval *sqlSymType, ch int) bool {
696 buf := s.buffer()
697
698 var curbyte byte
699 bytep := 0
700 const errInvalidBytesLiteral = "invalid hexadecimal bytes literal"
701outer:
702 for {
703 b := s.next()
704 switch b {
705 case ch:
706 newline, ok := s.skipWhitespace(lval, false)
707 if !ok {
708 return false
709 }
710 // SQL allows joining adjacent strings separated by whitespace
711 // as long as that whitespace contains at least one
712 // newline. Kind of strange to require the newline, but that
713 // is the standard.
714 if s.peek() == ch && newline {
715 s.pos++
716 continue
717 }
718 break outer
719
720 case '0', '1', '2', '3', '4', '5', '6', '7', '8', '9':
721 curbyte = (curbyte << 4) | byte(b-'0')
722 case 'a', 'b', 'c', 'd', 'e', 'f':
723 curbyte = (curbyte << 4) | byte(b-'a'+10)
724 case 'A', 'B', 'C', 'D', 'E', 'F':
725 curbyte = (curbyte << 4) | byte(b-'A'+10)
726 default:
727 lval.id = ERROR
728 lval.str = errInvalidBytesLiteral
729 return false
730 }
731 bytep++
732
733 if bytep > 1 {
734 buf = append(buf, curbyte)
735 bytep = 0
736 curbyte = 0
737 }
738 }
739
740 if bytep != 0 {
741 lval.id = ERROR
742 lval.str = errInvalidBytesLiteral
743 return false
744 }
745
746 lval.id = BCONST
747 lval.str = s.finishString(buf)
748 return true
749}
750
751// scanBitString scans the content inside B'....'.
752func (s *scanner) scanBitString(lval *sqlSymType, ch int) bool {

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