Class | Sequel::Postgres::PGRow::Splitter |
In: |
lib/sequel/extensions/pg_row.rb
|
Parent: | StringScanner |
This parser-like class splits the PostgreSQL row-valued/composite type output string format into an array of strings. Note this class makes no attempt to handle all input formats that PostgreSQL will accept, it only handles the output format that PostgreSQL uses.
OPEN_PAREN | = | /\(/.freeze |
CLOSE_PAREN | = | /\)/.freeze |
UNQUOTED_RE | = | /[^,)]*/.freeze |
SEP_RE | = | /[,)]/.freeze |
QUOTE_RE | = | /"/.freeze |
QUOTE_SEP_RE | = | /"[,)]/.freeze |
QUOTED_RE | = | /(\\.|""|[^"])*/.freeze |
REPLACE_RE | = | /\\(.)|"(")/.freeze |
REPLACE_WITH | = | '\1\2'.freeze |
Split the stored string into an array of strings, handling the different types of quoting.
# File lib/sequel/extensions/pg_row.rb, line 235 235: def parse 236: return @result if @result 237: values = [] 238: skip(OPEN_PAREN) 239: if skip(CLOSE_PAREN) 240: values << nil 241: else 242: until eos? 243: if skip(QUOTE_RE) 244: values << scan(QUOTED_RE).gsub(REPLACE_RE, REPLACE_WITH) 245: skip(QUOTE_SEP_RE) 246: else 247: v = scan(UNQUOTED_RE) 248: values << (v unless v.empty?) 249: skip(SEP_RE) 250: end 251: end 252: end 253: values 254: end