module BioRdf::RDF
Public Class Methods
escape_string_literal(literal)
click to toggle source
# File lib/bio/writers/rdf.rb, line 11 def RDF::escape_string_literal(literal) s = literal.to_s # Put a slash before every double quote if there is no such slash already s = s.gsub(/(?<!\\)"/,'\"') # Put a slash before a single slash if it is not \["utnr>\] if s =~ /[^\\]\\[^\\]/ s2 = [] s.each_char.with_index { |c,i| res = c if i>0 and c == '\\' and s[i-1] != '\\' and s[i+1] !~ /^[uUtnr\\"]/ res = '\\' + c end # p [i,c,s[i+1],res] s2 << res } s = s2.join('') end s end
quoted_stringify_literal(literal)
click to toggle source
# File lib/bio/writers/rdf.rb, line 35 def RDF::quoted_stringify_literal(literal) '"' + stringify_literal(literal) + '"' end
stringify_literal(literal)
click to toggle source
# File lib/bio/writers/rdf.rb, line 31 def RDF::stringify_literal(literal) RDF::escape_string_literal(literal.to_s) end
valid_uri?(uri)
click to toggle source
# File lib/bio/writers/rdf.rb, line 7 def RDF::valid_uri? uri uri =~ /^([!#$&-;=?_a-z~]|%[0-9a-f]{2})+$/i end