如何在GNU M4中匹配换行符_properly_ [英] How to match newlines in GNU M4 _properly_

查看:97
本文介绍了如何在GNU M4中匹配换行符_properly_的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试制作一个宏来替换换行符.

I am trying to craft a macro replacing newlines.

我的第一次尝试是:

    define(`m4_pascal_str',`
     patsubst(`$1',`^\(.*\)$',`\1++')
')

m4_pascal_str(`

11

22 33 44
')

define(zz,`

11

22 33 44
')
m4_pascal_str(`zz')

在不使用中间宏时给出正确答案,否则仅匹配最后一个换行符.查看以下结果:

That gives correct answer when not using intermediate macro, and match only last newline otherwise. See results below:

 ++

++
11++
++
22 33 44++

++

11

22 33 44
++

然后我发现了类似的问题: 在m4的部分中,如何用空格替换换行符?

Then I found similar question: in m4's patsubst, how do I replace newlines with spaces?

所以,我刚刚做了:

define(`m4_pascal_str',`
     patsubst(`$1',`
',`++')
')

m4_pascal_str(`

11

22 33 44
')

define(zz,`

11

22 33 44
')
m4_pascal_str(`zz')

它给出:

 ++++11++++22 33 44++

11

22 33 44

最后一个选择也遇到了同样的问题. 有什么建议吗?

The last alternative suffers the same problem. Any suggestions?

推荐答案

对于最后一行,请尝试删除 zz 周围的引号.当我这样做时,两个m4_pascal_str调用都得到相同的结果:

For the last line try removing the quoting around the zz. When I did this I got the same result for both m4_pascal_str calls:

     ++
++
11++
++
22 33 44++
++




     ++
++
11++
++
22 33 44++
++

这篇关于如何在GNU M4中匹配换行符_properly_的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆