Skip to content

Commit

Permalink
xpt#snip#TextToPlaceholders add escape
Browse files Browse the repository at this point in the history
  • Loading branch information
drmingdrmer committed Feb 5, 2015
1 parent 9a0742d commit 322759a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
7 changes: 4 additions & 3 deletions autoload/xpt/snip.vim
Expand Up @@ -176,6 +176,7 @@ endfunction "}}}
fun! xpt#snip#TextToPlaceholders(text, ptn) "{{{

let [ l, r ] = [ a:ptn.l, a:ptn.r ]
let lr = l . r

let toks = xpt#snip#Tokenize(a:text, a:ptn) + ["", "", ""]
let elts = []
Expand All @@ -190,13 +191,13 @@ fun! xpt#snip#TextToPlaceholders(text, ptn) "{{{
let chr = tok[0]
if chr != l && chr != r
if tok != ""
call add(elts, {'text': tok})
call add(elts, {'text': xpt#util#UnescapeChar(tok, lr)})
endif
continue
endif

if chr == l
call add(buf, {'text': tok[1:]})
call add(buf, {'text': xpt#util#UnescapeChar(tok[1:], lr)})
continue
endif

Expand All @@ -215,7 +216,7 @@ fun! xpt#snip#TextToPlaceholders(text, ptn) "{{{
else
" toks[i+1] is text
if toks[i + 2] == r
let [flt, iFilterEnd] = [{'text': toks[i + 1]}, i + 2]
let [flt, iFilterEnd] = [{'text': xpt#util#UnescapeChar(toks[i + 1], lr)}, i + 2]
else
continue
endif
Expand Down
21 changes: 21 additions & 0 deletions autoload/xpt/ut/test_snip.vim
Expand Up @@ -46,6 +46,17 @@ fun! s:TestTextToPlaceholders(t) "{{{
\ [' a ', [{'text': ' a '}]],
\ ['a b', [{'text': 'a b'}]],
\
\ ['\', [{'text': '\'}]],
\ ['\\', [{'text': '\\'}]],
\
\ ['\`', [{'text': '`'}]],
\ ['\\\`', [{'text': '\`'}]],
\ ['\\\\\`', [{'text': '\\`'}]],
\
\ ['\^', [{'text': '^'}]],
\ ['\\\^', [{'text': '\^'}]],
\ ['\\\\\^', [{'text': '\\^'}]],
\
\ [' a b', [{'text': ' a b'}]],
\ [' a b ', [{'text': ' a b '}]],
\
Expand Down Expand Up @@ -111,6 +122,16 @@ fun! s:TestTextToPlaceholders(t) "{{{
\ },
\ { "text": "\n" },
\ { "name": { "text": "Inc('t')" } }]],
\
\ ["a\n`\\\n\\` \\\\`tr($A, 'a', 'b')` \\^^\nEcho(0)^\n`Inc('t')^",
\ [ { "text": "a\n"},
\ { "leftEdge": {"text": "\\\n` \\\\"},
\ "name": {"text": "tr($A, 'a', 'b')"},
\ "rightEdge": {"text": " ^"},
\ "liveFilter": {"text": "\nEcho(0)"},
\ },
\ { "text": "\n" },
\ { "name": { "text": "Inc('t')" } }]],
\ ]

for [inp, outp] in cases
Expand Down

0 comments on commit 322759a

Please sign in to comment.