Loading ...
Sorry, an error occurred while loading the content.

45611Re: Calling a function from a :s command (weird results)

Expand Messages
  • John Aldridge
    Nov 30, 2003
    • 0 Attachment
      At 19:24 11-30-2003, David Fishburn wrote:


      >Vim 6.2.154 WinXP
      >
      >I have this function (from a previous posting):
      >
      >function! InvertString(str)
      > " Courtesy of Antony Scriven
      > " This will invert/reverse a string
      > " This will work on arbitrary length strings, too. The /.*/ should
      >be
      > " quick, which might make it up for using a regex rather than using
      > " numerous commands in a :while loop.
      > "
      > " This can be used in a substitute command as follows:
      > " :%s/AUTHORIZATION/\=InvertString(submatch(0))
      > let inverted = substitute(a:str, '.\(.*\)\@=',
      > \ '\=a:str[strlen(submatch(1))]', 'g')
      >
      > return inverted
      >endfunction
      >
      >
      >I have this file:
      >CREATE SERVICE "scores" TYPE 'RAW'
      > OFF USER DBA
      > URL ON
      > AS CALL sp_http_scores();
      >
      >CREATE SERVICE "scores" TYPE 'RAW'
      > AUTHORIZATION OFF USER DBA
      > URL ON
      > AS CALL sp_http_scores();
      >
      >I issue this command:
      >:%s/AUTHORIZATION/\=InvertString(submatch(0))
      >
      >I get this result, and I don't understand why:
      >CREATE SERVICE "scores" TYPE 'RAW'
      >
      >=a:str[strlen(submatch(1))]=a:str[strlen(submatch(1))]=a:str[strlen(subm
      >atch(1))]=a:str[strlen(submatch(1))]=a:str[strlen(submatch(1))]=a:str[st
      >rlen(submatch(1))]=a:str[strlen(submatch(1))]=a:str[strlen(submatch(1))]
      >=a:str[strlen(submatch(1))]=a:str[strlen(submatch(1))]=a:str[strlen(subm
      >atch(1))]=a:str[strlen(submatch(1))]=a:str[strlen(submatch(1))] OFF USER
      >DBA
      > URL ON
      > AS CALL sp_http_scores();
      >
      >CREATE SERVICE "scores" TYPE 'RAW'
      >
      >=a:str[strlen(submatch(1))]=a:str[strlen(submatch(1))]=a:str[strlen(subm
      >atch(1))]=a:str[strlen(submatch(1))]=a:str[strlen(submatch(1))]=a:str[st
      >rlen(submatch(1))]=a:str[strlen(submatch(1))]=a:str[strlen(submatch(1))]
      >=a:str[strlen(submatch(1))]=a:str[strlen(submatch(1))]=a:str[strlen(subm
      >atch(1))]=a:str[strlen(submatch(1))]=a:str[strlen(submatch(1))] OFF USER
      >DBA
      > URL ON
      > AS CALL sp_http_scores();
      >
      >This works fine:
      >:echo InvertString('1234567890')
      >0987654321 is displayed.
      >
      >Any ideas?
      >
      >Thanks,
      >Dave

      I get this kind of thing once in a while; and if I remember correctly,
      it's a quoting issue. From your results, it looks as if the \= isn't
      being taken for its intended meaning. Without remembering what really
      fixes this, I'd say go ahead and throw an extra backslash in there.
    • Show all 11 messages in this topic