Project

General

Profile

Actions

Feature #17184

open

No stdlib function to perform simple string replacement

Added by sheerun (Adam Stankiewicz) about 1 year ago. Updated 8 months ago.

Status:
Open
Priority:
Normal
Target version:
-
[ruby-core:100099]

Description

I have following simple build.rb:

template = File.read('template.vim')
script = File.read('script.vim')
File.write('app.vim', template.gsub("SCRIPT", script))

And then following template.vim:

" some header
SCRIPT

Plus following script.vim:

if g:something =~ "\s\+"
  echo 'g:something is empty'
endif

I'd expect that the script above produces app.vim with following contents:

" some header
if g:something =~ "\s\+"
  echo 'g:something is empty'
endif

Unfortunately it produces following:

" some header
if g:something =~ "\s"
  echo 'g:something is empty'
endif

It's probably because gsub interprets \+ in script as back-reference.

I tried to find replacement function in ruby that just replaces one string with something else, without interpreting replacement in any way, but surprisingly I haven't found any.. Am I mistaken?

Actions

Also available in: Atom PDF