2016-04-04 18:35 GMT+03:00 Ni Va <[email protected]>:
> Hi,
>
> I've got some CDATA sections in html source and want to pass easily from 
> utf-16 characters to ascii chars and opposite operation.
>
> I'am currently using a dict to make needed substitutions. Is it possible to 
> avoid this king of func passing by some others predefined commands ?
>
>
> fun! TestFunc2() "{{{
>   "
>   " 02 Convert Code
>   "
>
>   let mydict={'&quot;':'"', '&apos;':"'", '&lt;':'<', '&gt;':'>',
>   '&#xD;':'\r', '&#xA;':'\n', '&amp;':'&' }
>
>   let item=""
>   for item in keys(mydict)

This code looks like it is going to replace `&quot;amp;` with `&` or
something like this (depends on the order of keys in the hash table
which is not guaranteed to be fixed (though not like in Python >=3.3
where it is intentionally random unless you turn this functionality
off: currently you will have the same order that depends purely on key
values and an order of insertion)). You must construct a single regexp
out of the keys to do substitute in one go. For `&#x…;` you may use \=
and str2nr() to turn entity into a character, for others dictionary is
the only sane choice. Probably better write this as two functions or
you will have rather lengthy expression in \= if you add special
handling for &#x…;.

I do not know any way to do this without helper functions. But AFAIR
there is some plugin which has this function written for you, I do not
use it though and have not saved reference to it anywhere.

>     exe "silent! %s/".item.'/\=get(mydict, submatch(0), submatch(0))/g'
>   endfor
>
>   set ft=vb
>   norm 1G
>
> endfunction "}}}
>
> --
> --
> You received this message from the "vim_use" maillist.
> Do not top-post! Type your reply below the text you are replying to.
> For more information, visit http://www.vim.org/maillist.php
>
> ---
> You received this message because you are subscribed to the Google Groups 
> "vim_use" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to [email protected].
> For more options, visit https://groups.google.com/d/optout.

-- 
-- 
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to