Closed ghost closed 9 years ago
Verified that sed works as scott says: +1
I would like to see a way for the delimiter to adapt to the specific input, either though an added property in the type (say, 'match_delimiter' or 'after_delimiter') that the caller would be responsible to set, with a sensible default like '|', or through some coding that searches through candidate delimiters until it either finds one that's not in 'match' or 'after', or fails.
irb(main):014:0> def find_delimiter(user)
irb(main):015:1> delimiter = false
irb(main):016:1> candidate_delimiters = ["/", "|", ",", "="]
irb(main):017:1> candidate_delimiters.each{|candidate| delimiter = candidate unless (user.match candidate) }
irb(main):018:1> delimiter
irb(main):019:1> end
irb(main):020:0> find_delimiter "foo"
=> "="
irb(main):022:0> find_delimiter "|,="
=> "/"
irb(main):024:0> def find_delimiter(user)
irb(main):025:1> delimiter = false
irb(main):026:1> candidate_delimiters = ["/", "|", ",", "="]
irb(main):027:1> candidate_delimiters.each{|candidate| delimiter = candidate unless (user.match candidate) }
irb(main):028:1> delimiter or fail
irb(main):029:1> end
=> nil
irb(main):030:0> find_delimiter "foo"
=> "="
irb(main):031:0> find delimiter "|,="
NoMethodError: undefined method `delimiter' for main:Object
from (irb):31
from :0
irb(main):032:0> find_delimiter "|,="
=> "/"
irb(main):033:0> find_delimiter "/|,="
RuntimeError:
from (irb):28:in `find_delimiter'
from (irb):33
from :0
irb(main):034:0>
of course, choose a good set of candidate delimiters
Created story based on Randy's comments and merging existing fix's.
Modified the sed command to use "|" instead of "/" as the delimiter. The current "/" was causing issue with various updates that would need multiple escape "\".