1 " Vim script
 2 " Maintainer: Peter Odding <peter@peterodding.com>
 3 " Last Change: June 10, 2010
 4 " URL: http://peterodding.com/code/vim/profile/autoload/xolox/option.vim
 5 
 6 " Functions to parse multi-valued Vim options like &tags and &runtimepath.
 7 
 8 function! xolox#option#split(value) " {{{1
 9   let values = split(a:value, '[^\\]\zs,')
10   return map(values, 's:unescape(v:val)')
11 endfunction
12 
13 function! s:unescape(s)
14   return substitute(a:s, '\\\([\\,]\)', '\1', 'g')
15 endfunction
16 
17 function! xolox#option#join(values) " {{{1
18   let values = copy(a:values)
19   call map(values, 's:escape(v:val)')
20   return join(values, ',')
21 endfunction
22 
23 function! s:escape(s)
24   return escape(a:s, ',\')
25 endfunction
26 
27 function! xolox#option#split_tags(value) " {{{1
28   let values = split(a:value, '[^\\]\zs,')
29   return map(values, 's:unescape_tags(v:val)')
30 endfunction
31 
32 function! s:unescape_tags(s)
33   return substitute(a:s, '\\\([\\, ]\)', '\1', 'g')
34 endfunction
35 
36 function! xolox#option#join_tags(values) " {{{1
37   let values = copy(a:values)
38   call map(values, 's:escape_tags(v:val)')
39   return join(values, ',')
40 endfunction
41 
42 function! s:escape_tags(s)
43   return escape(a:s, ', ')
44 endfunction
45 
46 " vim: ts=2 sw=2 et