Mercurial > cpython-lru_cache-weakref
diff Python/compile.c @ 11974:28003afa1a2f legacy-trunk
Marc-Andre Lemburg: support for Unicode string literals (u"...", ur"...").
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Fri, 10 Mar 2000 23:01:36 +0000 |
| parents | 770618d9a7fc |
| children | 603db0d0aed1 |
line wrap: on
line diff
--- a/Python/compile.c Fri Mar 10 23:00:52 2000 +0000 +++ b/Python/compile.c Fri Mar 10 23:01:36 2000 +0000 @@ -875,8 +875,18 @@ int c; int first = *s; int quote = first; - if (isalpha(quote) || quote == '_') - quote = *++s; + int rawmode = 0; + int unicode = 0; + if (isalpha(quote) || quote == '_') { + if (quote == 'u' || quote == 'U') { + quote = *++s; + unicode = 1; + } + if (quote == 'r' || quote == 'R') { + quote = *++s; + rawmode = 1; + } + } if (quote != '\'' && quote != '\"') { PyErr_BadInternalCall(); return NULL; @@ -895,8 +905,17 @@ return NULL; } } - if (first != quote || strchr(s, '\\') == NULL) + if (unicode) { + if (rawmode) + return PyUnicode_DecodeRawUnicodeEscape( + s, len, NULL); + else + return PyUnicode_DecodeUnicodeEscape( + s, len, NULL); + } + else if (rawmode || strchr(s, '\\') == NULL) { return PyString_FromStringAndSize(s, len); + } v = PyString_FromStringAndSize((char *)NULL, len); p = buf = PyString_AsString(v); end = s + len;
