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

Method scanHexString

pkg/sql/scanner/scan.go:827–882  ·  view source on GitHub ↗

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

(lval ScanSymType, ch int)

Source from the content-addressed store, hash-verified

825
826// scanHexString scans the content inside x'....'.
827func (s *Scanner) scanHexString(lval ScanSymType, ch int) bool {
828 s.lastAttemptedID = int32(lexbase.BCONST)
829 buf := s.buffer()
830
831 var curbyte byte
832 bytep := 0
833 const errInvalidBytesLiteral = "invalid hexadecimal bytes literal"
834outer:
835 for {
836 b := s.next()
837 switch b {
838 case ch:
839 newline, ok := s.skipWhitespace(lval, false)
840 if !ok {
841 return false
842 }
843 // SQL allows joining adjacent strings separated by whitespace
844 // as long as that whitespace contains at least one
845 // newline. Kind of strange to require the newline, but that
846 // is the standard.
847 if s.peek() == ch && newline {
848 s.pos++
849 continue
850 }
851 break outer
852
853 case '0', '1', '2', '3', '4', '5', '6', '7', '8', '9':
854 curbyte = (curbyte << 4) | byte(b-'0')
855 case 'a', 'b', 'c', 'd', 'e', 'f':
856 curbyte = (curbyte << 4) | byte(b-'a'+10)
857 case 'A', 'B', 'C', 'D', 'E', 'F':
858 curbyte = (curbyte << 4) | byte(b-'A'+10)
859 default:
860 lval.SetID(lexbase.ERROR)
861 lval.SetStr(errInvalidBytesLiteral)
862 return false
863 }
864 bytep++
865
866 if bytep > 1 {
867 buf = append(buf, curbyte)
868 bytep = 0
869 curbyte = 0
870 }
871 }
872
873 if bytep != 0 {
874 lval.SetID(lexbase.ERROR)
875 lval.SetStr(errInvalidBytesLiteral)
876 return false
877 }
878
879 lval.SetID(lexbase.BCONST)
880 lval.SetStr(s.finishString(buf))
881 return true
882}
883
884// scanBitString scans the content inside B'....'.

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