diff options
| author | Guido van Rossum <guido@python.org> | 2000-03-10 23:01:36 +0000 |
|---|---|---|
| committer | Guido van Rossum <guido@python.org> | 2000-03-10 23:01:36 +0000 |
| commit | 8b8b1fe1e07eed0451cd29389319a22f9b3a41ea (patch) | |
| tree | f11da1e6e0a294f2557d3ae287d08f6b9320845c /Python/compile.c | |
| parent | 2c536029a3fa342e1c5b20353b557f15440e0d19 (diff) | |
| download | cpython-8b8b1fe1e07eed0451cd29389319a22f9b3a41ea.tar.gz | |
Marc-Andre Lemburg: support for Unicode string literals (u"...", ur"...").
Diffstat (limited to 'Python/compile.c')
| -rw-r--r-- | Python/compile.c | 25 |
1 files changed, 22 insertions, 3 deletions
diff --git a/Python/compile.c b/Python/compile.c index 37cdfc9b9b..72848fae36 100644 --- a/Python/compile.c +++ b/Python/compile.c @@ -875,8 +875,18 @@ parsestr(s) 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 @@ parsestr(s) 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; |
