Re: tr() problem ?
On Wed, Feb 9, 2011 at 12:04 PM, Dimitar DIMITROV wrote: > But this doesn't: > > command! Translate call setline(line('.'), tr(getline('.'), > \'ABVGDEWZIJKLMNOPRSTUYFHXC$^&}{!|Qabvgdewzijklmnoprstuyfhxc467][1\q', > \'АБВГДЕЖЗИЙКЛМНОПРСТУYФХXЦЧШЩЪЬЮЮЯабвгдежзийклмнопрстуyфхxцчшщъьююя')) > > then :Translate on any line > > The error is: > E475: Invalid argument: > ABVGDEWZIJKLMNOPRSTUYFHXC$^&}{!|Qabvgdewzijklmnoprstuyfhxc467][1\q This has something to do with how Vim is storing the U+0440 character (which breaks down to \xd1\x80) in the "to" string. A minimal reproduction can be done with this simplified version: command! Translate echo tr(getline('.'), 'r', 'р') and then use Translate with your cursor on the line defining the command. In fact, if you use the following erroneous version of the command, the error string that Vim prints when you try to use :Translate will show that the U+0440 character has been corrupted: command! Translate echo tr(getline('.'), 'r', \'p') I end up getting: E15: Invalid expression: \'рX') Everything works fine if the command is defined using "\u0440" instead of the literal character. -- James GPG Key: 1024D/61326D40 2003-09-02 James Vega -- You received this message from the "vim_dev" 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
Re : tr() problem ?
Thanks James, I'll use "\u0440" as you suggested D De : James Vega À : vim_dev@googlegroups.com Envoyé le : Mer 9 février 2011, 19h 10min 55s Objet : Re: tr() problem ? On Wed, Feb 9, 2011 at 12:04 PM, Dimitar DIMITROV wrote: > But this doesn't: > > command! Translate call setline(line('.'), tr(getline('.'), >\'ABVGDEWZIJKLMNOPRSTUYFHXC$^&}{!|Qabvgdewzijklmnoprstuyfhxc467][1\q', >\'АБВГДЕЖЗИЙКЛМНОПРСТУYФХXЦЧШЩЪЬЮЮЯабвгдежзийклмнопрстуyфхxцчшщъьююя')) > > then :Translate on any line > > The error is: > E475: Invalid argument: > ABVGDEWZIJKLMNOPRSTUYFHXC$^&}{!|Qabvgdewzijklmnoprstuyfhxc467][1\q This has something to do with how Vim is storing the U+0440 character (which breaks down to \xd1\x80) in the "to" string. A minimal reproduction can be done with this simplified version: command! Translate echo tr(getline('.'), 'r', 'р') and then use Translate with your cursor on the line defining the command. In fact, if you use the following erroneous version of the command, the error string that Vim prints when you try to use :Translate will show that the U+0440 character has been corrupted: command! Translate echo tr(getline('.'), 'r', \'p') I end up getting: E15: Invalid expression: \'рX') Everything works fine if the command is defined using "\u0440" instead of the literal character. -- James GPG Key: 1024D/61326D40 2003-09-02 James Vega -- You received this message from the "vim_dev" 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 from the "vim_dev" 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
Re: tr() problem ?
On Wed, Feb 9, 2011 at 2:10 PM, James Vega wrote: > On Wed, Feb 9, 2011 at 12:04 PM, Dimitar DIMITROV wrote: >> But this doesn't: >> >> command! Translate call setline(line('.'), tr(getline('.'), >> \'ABVGDEWZIJKLMNOPRSTUYFHXC$^&}{!|Qabvgdewzijklmnoprstuyfhxc467][1\q', >> \'АБВГДЕЖЗИЙКЛМНОПРСТУYФХXЦЧШЩЪЬЮЮЯабвгдежзийклмнопрстуyфхxцчшщъьююя')) >> >> then :Translate on any line >> >> The error is: >> E475: Invalid argument: >> ABVGDEWZIJKLMNOPRSTUYFHXC$^&}{!|Qabvgdewzijklmnoprstuyfhxc467][1\q > > This has something to do with how Vim is storing the U+0440 character > (which breaks down to \xd1\x80) in the "to" string. A minimal > reproduction can be done with this simplified version: > > command! Translate echo tr(getline('.'), 'r', 'р') > > and then use Translate with your cursor on the line defining the > command. > > In fact, if you use the following erroneous version of the command, the > error string that Vim prints when you try to use :Translate will show > that the U+0440 character has been corrupted: > > command! Translate echo tr(getline('.'), 'r', \'p') > > I end up getting: E15: Invalid expression: \'рX') > > Everything works fine if the command is defined using "\u0440" instead > of the literal character. Another interesting data point is that the workaround of using "\u0440" only works when building Vim without GUI support. Building with GUI type of any support (I tried Athena, motif and Gtk2) causes the problem to occur even when using "\u0440" instead of "р". -- James GPG Key: 1024D/61326D40 2003-09-02 James Vega -- You received this message from the "vim_dev" 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
Re : tr() problem ?
I just tested: :com! Test ec '♛' then :Test prints ♀Q :ec '♛' prints '♛' So the problem is :com related not tr() as previously thought De : James Vega À : vim_dev@googlegroups.com Cc : Bram Moolenaar Envoyé le : Jeu 10 février 2011, 21h 04min 42s Objet : Re: tr() problem ? On Wed, Feb 9, 2011 at 2:10 PM, James Vega wrote: > On Wed, Feb 9, 2011 at 12:04 PM, Dimitar DIMITROV wrote: >> But this doesn't: >> >> command! Translate call setline(line('.'), tr(getline('.'), >>\'ABVGDEWZIJKLMNOPRSTUYFHXC$^&}{!|Qabvgdewzijklmnoprstuyfhxc467][1\q', >>\'АБВГДЕЖЗИЙКЛМНОПРСТУYФХXЦЧШЩЪЬЮЮЯабвгдежзийклмнопрстуyфхxцчшщъьююя')) >> >> then :Translate on any line >> >> The error is: >> E475: Invalid argument: >> ABVGDEWZIJKLMNOPRSTUYFHXC$^&}{!|Qabvgdewzijklmnoprstuyfhxc467][1\q > > This has something to do with how Vim is storing the U+0440 character > (which breaks down to \xd1\x80) in the "to" string. A minimal > reproduction can be done with this simplified version: > > command! Translate echo tr(getline('.'), 'r', 'р') > > and then use Translate with your cursor on the line defining the > command. > > In fact, if you use the following erroneous version of the command, the > error string that Vim prints when you try to use :Translate will show > that the U+0440 character has been corrupted: > > command! Translate echo tr(getline('.'), 'r', \'p') > > I end up getting: E15: Invalid expression: \'рX') > > Everything works fine if the command is defined using "\u0440" instead > of the literal character. Another interesting data point is that the workaround of using "\u0440" only works when building Vim without GUI support. Building with GUI type of any support (I tried Athena, motif and Gtk2) causes the problem to occur even when using "\u0440" instead of "р". -- James GPG Key: 1024D/61326D40 2003-09-02 James Vega -- You received this message from the "vim_dev" 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 from the "vim_dev" 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
Re: Re : tr() problem ?
On 11/02/11 11:02 PM, Dimitar DIMITROV wrote: I just tested: :com! Test ec '♛' then :Test prints ♀Q :ec '♛' prints '♛' So the problem is :com related not tr() as previously thought Attached is the fix. K_SPECIAL is not a multibyte character code, so vim_strchr is not an appropriate way to search for it. A bytewise search of the string is needed. Ben. -- You received this message from the "vim_dev" 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 # HG changeset patch # Parent 0032a84f560c4a5970cb3be1fa93d52ffe9f4d22 diff --git a/src/ex_docmd.c b/src/ex_docmd.c --- a/src/ex_docmd.c +++ b/src/ex_docmd.c @@ -6072,8 +6072,10 @@ end = vim_strchr(start + 1, '>'); if (buf != NULL) { - ksp = vim_strchr(p, K_SPECIAL); - if (ksp != NULL && (start == NULL || ksp < start || end == NULL) + ksp = p; + while (*ksp != NUL && *ksp != K_SPECIAL) + ++ksp; + if (*ksp == K_SPECIAL && (start == NULL || ksp < start || end == NULL) && ((ksp[1] == KS_SPECIAL && ksp[2] == KE_FILLER) # ifdef FEAT_GUI || (ksp[1] == KS_EXTRA && ksp[2] == (int)KE_CSI)
Re: Re : tr() problem ?
Ben Schmidt wrote: > On 11/02/11 11:02 PM, Dimitar DIMITROV wrote: > > I just tested: > > > > :com! Test ec '♛' > > then > > :Test prints ♀Q > > :ec '♛' prints '♛' > > > > So the problem is :com related not tr() as previously thought > > Attached is the fix. > > K_SPECIAL is not a multibyte character code, so vim_strchr is not an > appropriate way to search for it. A bytewise search of the string is > needed. Thanks Ben! -- ARTHUR: Be quiet! DENNIS: Well you can't expect to wield supreme executive power just 'cause some watery tart threw a sword at you! ARTHUR: Shut up! DENNIS: I mean, if I went around sayin' I was an empereror just because some moistened bint had lobbed a scimitar at me they'd put me away! The Quest for the Holy Grail (Monty Python) /// Bram Moolenaar -- b...@moolenaar.net -- http://www.Moolenaar.net \\\ ///sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\ an exciting new programming language -- http://www.Zimbu.org/// \\\help me help AIDS victims -- http://ICCF-Holland.org/// -- You received this message from the "vim_dev" 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