(s string)
| 684 | var asciiSpace = [256]uint8{'\t': 1, '\n': 1, '\v': 1, '\f': 1, '\r': 1, ' ': 1} |
| 685 | |
| 686 | func parseKeywordValueSettings(s string) (map[string]string, error) { |
| 687 | settings := make(map[string]string) |
| 688 | |
| 689 | // Trim any leading whitespace so that the loop exits cleanly when only |
| 690 | // spaces remain (e.g. trailing spaces after the last value). |
| 691 | s = strings.TrimLeft(s, " \t\n\r\v\f") |
| 692 | for len(s) > 0 { |
| 693 | var key, val string |
| 694 | eqIdx := strings.IndexRune(s, '=') |
| 695 | if eqIdx < 0 { |
| 696 | return nil, errors.New("invalid keyword/value") |
| 697 | } |
| 698 | |
| 699 | key = strings.Trim(s[:eqIdx], " \t\n\r\v\f") |
| 700 | s = strings.TrimLeft(s[eqIdx+1:], " \t\n\r\v\f") |
| 701 | switch { |
| 702 | case len(s) == 0: |
| 703 | case s[0] != '\'': |
| 704 | end := 0 |
| 705 | for ; end < len(s); end++ { |
| 706 | if asciiSpace[s[end]] == 1 { |
| 707 | break |
| 708 | } |
| 709 | if s[end] == '\\' { |
| 710 | end++ |
| 711 | if end == len(s) { |
| 712 | return nil, errors.New("invalid backslash") |
| 713 | } |
| 714 | } |
| 715 | } |
| 716 | val = strings.ReplaceAll(strings.ReplaceAll(s[:end], "\\\\", "\\"), "\\'", "'") |
| 717 | // Consume the value and trim any subsequent whitespace so that |
| 718 | // multiple trailing spaces don't cause a spurious parse failure. |
| 719 | s = strings.TrimLeft(s[end:], " \t\n\r\v\f") |
| 720 | default: // quoted string |
| 721 | s = s[1:] |
| 722 | end := 0 |
| 723 | for ; end < len(s); end++ { |
| 724 | if s[end] == '\'' { |
| 725 | break |
| 726 | } |
| 727 | if s[end] == '\\' { |
| 728 | end++ |
| 729 | } |
| 730 | } |
| 731 | if end == len(s) { |
| 732 | return nil, errors.New("unterminated quoted string in connection info string") |
| 733 | } |
| 734 | val = strings.ReplaceAll(strings.ReplaceAll(s[:end], "\\\\", "\\"), "\\'", "'") |
| 735 | // Consume the closing quote and any subsequent whitespace. |
| 736 | s = strings.TrimLeft(s[end+1:], " \t\n\r\v\f") |
| 737 | } |
| 738 | |
| 739 | key = canonicalConnStringKey(key) |
| 740 | |
| 741 | if key == "" { |
| 742 | return nil, errors.New("invalid keyword/value") |
| 743 | } |
no test coverage detected