如何绕过 g++ 4.8.1 那个不能在宏里面使用 R”(…)” 的 bug?
看到形如:R”” 这样的写法,相信学过 Python 的童鞋会感到似曾相识。Python 支持所谓的 “raw string”。Python 文档这样介绍 raw string:
Both string and bytes literals may optionally be prefixed with a letter ‘r’ or ‘R’; such strings are called raw strings and treat backslashes as literal characters. As a result, in string literals, ‘\U’ and ‘\u’ escapes in raw strings are not treated specially. Given that Python 2.x’s raw unicode literals behave differently than Python 3.x’s the ‘ur’ syntax is not supported.
从这段文字中我们可以看出,raw string 最大的特点就是:它不会对反斜杠’\’进行特殊的转义处理。
那么,它的这一特性有什么好处呢?
不用正则,不知 raw string 大法好!我们知道,正则表达式里,有很多元字符,当没有 raw string 时,我们需要在书写正则表达式的时候使用’\‘来表示元字符里的’\’,这样将导致正则表达式变得冗长,而且可读性也会降低。
. . .