ParseDBool parses and returns the *DBool Datum value represented by the provided string, or an error if parsing is unsuccessful. See https://github.com/postgres/postgres/blob/90627cf98a8e7d0531789391fd798c9bfcc3bc1a/src/backend/utils/adt/bool.c#L36
(s string)
| 169 | // string, or an error if parsing is unsuccessful. |
| 170 | // See https://github.com/postgres/postgres/blob/90627cf98a8e7d0531789391fd798c9bfcc3bc1a/src/backend/utils/adt/bool.c#L36 |
| 171 | func ParseDBool(s string) (*DBool, error) { |
| 172 | s = strings.TrimSpace(s) |
| 173 | if len(s) >= 1 { |
| 174 | switch s[0] { |
| 175 | case 't', 'T': |
| 176 | if isCaseInsensitivePrefix(s, "true") { |
| 177 | return DBoolTrue, nil |
| 178 | } |
| 179 | case 'f', 'F': |
| 180 | if isCaseInsensitivePrefix(s, "false") { |
| 181 | return DBoolFalse, nil |
| 182 | } |
| 183 | case 'y', 'Y': |
| 184 | if isCaseInsensitivePrefix(s, "yes") { |
| 185 | return DBoolTrue, nil |
| 186 | } |
| 187 | case 'n', 'N': |
| 188 | if isCaseInsensitivePrefix(s, "no") { |
| 189 | return DBoolFalse, nil |
| 190 | } |
| 191 | case '1': |
| 192 | if s == "1" { |
| 193 | return DBoolTrue, nil |
| 194 | } |
| 195 | case '0': |
| 196 | if s == "0" { |
| 197 | return DBoolFalse, nil |
| 198 | } |
| 199 | case 'o', 'O': |
| 200 | // Just 'o' is ambiguous between 'on' and 'off'. |
| 201 | if len(s) > 1 { |
| 202 | if isCaseInsensitivePrefix(s, "on") { |
| 203 | return DBoolTrue, nil |
| 204 | } |
| 205 | if isCaseInsensitivePrefix(s, "off") { |
| 206 | return DBoolFalse, nil |
| 207 | } |
| 208 | } |
| 209 | } |
| 210 | } |
| 211 | return nil, makeParseError(s, types.Bool, pgerror.New(pgcode.InvalidTextRepresentation, "invalid bool value")) |
| 212 | } |
| 213 | |
| 214 | // ParseDByte parses a string representation of hex encoded binary |
| 215 | // data. It supports both the hex format, with "\x" followed by a |
no test coverage detected