Reply to message «Re: lazyredraw for encoding change?», sent 00:23:41 21 March 2011, Monday by [email protected]:
> I need to map each character to specific strings, for which I have a
> dictionary (mappings below) for each character 128-255. For example, <97>
> maps to "AA". I use the substitute() function along with submatch to do
> that.
I would have used something like this:
let i=0
let slen=len(str)
let r=""
while i<slen
let c=char2nr(str[i])
if c>128
let r.=mappings[str[i]]
else
let r.=str[i]
endif
let i+=1
endwhile
Though I tested another option and it works:
echo substitute(str, "[\x7F-\xFF]", '\=mappings[submatch(0)]', "g")
Note the single quotes around {pattern}: it will force pattern to contain
specific bites, not unicode characters.
Original message:
> Hi ZyX,
>
> Here is a specific example:
>
> I have a string that has 8-bits characters in the 128-255 range
>
> :let a ="<97><9e>·<97>¢<96><9b>Ü<88>å<82>ÌÂ<98>Ð0"
>
> I need to map each character to specific strings, for which I have a
> dictionary (mappings below) for each character 128-255. For example, <97>
> maps to "AA". I use the substitute() function along with submatch to do
> that.
>
> let retval = substitute(value, '\([\d128-\d255]\)',
> '\=mappings[submatch(1)]', "g")
>
> It appears to me that substitute() seems to be running based off the
> current encoding setting, even if I converted all the rest to "latin1"
> using iconv() functions.
>
>
> Thanks for any help!
>
> On Sun, Mar 20, 2011 at 1:54 PM, ZyX <[email protected]> wrote:
> > Reply to message «lazyredraw for encoding change?»,
> > sent 23:18:31 20 March 2011, Sunday
> > by [email protected]:
> >
> > What do you switch? 'encoding'? You are not supposed to do this ever, why
> > don't
> > you use `iconv()', `scriptencoding utf-8', 'fileencoding', `e ++enc' or
> > some
> > other stuff depending on what you actually do in your script. Can you
> > provide
> > more specific example?
> >
> > Original message:
> > > Hello All,
> > >
> > > I have a script which needs to manipulate strings in 8-bit characters.
> >
> > So,
> >
> > > I switch between the current encoding and the 8-bit encoding. However,
> >
> > the
> >
> > > screen redraws during the change of encoding. Is there a way to
> > > suppress it?
> > >
> > > Thanks!
signature.asc
Description: This is a digitally signed message part.
