# # Very basic method that tokenizes a string based on commas, # while honoring single and double quotes. # # (written on 2008-02-07 for linoj in #ruby-lang) # def tokenize_line(str) in_quote = false str.split(//).inject(['']) do |r, c| if in_quote if c == '"' || c == "'" in_quote = false else r[-1] << c end else if c == ',' r << '' elsif c == '"' || c == "'" in_quote = true else r[-1] << c end end r end end