scanHexString scans the content inside x'....'.
(lval *sqlSymType, ch int)
| 693 | |
| 694 | // scanHexString scans the content inside x'....'. |
| 695 | func (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" |
| 701 | outer: |
| 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'....'. |
| 752 | func (s *scanner) scanBitString(lval *sqlSymType, ch int) bool { |
no test coverage detected