Created
August 21, 2019 06:52
-
-
Save laike9m/1855aa6546d0eab648929fbec25072d1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
http://wiki.c2.com/?RawStrings | |
Raw string 是个通用概念。即 escape 不生效的 string,既然不生效,也无法 escape 掉 ending sequence。 | |
所有语言的 raw string 都面临一个问题,即如何处理 ending sequence | |
Python | |
https://docs.python.org/3/reference/lexical_analysis.html#string-and-bytes-literals | |
staring sequence: “ or ' | |
ending sequence: “ or ' | |
Python 的做法是允许 ‘, “ 出现,但需要用 \ escape 掉它们(相当于在 Python raw string里有唯一生效的escape就是\”和\’),并且 \ 依然会出现 | |
C++ | |
http://en.cppreference.com/w/cpp/language/string_literal | |
staring sequence: “( | |
ending sequence: “) | |
直接不允许 ending sequence 在 raw string 中出现 | |
Go | |
https://golang.org/ref/spec#String_literals | |
staring sequence: ` | |
ending sequence: ` | |
类似的,也不允许 ending sequence 在 raw string 中出现 | |
因为 raw string 本来就是在特殊情况下才有用的,比如 regex, multiline,即使有不能使用 ending sequence 的限制也无所谓。如果有这种需求用普通string就好了。 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment