MCPcopy Create free account
hub / github.com/MaterializeInc/materialize / parse_options

Function parse_options

src/pgwire/src/protocol.rs:656–675  ·  view source on GitHub ↗

Returns (name, value) session settings pairs from an options value. From Postgres, see pg_split_opts in postinit.c and process_postgres_switches in postgres.c.

(value: &str)

Source from the content-addressed store, hash-verified

654/// From Postgres, see pg_split_opts in postinit.c and process_postgres_switches
655/// in postgres.c.
656fn parse_options(value: &str) -> Result<Vec<(String, String)>, ()> {
657 let opts = split_options(value);
658 let mut pairs = Vec::with_capacity(opts.len());
659 let mut seen_prefix = false;
660 for opt in opts {
661 if !seen_prefix {
662 if opt == "-c" {
663 seen_prefix = true;
664 } else {
665 let (key, val) = parse_option(&opt)?;
666 pairs.push((key.to_owned(), val.to_owned()));
667 }
668 } else {
669 let (key, val) = opt.split_once('=').ok_or(())?;
670 pairs.push((key.to_owned(), val.to_owned()));
671 seen_prefix = false;
672 }
673 }
674 Ok(pairs)
675}
676
677/// Returns the parsed key and value from option of the form `--key=value`, `-c
678/// key=value`, or `-ckey=value`. Keys replace `-` with `_`. Returns an error if

Callers 2

runFunction · 0.85
test_parse_optionsFunction · 0.85

Calls 5

split_optionsFunction · 0.85
parse_optionFunction · 0.85
lenMethod · 0.45
pushMethod · 0.45
to_ownedMethod · 0.45

Tested by 1

test_parse_optionsFunction · 0.68