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

45610Calling a function from a :s command (weird results)

Expand Messages
  • David Fishburn
    Nov 30, 2003
      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
    • Show all 11 messages in this topic