Description
We want to change the first quote of every single-quoted string to backquote,
where
- the opening and the closing quotes of a quoted string may be
on different lines, and
- an escaped quote has to be treated literally.
|
| Raw Input
|
| Desired Output
| first 'aaa\'AAA' second 'bbb
ccc' third 'ddd\'DE\'eee'
fourth '' fifth 'fff
ggg' sixth 'hh' seventh '
' eight 'jjj kkk' ninth 'lll
mmm'
|
| first `aaa\'AAA' second `bbb
ccc' third `ddd\'DE\'eee'
fourth `' fifth `fff
ggg' sixth `hh' seventh `
' eight `jjj kkk' ninth `lll
mmm'
|
|
Script and Comments
Script1 [ 1] :find_opening
[ 2] /\n/!s/^/\n/
[ 3] s/\n((\\.|[^'])*)/\1\n/
[ 4] /\n'/!{
[ 5] s/\n//
[ 6] n
[ 7] b find_opening
[ 8] }
[ 9] s/\n'/`\n/
[10] :find_closing
[11] /\n/!s/^/\n/
[12] s/\n((\\.|[^'])*)/\1\n/
[13] /\n'/!{
[14] s/\n//
[15] n
[16] b find_closing
[17] }
[18] s/\n'/'\n/
[19] b find_opening
|
Script2 [ 1] :loop
[ 2] /\n/!s/^/\n/
[ 3] s/\n((\\.|[^'])*)/\1\n/
[ 4] /\n'/!{
[ 5] s/\n//
[ 6] n
[ 7] b loop
[ 8] }
[ 9] G
[10] /\n$/s/\n'/`\n/
[11] /\n#$/s/\n'/'\n/
[12] s/\n#*$//
[13] x
[14] s/^/#/
[15] s/##//
[16] x
[17] b loop
| |