# File lib/postgres-pr/typeconv/array.rb, line 5 def decode_array(str, delim=',', &conv_proc) delim = Regexp.escape(delim) buf = StringScanner.new(str) return parse_arr(buf, delim, &conv_proc) ensure raise ConversionError, "end of string expected (#{buf.rest})" unless buf.empty? end
Decodes a bytea encoded string.
for decoding rules see:
http://www.postgresql.org/docs/7.4/static/datatype-binary.html
# File lib/postgres-pr/typeconv/bytea.rb, line 20 def decode_bytea(str) str.gsub(/\\(\\|'|[0-3][0-7][0-7])/) {|s| if s.size == 2 then s[1,1] else s[1,3].oct.chr end } end
Encodes a string as bytea value.
for encoding rules see:
http://www.postgresql.org/docs/7.4/static/datatype-binary.html
# File lib/postgres-pr/typeconv/bytea.rb, line 10 def encode_bytea(str) str.gsub(/[\0000-\0037\0047\1134\1177-\3377]/) {|b| "\\#{ b[0].to_s(8).rjust(3, '0') }" } end
Generated with the Darkfish Rdoc Generator 2.